DBA Data[Home] [Help]

PACKAGE BODY: APPS.CS_CHARGE_DETAILS_PVT

Source


1 PACKAGE BODY CS_Charge_Details_PVT AS
2 /* $Header: csxvestb.pls 120.61.12010000.5 2008/10/08 11:20:15 sshilpam ship $ */
3 
4 --==========================================================
5 -- Global Variables Decalaration
6 --==========================================================
7 
8 RECORD_LOCK_EXCEPTION EXCEPTION ;
9 PRAGMA EXCEPTION_INIT(RECORD_LOCK_EXCEPTION,-0054);
10 
11 
12 -- Structure Definitions
13 TYPE REC_UOM IS RECORD
14  (
15    Unit_of_Measure NUMBER
16  );
17 
18 TYPE TBL_UOM IS TABLE OF REC_UOM INDEX BY BINARY_INTEGER ;
19 
20 
21 --===========================================================
22 -- Declaration of  Procedures and functions
23 --===========================================================
24 PROCEDURE VALIDATE_CHARGE_DETAILS(
25                  P_API_NAME                  IN            VARCHAR2,
26                  P_CHARGES_DETAIL_REC        IN            CS_Charge_Details_PUB.Charges_Rec_Type,
27                  P_VALIDATION_MODE           IN            VARCHAR2,
28                  P_USER_ID                   IN            NUMBER,
29                  P_LOGIN_ID                  IN            NUMBER,
30                  X_CHARGES_DETAIL_REC        OUT NOCOPY    CS_Charge_Details_PUB.Charges_Rec_Type,
31                  X_MSG_DATA                  OUT NOCOPY    VARCHAR2,
32                  X_MSG_COUNT                 OUT NOCOPY    NUMBER,
33                  X_RETURN_STATUS             OUT NOCOPY    VARCHAR2);
34 
35 
36 PROCEDURE ADD_INVALID_ARGUMENT_MSG(
37                  P_TOKEN_AN	  VARCHAR2,
38                  P_TOKEN_V	  VARCHAR2,
39                  P_TOKEN_P	  VARCHAR2);
40 
41 PROCEDURE ADD_NULL_PARAMETER_MSG(
42                  P_TOKEN_AN   IN  VARCHAR2,
43                  P_TOKEN_NP   IN  VARCHAR2);
44 
45 PROCEDURE CANT_UPDATE_DETAIL_PARAM_MSG(
46                  P_TOKEN_AN            IN      VARCHAR2,
47                  P_TOKEN_CN            IN      VARCHAR2,
48                  P_TOKEN_V             IN      VARCHAR2 );
49 
50 PROCEDURE CANNOT_DELETE_LINE_MSG(
51                  P_TOKEN_AN    IN      VARCHAR2);
52 
53 PROCEDURE RECORD_IS_LOCKED_MSG(
54                  P_TOKEN_AN     IN  VARCHAR2);
55 
56 
57 PROCEDURE GET_SITE_FOR_PARTY(
58                  P_API_NAME          IN         VARCHAR2,
59                  P_SITE_USE_ID       IN         NUMBER,
60                  P_PARTY_ID          IN         NUMBER,
61                  P_VAL_MODE          IN         VARCHAR2,
62                  X_SITE_ID           OUT NOCOPY NUMBER,
63                  X_RETURN_STATUS     OUT NOCOPY VARCHAR2);
64 
65 PROCEDURE GET_SR_DEFAULTS(
66                  P_API_NAME               IN          VARCHAR2,
67                  P_INCIDENT_ID            IN          NUMBER,
68                  X_BUSINESS_PROCESS_ID    OUT NOCOPY  NUMBER,
69                  X_CUSTOMER_ID            OUT NOCOPY  NUMBER,
70                  X_CUSTOMER_SITE_ID       OUT NOCOPY  NUMBER,
71                  X_CUST_PO_NUMBER         OUT NOCOPY  VARCHAR2,
72                  X_CUSTOMER_PRODUCT_ID    OUT NOCOPY  NUMBER,
73                  X_SYSTEM_ID              OUT NOCOPY  NUMBER,
74                  X_INVENTORY_ITEM_ID      OUT NOCOPY  NUMBER,
75                  X_ACCOUNT_ID             OUT NOCOPY  NUMBER,
76                  X_BILL_TO_PARTY_ID       OUT NOCOPY  NUMBER,
77                  X_BILL_TO_ACCOUNT_ID     OUT NOCOPY  NUMBER,
78                  X_BILL_TO_CONTACT_ID     OUT NOCOPY  NUMBER,
79                  X_BILL_TO_SITE_ID        OUT NOCOPY  NUMBER,
80                  X_SHIP_TO_PARTY_ID       OUT NOCOPY  NUMBER,
81                  X_SHIP_TO_ACCOUNT_ID     OUT NOCOPY  NUMBER,
82                  X_SHIP_TO_CONTACT_ID     OUT NOCOPY  NUMBER,
83                  X_SHIP_TO_SITE_ID        OUT NOCOPY  NUMBER,
84                  X_CONTRACT_ID            OUT NOCOPY  NUMBER,
85                  X_CONTRACT_SERVICE_ID    OUT NOCOPY  NUMBER,
86                  X_INCIDENT_DATE          OUT NOCOPY  DATE,
87                  X_CREATION_DATE          OUT NOCOPY  DATE,
88                  X_MSG_DATA               OUT NOCOPY  VARCHAR2,
89                  X_MSG_COUNT              OUT NOCOPY  NUMBER,
90                  X_RETURN_STATUS          OUT NOCOPY  VARCHAR2);
91 
92 PROCEDURE VALIDATE_TXN_TYPE(
93                  P_API_NAME                  IN         VARCHAR2,
94                  P_BUSINESS_PROCESS_ID       IN         NUMBER,
95                  P_TXN_TYPE_ID               IN         NUMBER,
96                  P_SOURCE_CODE               IN         VARCHAR2,
97                  X_LINE_ORDER_CATEGORY_CODE  OUT NOCOPY VARCHAR2,
98                  X_NO_CHARGE_FLAG            OUT NOCOPY VARCHAR2,
99                  X_INTERFACE_TO_OE_FLAG      OUT NOCOPY VARCHAR2, -- Added a new parameter for R11.5.10
100                  X_UPDATE_IB_FLAG            OUT NOCOPY VARCHAR2,
101                  X_SRC_REFERENCE_REQD_FLAG   OUT NOCOPY VARCHAR2,
102                  X_SRC_RETURN_REQD_FLAG      OUT NOCOPY VARCHAR2,
103                  X_NON_SRC_REFERENCE_REQD    OUT NOCOPY VARCHAR2,
104                  X_NON_SRC_RETURN_REQD       OUT NOCOPY VARCHAR2,
105                  X_MSG_DATA                  OUT NOCOPY  VARCHAR2,
106                  X_MSG_COUNT                 OUT NOCOPY  NUMBER,
107                  X_RETURN_STATUS             OUT NOCOPY VARCHAR2);
108 
109 PROCEDURE VALIDATE_ITEM(
110                  P_API_NAME             IN         VARCHAR2,
111                  P_INV_ID               IN         NUMBER,
112                  P_UPDATE_IB_FLAG       IN         VARCHAR2,
113                  X_COMMS_TRACKABLE_FLAG OUT NOCOPY VARCHAR2,
114                  X_SERIAL_CONTROL_FLAG  OUT NOCOPY VARCHAR2,
115                  X_REV_CONTROL_FLAG     OUT NOCOPY VARCHAR2,
116                  X_MSG_DATA             OUT NOCOPY  VARCHAR2,
117                  X_MSG_COUNT            OUT NOCOPY  NUMBER,
118                  X_RETURN_STATUS        OUT NOCOPY VARCHAR2);
119 
120 PROCEDURE GET_BILLING_FLAG(
121                  P_API_NAME            IN         VARCHAR2,
122                  P_INV_ID              IN         NUMBER,
123                  P_TXN_TYPE_ID         IN         NUMBER,
124                  X_BILLING_FLAG        OUT NOCOPY VARCHAR2,
125                  X_MSG_DATA            OUT NOCOPY VARCHAR2,
126                  X_MSG_COUNT           OUT NOCOPY NUMBER,
127                  X_RETURN_STATUS       OUT NOCOPY VARCHAR2);
128 
129 PROCEDURE GET_TXN_BILLING_TYPE(
130                  P_API_NAME            IN         VARCHAR2,
131                  P_INV_ID              IN         NUMBER,
132                  P_TXN_TYPE_ID         IN         NUMBER,
133                  X_TXN_BILLING_TYPE_ID OUT NOCOPY NUMBER,
134                  X_MSG_DATA            OUT NOCOPY VARCHAR2,
135                  X_MSG_COUNT           OUT NOCOPY NUMBER,
136                  X_RETURN_STATUS       OUT NOCOPY VARCHAR2);
137 
138 PROCEDURE GET_UOM(
139                  P_INV_ID            IN NUMBER,
140                  X_TBL_UOM           OUT NOCOPY TBL_UOM,
141                  X_MSG_DATA          OUT NOCOPY VARCHAR2,
142                  X_MSG_COUNT         OUT NOCOPY NUMBER,
143                  X_RETURN_STATUS     OUT NOCOPY VARCHAR2);
144 
145 
146 PROCEDURE GET_PRIMARY_UOM(
147                  P_INV_ID            IN NUMBER,
148                  X_PRIMARY_UOM       OUT NOCOPY VARCHAR2,
149                  X_MSG_DATA          OUT NOCOPY VARCHAR2,
150                  X_MSG_COUNT         OUT NOCOPY NUMBER,
151                  X_RETURN_STATUS     OUT NOCOPY VARCHAR2) ;
152 
153 
154 PROCEDURE VALIDATE_SOURCE(
155                  P_API_NAME          IN         VARCHAR2,
156                  P_SOURCE_CODE       IN         VARCHAR2,
157                  P_SOURCE_ID         IN         NUMBER,
158                  P_ORG_ID            IN         NUMBER,
159                  X_SOURCE_ID         OUT NOCOPY NUMBER,
160                  X_MSG_DATA          OUT NOCOPY VARCHAR2,
161                  X_MSG_COUNT         OUT NOCOPY NUMBER,
162                  X_RETURN_STATUS     OUT NOCOPY VARCHAR2) ;
163 
164 PROCEDURE GET_CONTRACT_PRICE_LIST(
165                  p_api_name               IN         VARCHAR2,
166                  p_business_process_id    IN         NUMBER,
167                  p_request_date           IN         DATE,
168                  p_contract_line_id       IN         NUMBER,
169                  --p_coverage_id            IN         NUMBER,
170                  x_price_list_id          OUT NOCOPY NUMBER,
171                  x_currency_code          OUT NOCOPY VARCHAR2,
172                  X_MSG_DATA               OUT NOCOPY VARCHAR2,
173                  X_MSG_COUNT              OUT NOCOPY NUMBER,
174                  x_return_status          OUT NOCOPY VARCHAR2);
175 
176 PROCEDURE  GET_CURRENCY_CODE(
177                  p_api_name        IN         VARCHAR2,
178                  p_price_list_id   IN         NUMBER ,
179                  x_currency_code   OUT NOCOPY VARCHAR2,
180                  X_MSG_DATA        OUT NOCOPY VARCHAR2,
181                  X_MSG_COUNT       OUT NOCOPY NUMBER,
182                  x_return_status   OUT NOCOPY VARCHAR2);
183 
184 PROCEDURE DO_TXNS_EXIST(
185                  P_API_NAME            IN          VARCHAR2,
186                  P_ESTIMATE_DETAIL_ID  IN          NUMBER ,
187                  x_ORDER_LINE_ID       OUT NOCOPY  NUMBER,
188                  x_gen_bca_flag        OUT NOCOPY  VARCHAR2,
189                  x_charge_line_type    OUT NOCOPY  VARCHAR2,
190                  x_RETURN_STATUS       OUT NOCOPY  VARCHAR2);
191 
192 PROCEDURE  GET_CONVERSION_RATE(
193                  P_API_NAME       IN         VARCHAR2,
194                  P_FROM_CURRENCY  IN         VARCHAR2,
195                  P_TO_CURRENCY    IN         VARCHAR2,
196                  X_DENOMINATOR    OUT NOCOPY NUMBER,
197                  X_NUMERATOR      OUT NOCOPY NUMBER,
198                  X_RATE           OUT NOCOPY NUMBER,
199                  X_RETURN_STATUS  OUT NOCOPY VARCHAR);
200 
201 
202 PROCEDURE Validate_Who_Info(
203                  P_API_NAME                  IN            VARCHAR2,
204                  P_USER_ID                   IN            NUMBER,
205                  P_LOGIN_ID                  IN            NUMBER,
206                  X_RETURN_STATUS             OUT NOCOPY    VARCHAR2);
207 
208 
209 PROCEDURE GET_CHARGE_DETAIL_REC(
210                  P_API_NAME           IN         VARCHAR2,
211                  P_ESTIMATE_DETAIL_ID IN         NUMBER,
212                  x_CHARGE_DETAIL_REC  OUT NOCOPY CS_ESTIMATE_DETAILS%ROWTYPE ,
213                  x_MSG_DATA           OUT NOCOPY VARCHAR2,
214                  x_MSG_COUNT          OUT NOCOPY NUMBER,
215                  x_RETURN_STATUS      OUT NOCOPY VARCHAR2);
216 
217 --Fixed Bug # 3325667 added p_org_id to procedure get_line_type
218 Procedure Get_Line_Type(
219                  p_api_name              IN VARCHAR2,
220                  p_txn_billing_type_id   IN  NUMBER,
221                  p_org_id                IN  NUMBER,
222                  x_line_type_id          OUT NOCOPY  NUMBER,
223                  x_return_status         OUT NOCOPY VARCHAR2,
224                  x_msg_count             OUT NOCOPY NUMBER,
225                  x_msg_data              OUT NOCOPY VARCHAR2);
226 
227 --Bug Fix for Bug # 3086455
228 PROCEDURE get_charge_flags_from_sr(
229                  p_api_name                IN          VARCHAR2,
230                  p_incident_id             IN          NUMBER,
231                  x_disallow_new_charge     OUT NOCOPY  VARCHAR2,
232                  x_disallow_charge_update  OUT NOCOPY  VARCHAR2,
233                  x_msg_data                OUT NOCOPY  VARCHAR2,
234                  x_msg_count               OUT NOCOPY  NUMBER,
235                  x_return_status           OUT NOCOPY  NUMBER);
236 
237 --Added by bkanimoz on 15-dec-2007 --Service Costing Enh
238 
239 PROCEDURE get_charge_flag_from_sac
240 (
241 	  p_api_name                IN          VARCHAR2,
242           p_txn_type_id             IN          NUMBER,
243 	  x_create_charge_flag      OUT NOCOPY  VARCHAR2,
244 	  x_msg_data                OUT NOCOPY  VARCHAR2,
245 	  x_msg_count               OUT NOCOPY  NUMBER,
246           x_return_status           OUT NOCOPY  NUMBER
247 );
248 
249 
250 PROCEDURE Validate_Order(
251                  p_api_name              IN VARCHAR2,
252                  p_order_header_id       IN NUMBER,
253                  p_org_id                IN NUMBER,
254                  x_return_status         OUT NOCOPY VARCHAR2,
255                  x_msg_count             OUT NOCOPY NUMBER,
256                  x_msg_data              OUT NOCOPY VARCHAR2);
257 
258 PROCEDURE VALIDATE_ORG_ID(
259                  P_API_NAME       IN VARCHAR2,
260                  P_ORG_ID         IN NUMBER,
261                  X_RETURN_STATUS  OUT NOCOPY VARCHAR2,
262                  X_MSG_COUNT      OUT NOCOPY NUMBER,
263                  X_MSG_DATA       OUT NOCOPY VARCHAR2);
264 
265 
266 FUNCTION IS_INCIDENT_ID_VALID (
267                  p_incident_id   IN         NUMBER,
268                  x_msg_data      OUT NOCOPY VARCHAR2,
269                  x_msg_count     OUT NOCOPY NUMBER,
270                  x_return_status OUT NOCOPY VARCHAR2)
271 RETURN VARCHAR2;
272 
273 
274 FUNCTION IS_RETURN_REASON_VALID(
275                  P_RETURN_REASON_CODE IN         VARCHAR2,
276                  X_MSG_DATA           OUT NOCOPY VARCHAR2,
277                  X_MSG_COUNT          OUT NOCOPY NUMBER,
278                  X_RETURN_STATUS      OUT NOCOPY VARCHAR2)
279 RETURN VARCHAR2;
280 
281 FUNCTION IS_CHARGE_LINE_TYPE_VALID(
282                  p_charge_line_type IN         VARCHAR2,
283                  x_msg_data         OUT NOCOPY VARCHAR2,
284                  x_msg_count        OUT NOCOPY NUMBER,
285                  x_return_status    OUT NOCOPY VARCHAR2)
286 RETURN VARCHAR2;
287 
288 FUNCTION IS_BUSINESS_PROCESS_ID_VALID(
289                  p_business_process_id IN         NUMBER,
290                  x_msg_data            OUT NOCOPY VARCHAR2,
291                  x_msg_count           OUT NOCOPY NUMBER,
292                  x_return_status       OUT NOCOPY VARCHAR2)
293 RETURN VARCHAR2;
294 
295 FUNCTION IS_PARTY_VALID(
296                  p_party_id      IN         NUMBER,
297                  x_msg_data      OUT NOCOPY VARCHAR2,
298                  x_msg_count     OUT NOCOPY NUMBER,
299                  x_return_status OUT NOCOPY VARCHAR2)
300 RETURN VARCHAR2;
301 
302 FUNCTION IS_ACCOUNT_VALID(
303                  p_account_id    IN         NUMBER,
304                  p_party_id      IN         NUMBER,
305                  x_msg_data      OUT NOCOPY VARCHAR2,
306                  x_msg_count     OUT NOCOPY NUMBER,
307                  x_return_status OUT NOCOPY VARCHAR2)
308 RETURN VARCHAR2;
309 
310 FUNCTION IS_CONTACT_VALID(
311                  p_contact_id    IN         NUMBER,
312                  p_party_id      IN         NUMBER,
313                  x_msg_data      OUT NOCOPY VARCHAR2,
314                  x_msg_count     OUT NOCOPY NUMBER,
315                  x_return_status OUT NOCOPY VARCHAR2)
316 RETURN VARCHAR2;
317 
318 FUNCTION IS_PARTY_SITE_VALID(
319                  p_party_site_id IN         NUMBER,
320                  p_party_id      IN         NUMBER,
321                  p_val_mode      IN         VARCHAR2,
322                  x_msg_data      OUT NOCOPY VARCHAR2,
323                  x_msg_count     OUT NOCOPY NUMBER,
324                  x_return_status OUT NOCOPY VARCHAR2)
325 RETURN VARCHAR2;
326 
327 
328 FUNCTION IS_CONTRACT_VALID(
329                  p_contract_id           IN NUMBER,
330                  x_msg_data              OUT NOCOPY VARCHAR2,
331                  x_msg_count             OUT NOCOPY NUMBER,
332                  x_return_status         OUT NOCOPY VARCHAR2)
333 RETURN VARCHAR2;
334 
335 --Added for R12 implementation
336 
337 FUNCTION IS_CONTRACT_LINE_VALID(
338                  p_contract_line_id      IN NUMBER,
339                  x_contract_id           OUT NOCOPY NUMBER,
340                  x_msg_data              OUT NOCOPY VARCHAR2,
341                  x_msg_count             OUT NOCOPY NUMBER,
342                  x_return_status         OUT NOCOPY VARCHAR2)
343 RETURN VARCHAR2;
344 
345 FUNCTION IS_PRICE_LIST_VALID(
346                  p_price_list_id  IN         NUMBER,
347                  x_msg_data       OUT NOCOPY VARCHAR2,
348                  x_msg_count      OUT NOCOPY NUMBER,
349                  x_return_status  OUT NOCOPY VARCHAR2)
350 RETURN VARCHAR2;
351 
352 FUNCTION IS_UOM_VALID(
353                  p_uom_code       IN         VARCHAR2,
354                  p_inv_id         IN         NUMBER,
355                  x_msg_data       OUT NOCOPY VARCHAR2,
356                  x_msg_count      OUT NOCOPY NUMBER,
357                  x_return_status  OUT NOCOPY VARCHAR2)
358 RETURN VARCHAR2;
359 
360 
361 FUNCTION IS_INSTANCE_FOR_INVENTORY(
362                  p_instance_id    IN         NUMBER,
363                  p_inv_id         IN         NUMBER,
364                  x_msg_data       OUT NOCOPY VARCHAR2,
365                  x_msg_count      OUT NOCOPY NUMBER,
366                  x_return_status  OUT NOCOPY VARCHAR2)
367 RETURN VARCHAR2;
368 
369 FUNCTION IS_INSTANCE_VALID(
370                  p_instance_id    IN         NUMBER,
371                  p_party_id       IN         NUMBER,
372                  x_msg_data       OUT NOCOPY VARCHAR2,
373                  x_msg_count      OUT NOCOPY NUMBER,
374                  x_return_status  OUT NOCOPY VARCHAR2)
375 RETURN VARCHAR2;
376 
377 FUNCTION IS_INSTANCE_SERIAL_VALID  (
378                                    p_instance_id   IN         NUMBER
379                                   ,p_serial_number IN         VARCHAR
380                                   ,x_msg_data      OUT NOCOPY VARCHAR2
381                                   ,x_msg_count     OUT NOCOPY NUMBER
382                                   ,x_return_status OUT NOCOPY VARCHAR2)
383 
384 RETURN VARCHAR2;
385 
386 FUNCTION IS_TXN_INV_ORG_VALID(
387                  p_txn_inv_org    IN         NUMBER,
388                  p_org_id         IN         NUMBER,
389                  x_msg_data       OUT NOCOPY VARCHAR2,
390                  x_msg_count      OUT NOCOPY NUMBER,
391                  x_return_status  OUT NOCOPY VARCHAR2)
392 RETURN VARCHAR2;
393 
394 FUNCTION IS_ESTIMATE_DETAIL_ID_VALID(
395                  p_estimate_detail_id IN         NUMBER,
396                  x_msg_data           OUT NOCOPY VARCHAR2,
397                  x_msg_count          OUT NOCOPY NUMBER,
398                  x_return_status      OUT NOCOPY VARCHAR2)
399 RETURN VARCHAR2;
400 
401 
402 FUNCTION GET_CONTRACT_LINE_ID(
403                  p_coverage_id        IN         NUMBER,
404                  x_msg_data           OUT NOCOPY VARCHAR2,
405                  x_msg_count          OUT NOCOPY NUMBER,
406                  x_return_status      OUT NOCOPY VARCHAR2)
407 RETURN NUMBER;
408 
409 -- Added fix for the bug:5125858
410 FUNCTION IS_ITEM_REVISION_VALID(
411                  p_inventory_item_id IN         NUMBER,
412                  p_item_revision     IN         VARCHAR2,
413                  x_msg_data           OUT NOCOPY VARCHAR2,
414                  x_msg_count          OUT NOCOPY NUMBER,
415                  x_return_status      OUT NOCOPY VARCHAR2)
416 RETURN VARCHAR2;
417 
418 -- Added fix for the bug:
419 FUNCTION IS_LINE_NUMBER_VALID(
420                  p_line_number       IN         NUMBER,
421                  p_incident_id       IN         NUMBER,
422                  x_msg_data           OUT NOCOPY VARCHAR2,
423                  x_msg_count          OUT NOCOPY NUMBER,
424                  x_return_status      OUT NOCOPY VARCHAR2)
425 RETURN VARCHAR2;
426 
427 --=================================================
428 -- Function Implementations
429 --=================================================
430 
431 --==================================================
432 -- IS_INCIDENT_ID_VALID - for Incident Id Validation
433 --==================================================
434 FUNCTION IS_INCIDENT_ID_VALID (p_incident_id   IN         NUMBER,
435                                x_msg_data      OUT NOCOPY VARCHAR2,
436                                x_msg_count     OUT NOCOPY NUMBER,
437                                x_return_status OUT NOCOPY VARCHAR2
438                                )
439 RETURN VARCHAR2
440 IS
441 
442 Cursor c_incident IS
443   SELECT 'Y'
444     FROM cs_incidents_all
445    WHERE incident_id = p_incident_id;
446 
447 lv_exists_flag VARCHAR2(1) := 'N';
448 
449 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'is_incident_id_valid';
450 
451 BEGIN
452 
453 x_return_status := FND_API.G_RET_STS_SUCCESS;
454 
455 OPEN c_incident;
456 FETCH c_incident INTO lv_exists_flag;
457 CLOSE c_incident;
458 
459 RETURN lv_exists_flag;
460 
461 EXCEPTION
462 
463       WHEN OTHERS THEN
464 
465         FND_MESSAGE.SET_NAME(G_APP_NAME, G_DB_ERROR);
466         FND_MESSAGE.SET_TOKEN(token => G_PROG_NAME_TOKEN, value => l_prog_name);
467         FND_MESSAGE.SET_TOKEN(token => G_SQLCODE_TOKEN, value => SQLCODE);
468         FND_MESSAGE.SET_TOKEN(token => G_SQLERRM_TOKEN, value => SQLERRM);
469         FND_MSG_PUB.add;
470 
471         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
472         RETURN lv_exists_flag;
473 
474 END IS_INCIDENT_ID_VALID;
475 
476 --========================================================
477 -- IS_RETURN_RESON_VALID - For Return Reson Code Validation
478 --=========================================================
479 
480 FUNCTION IS_RETURN_REASON_VALID(P_RETURN_REASON_CODE IN         VARCHAR2,
481                                 X_MSG_DATA           OUT NOCOPY VARCHAR2,
482                                 X_MSG_COUNT          OUT NOCOPY NUMBER,
483                                 X_RETURN_STATUS      OUT NOCOPY VARCHAR2)
484 RETURN VARCHAR2
485 IS
486 
487 --Cursor to check return reason code
488 
489 CURSOR c_return_reason_cur(p_return_reason_code varchar2) is
490 SELECT meaning from ar_lookups
491 WHERE  lookup_type = 'CREDIT_MEMO_REASON'
492 and lookup_code = p_return_reason_code;
493 
494 lv_exists_flag VARCHAR2(1) := 'N';
495 
496 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'is_return_reason_valid';
497 
498 BEGIN
499 
500 x_return_status := FND_API.G_RET_STS_SUCCESS;
501 
502  FOR v_return_reason_cur IN c_return_reason_cur(p_return_reason_code)
503      LOOP
504        lv_exists_flag := 'Y' ;
505      END LOOP ;
506    RETURN lv_exists_flag;
507 
508 EXCEPTION
509 
510       WHEN OTHERS THEN
511 
512         FND_MESSAGE.SET_NAME(G_APP_NAME, G_DB_ERROR);
513         FND_MESSAGE.SET_TOKEN(token => G_PROG_NAME_TOKEN, value => l_prog_name);
514         FND_MESSAGE.SET_TOKEN(token => G_SQLCODE_TOKEN, value => SQLCODE);
515         FND_MESSAGE.SET_TOKEN(token => G_SQLERRM_TOKEN, value => SQLERRM);
516         FND_MSG_PUB.add;
517 
518         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
519         RETURN lv_exists_flag;
520 
521 END IS_RETURN_REASON_VALID;
522 
523 --========================================================
524 --IS_CHARGE_LINE_TYPE_VALID - for Charge Line Type
525 --Validation
526 --========================================================
527 FUNCTION IS_CHARGE_LINE_TYPE_VALID(p_charge_line_type IN VARCHAR2,
528                                    x_msg_data         OUT NOCOPY VARCHAR2,
529                                    x_msg_count        OUT NOCOPY NUMBER,
530                                    x_return_status    OUT NOCOPY VARCHAR2)
531 RETURN VARCHAR2
532 IS
533 
534 --Cursor to check valid Incident Id
535 
536 Cursor c_charge_line_type (p_charge_line_type IN VARCHAR2) IS
537   SELECT lookup_code
538     FROM fnd_lookup_values
539    WHERE lookup_type = 'CS_CHG_LINE_TYPE' AND
540          lookup_code = p_charge_line_type;
541 
542 lv_exists_flag VARCHAR2(1) := 'N';
543 
544 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'is_charge_line_type_valid';
545 
546 BEGIN
547 
548 x_return_status := FND_API.G_RET_STS_SUCCESS;
549 
550    FOR v_charge_line_type IN c_charge_line_type(p_charge_line_type)
551      LOOP
552        lv_exists_flag := 'Y';
553      END LOOP ;
554    RETURN lv_exists_flag;
555 
556 EXCEPTION
557 
558       WHEN OTHERS THEN
559 
560         FND_MESSAGE.SET_NAME(G_APP_NAME, G_DB_ERROR);
561         FND_MESSAGE.SET_TOKEN(token => G_PROG_NAME_TOKEN, value => l_prog_name);
562         FND_MESSAGE.SET_TOKEN(token => G_SQLCODE_TOKEN, value => SQLCODE);
563         FND_MESSAGE.SET_TOKEN(token => G_SQLERRM_TOKEN, value => SQLERRM);
564         FND_MSG_PUB.add;
565 
566         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
567         RETURN lv_exists_flag;
568 
569 
570 END IS_CHARGE_LINE_TYPE_VALID;
571 
572 --=========================================================
573 -- IS_BUSINESS_PROCESS_ID_VALID - for Business Process ID
574 -- Validation
575 --=========================================================
576 FUNCTION IS_BUSINESS_PROCESS_ID_VALID(p_business_process_id IN         NUMBER,
577                                       x_msg_data            OUT NOCOPY VARCHAR2,
578                                       x_msg_count           OUT NOCOPY NUMBER,
579                                       x_return_status       OUT NOCOPY VARCHAR2)
580 RETURN VARCHAR2
581 IS
582 
583 --Cursor to check valid Incident Id
584 
585 Cursor c_business_process_id (p_business_process_id IN NUMBER) IS
586 
587   SELECT business_process_id
588     FROM cs_business_processes
589    WHERE business_process_id = p_business_process_id;
590 
591 lv_exists_flag VARCHAR2(1) := 'N';
592 
593 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'is_business_process_id_valid';
594 
595 BEGIN
596 
597 x_return_status := FND_API.G_RET_STS_SUCCESS;
598 
599    FOR v_business_process_id IN c_business_process_id (p_business_process_id)
600      LOOP
601        lv_exists_flag := 'Y';
602      END LOOP ;
603    RETURN lv_exists_flag;
604 
605 EXCEPTION
606 
607       WHEN OTHERS THEN
608 
609         FND_MESSAGE.SET_NAME(G_APP_NAME, G_DB_ERROR);
610         FND_MESSAGE.SET_TOKEN(token => G_PROG_NAME_TOKEN, value => l_prog_name);
611         FND_MESSAGE.SET_TOKEN(token => G_SQLCODE_TOKEN, value => SQLCODE);
612         FND_MESSAGE.SET_TOKEN(token => G_SQLERRM_TOKEN, value => SQLERRM);
613         FND_MSG_PUB.add;
614 
615         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
616         RETURN lv_exists_flag;
617 
618 END IS_BUSINESS_PROCESS_ID_VALID;
619 
620 --===============================================================
621 -- IS_PARTY_VALID - for Bill_To_Party and Ship_to_Party Validation
622 --===============================================================
623 
624 FUNCTION IS_PARTY_VALID(p_party_id      IN         NUMBER,
625                         x_msg_data      OUT NOCOPY VARCHAR2,
626                         x_msg_count     OUT NOCOPY NUMBER,
627                         x_return_status OUT NOCOPY VARCHAR2) RETURN VARCHAR2 IS
628 
629 lv_exists_flag VARCHAR2(1) := 'N';
630 
631 CURSOR c_party IS
632 SELECT 'Y'
633 FROM hz_parties
634 WHERE party_id = p_party_id
635 AND   nvl(status, 'A')  = 'A';
636 
637 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'is_party_valid';
638 
639 BEGIN
640 
641 x_return_status := FND_API.G_RET_STS_SUCCESS;
642 
643 OPEN c_party;
644 FETCH c_party INTO lv_exists_flag;
645 CLOSE c_party;
646 
647 RETURN lv_exists_flag;
648 
649 EXCEPTION
650 
651       WHEN OTHERS THEN
652 
653         FND_MESSAGE.SET_NAME(G_APP_NAME, G_DB_ERROR);
654         FND_MESSAGE.SET_TOKEN(token => G_PROG_NAME_TOKEN, value => l_prog_name);
655         FND_MESSAGE.SET_TOKEN(token => G_SQLCODE_TOKEN, value => SQLCODE);
656         FND_MESSAGE.SET_TOKEN(token => G_SQLERRM_TOKEN, value => SQLERRM);
657         FND_MSG_PUB.add;
658 
659         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
660         RETURN lv_exists_flag;
661 
662 END IS_PARTY_VALID;
663 
664 
665 
666 --===============================================================
667 -- IS_ACCOUNT_VALID - for Bill_to_Accout and Ship_
668 --===============================================================
669 FUNCTION IS_ACCOUNT_VALID(p_account_id    IN         NUMBER,
670                           p_party_id      IN         NUMBER,
671                           x_msg_data      OUT NOCOPY VARCHAR2,
672                           x_msg_count     OUT NOCOPY NUMBER,
673                           x_return_status OUT NOCOPY VARCHAR2)
674 RETURN VARCHAR2
675 IS
676 
677 --Bug Fix for Bug # 2981195
678 --Added to the where
679 --Account_Activation_Date and Account_Termination_Date logic
680 --removed this from where clause Account_Activation_Date and Account_Termination_Date logic
681 
682 --Cursor to check Account Id
683 CURSOR c_account(p_account_id in number,
684                  p_party_id   in number) IS
685 SELECT cust_account_id
686 FROM   hz_cust_accounts
687 WHERE  cust_account_id = p_account_id
688   AND  party_id = p_party_id
689   AND  nvl(status, 'A') = 'A';
690 
691 
692 lv_exists_flag VARCHAR2(1) := 'N';
693 
694 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'is_account_valid';
695 
696 BEGIN
697 
698 x_return_status := FND_API.G_RET_STS_SUCCESS;
699 
700    FOR v_account IN c_account(p_account_id,
701                               p_party_id )
702      LOOP
703        lv_exists_flag := 'Y';
704      END LOOP ;
705    RETURN lv_exists_flag;
706 
707 EXCEPTION
708 
709       WHEN OTHERS THEN
710 
711         FND_MESSAGE.SET_NAME(G_APP_NAME, G_DB_ERROR);
712         FND_MESSAGE.SET_TOKEN(token => G_PROG_NAME_TOKEN, value => l_prog_name);
713         FND_MESSAGE.SET_TOKEN(token => G_SQLCODE_TOKEN, value => SQLCODE);
714         FND_MESSAGE.SET_TOKEN(token => G_SQLERRM_TOKEN, value => SQLERRM);
715         FND_MSG_PUB.add;
716 
717         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
718         RETURN lv_exists_flag;
719 
720 END IS_ACCOUNT_VALID;
721 
722 --===============================================================
723 -- IS_CONTACT_VALID - for Bill_to_Contact and Ship_to_Contact
724 --===============================================================
725 FUNCTION IS_CONTACT_VALID(p_contact_id    IN         NUMBER,
726                           p_party_id      IN         NUMBER,
727                           x_msg_data      OUT NOCOPY VARCHAR2,
728                           x_msg_count     OUT NOCOPY NUMBER,
729                           x_return_status OUT NOCOPY VARCHAR2)
730 RETURN VARCHAR2
731 IS
732 
733 --Check the party_type for the given party
734 
735  CURSOR c_party_type(p_party_id in number) IS
736   SELECT party_type
737    FROM  hz_parties
738   WHERE  party_id = p_party_id;
739 
740 CURSOR  c_contact_org(p_party_id in number,
741                       p_contact_id in number) IS
742 SELECT  rel.party_id
743 FROM    hz_relationships party_rel,
744         hz_parties sub,
745         hz_parties rel,
746         ar_lookups ar,
747         ar_lookups relm,
748         hz_relationship_types typ,
749         hz_code_assignments asg
750 WHERE   party_rel.object_id = p_party_id
751         AND party_rel.party_id =  rel.party_id
752         AND rel.party_id = p_contact_id
753         AND party_rel.subject_id = sub.party_id
754         AND sub.party_type = 'PERSON'
755         AND sub.status = 'A'
756         AND ar.lookup_type(+) = 'CONTACT_TITLE'
757         AND sub.person_pre_name_adjunct = ar.lookup_code(+)
758         AND relm.lookup_type(+) = 'PARTY_RELATIONS_TYPE'
759         AND party_rel.relationship_code = relm.lookup_code(+)
760         AND nvl(party_rel.start_date, sysdate-1) < sysdate
761         AND nvl(party_rel.end_date  , sysdate+1) > sysdate
762         AND party_rel.status = 'A'
763         AND asg.owner_table_name = 'HZ_RELATIONSHIP_TYPES'
764         AND asg.owner_table_id = typ.relationship_type_id
765         AND asg.class_category = 'RELATIONSHIP_TYPE_GROUP'
766         AND asg.class_code = 'PARTY_REL_GRP_CONTACTS'
767         AND typ.relationship_type = party_rel.relationship_type
768         AND party_rel.subject_type = 'PERSON'
769         AND party_rel.subject_table_name = 'HZ_PARTIES'
770         AND party_rel.object_type = 'ORGANIZATION'
771         AND party_rel.object_table_name = 'HZ_PARTIES'
772         AND party_rel.relationship_code = typ.forward_rel_code;
773 
774 CURSOR  c_contact_person(p_party_id number,p_contact_id number) IS
775 SELECT  rel.party_id
776 FROM    hz_relationships party_rel,
777         hz_parties sub,
778         hz_parties rel,
779         ar_lookups ar,
780         ar_lookups relm,
781         hz_relationship_types typ,
782         hz_code_assignments asg
783 WHERE   party_rel.object_id = p_party_id
784         AND party_rel.party_id = rel.party_id
785         AND rel.party_id = p_contact_id
786         AND party_rel.subject_id = sub.party_id
787         AND sub.party_type = 'PERSON'
788         AND ar.lookup_type(+) = 'CONTACT_TITLE'
789         AND sub.person_pre_name_adjunct = ar.lookup_code(+)
790         AND relm.lookup_type(+) = 'PARTY_RELATIONS_TYPE'
791         AND party_rel.relationship_code = relm.lookup_code(+)
792         AND nvl(party_rel.start_date, sysdate-1) < sysdate
793         AND nvl(party_rel.end_date  , sysdate+1) > sysdate
794         AND party_rel.status = 'A'
795         AND asg.owner_table_name = 'HZ_RELATIONSHIP_TYPES'
796         AND asg.owner_table_id = typ.relationship_type_id
797         AND asg.class_category = 'RELATIONSHIP_TYPE_GROUP'
798         AND asg.class_code = 'PARTY_REL_GRP_CONTACTS'
799         AND typ.relationship_type = party_rel.relationship_type
800         AND party_rel.subject_type = 'PERSON'
801         AND party_rel.subject_table_name = 'HZ_PARTIES'
802         AND party_rel.object_type = 'PERSON' -- added for bug # 4744186
803         AND party_rel.object_table_name = 'HZ_PARTIES'
804         AND party_rel.relationship_code = typ.forward_rel_code;
805 
806 lv_exists_flag VARCHAR2(1) := 'N';
807 lv_party_type VARCHAR2(30);
808 lv_type_found VARCHAR2(1) := 'N';
809 
810 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'is_contact_valid';
811 
812 BEGIN
813 
814 x_return_status := FND_API.G_RET_STS_SUCCESS;
815 
816    FOR v_party_type IN c_party_type(p_party_id)
817      LOOP
818        lv_type_found := 'Y';
819        lv_party_type := v_party_type.party_type;
820      END LOOP ;
821 
822      IF lv_type_found = 'Y' THEN
823       IF lv_party_type = 'ORGANIZATION' THEN
824         FOR v_contact_org IN c_contact_org(p_party_id , p_contact_id)LOOP
825           lv_exists_flag := 'Y';
826         END LOOP;
827       ELSE
828          IF lv_party_type = 'PERSON'
829          THEN
830             /* Start : 4744186 */
831             IF p_party_id = p_contact_id
832             THEN
833             /*If Bill to/ship to Party id is same as Bill to/ship to contact id and Bill to/ship to
834             party type is PERSON, there will not be any relationship*/
835                lv_exists_flag := 'Y';
836             ELSE
837             /* End : 4744186 */
838                FOR v_contact_person IN c_contact_person(p_party_id,  p_contact_id)
839                LOOP
840                   lv_exists_flag := 'Y';
841                END LOOP;
842             END IF;
843          END IF;
844       END IF;
845    ELSE
846       --lv_type_found = 'N'
847       lv_exists_flag := 'N';
848    END IF;
849 
850      RETURN lv_exists_flag;
851 
852 EXCEPTION
853 
854       WHEN OTHERS THEN
855 
856         FND_MESSAGE.SET_NAME(G_APP_NAME, G_DB_ERROR);
857         FND_MESSAGE.SET_TOKEN(token => G_PROG_NAME_TOKEN, value => l_prog_name);
858         FND_MESSAGE.SET_TOKEN(token => G_SQLCODE_TOKEN, value => SQLCODE);
859         FND_MESSAGE.SET_TOKEN(token => G_SQLERRM_TOKEN, value => SQLERRM);
860         FND_MSG_PUB.add;
861 
862         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
863         RETURN lv_exists_flag;
864 
865 END IS_CONTACT_VALID;
866 
867 
868 --===============================================================
869 -- IS_PARTY_SITE - for Bill_to_Accout and Ship_
870 --===============================================================
871 FUNCTION IS_PARTY_SITE_VALID(p_party_site_id IN         NUMBER,
872                              p_party_id      IN         NUMBER,
873                              p_val_mode      IN         VARCHAR2,
874                              x_msg_data      OUT NOCOPY VARCHAR2,
875                              x_msg_count     OUT NOCOPY NUMBER,
876                              x_return_status OUT NOCOPY VARCHAR2)
877 RETURN VARCHAR2
878 IS
879 
880 -- Cursor to check Bill To Party Site Id
881 
882 Cursor c_bill_to_party_site(p_party_site_id IN NUMBER,
883                             p_party_id      IN NUMBER) IS
884 SELECT site.party_site_id
885  FROM  HZ_PARTY_SITES site,
886        HZ_PARTY_SITE_USES site_use,
887        HZ_PARTIES party
888  WHERE site.party_site_id  = p_party_site_id
889        AND site.party_id   =  p_party_id
890        AND site.party_id   = party.party_id
891        AND site.party_site_id = site_use.party_site_id
892        AND nvl(site.status, 'A') = 'A'
893        AND site_use.site_use_type = 'BILL_TO';
894 
895 --Cursor to check Ship To Party Site Id
896 
897 Cursor c_ship_to_party_site(p_party_site_id IN NUMBER,
898                             p_party_id      IN NUMBER) IS
899 SELECT site.party_site_id
900  FROM  HZ_PARTY_SITES site,
901        HZ_PARTY_SITE_USES site_use,
902        HZ_PARTIES party
903  WHERE site.party_site_id  = p_party_site_id
904        AND site.party_id   =  p_party_id
905        AND site.party_id   = party.party_id
906        AND site.party_site_id = site_use.party_site_id
907        AND nvl(site.status, 'A') = 'A'
908        AND site_use.site_use_type = 'SHIP_TO';
909 
910 Cursor c_party_site(p_party_site_id IN NUMBER,
911                     p_party_id      IN NUMBER) IS
912 
913 SELECT site.party_site_id
914  FROM  HZ_PARTY_SITES site,
915        HZ_PARTIES party
916  WHERE site.party_site_id  = p_party_site_id
917        AND site.party_id   =  p_party_id
918        AND site.party_id   = party.party_id
919        AND nvl(site.status, 'A') = 'A';
920 
921 lv_exists_flag VARCHAR2(1) := 'N';
922 
923 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'is_party_site_valid';
924 
925 BEGIN
926 
927 x_return_status := FND_API.G_RET_STS_SUCCESS;
928 
929   IF p_val_mode = 'BILL_TO' THEN
930    FOR v_bill_to_party_site IN c_bill_to_party_site(p_party_site_id,
931                     p_party_id)
932      LOOP
933        lv_exists_flag := 'Y';
934      END LOOP ;
935   ELSIF  p_val_mode =  'SHIP_TO' THEN
936    FOR v_ship_to_party_site IN  c_ship_to_party_site(p_party_site_id,
937                      p_party_id)
938      LOOP
939        lv_exists_flag := 'Y';
940      END LOOP ;
941 
942   ELSE
943     -- the p_val_mode = 'NONE'
944     FOR v_party_site IN c_party_site(p_party_site_id,
945                                      p_party_id)
946       LOOP
947         lv_exists_flag := 'Y';
948       END LOOP;
949 
950   END IF;
951   RETURN lv_exists_flag;
952 
953 EXCEPTION
954 
955       WHEN OTHERS THEN
956 
957         FND_MESSAGE.SET_NAME(G_APP_NAME, G_DB_ERROR);
958         FND_MESSAGE.SET_TOKEN(token => G_PROG_NAME_TOKEN, value => l_prog_name);
959         FND_MESSAGE.SET_TOKEN(token => G_SQLCODE_TOKEN, value => SQLCODE);
960         FND_MESSAGE.SET_TOKEN(token => G_SQLERRM_TOKEN, value => SQLERRM);
961         FND_MSG_PUB.add;
962 
963         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
964         RETURN lv_exists_flag;
965 
966 END IS_PARTY_SITE_VALID;
967 
968 --======================================================
969 -- IS_CONTRACT_LINE VALID - for Contract Line Validation
970 --======================================================
971 
972 FUNCTION IS_CONTRACT_LINE_VALID(
973                  p_contract_line_id      IN NUMBER,
974                  x_contract_id           OUT NOCOPY NUMBER,
975                  x_msg_data              OUT NOCOPY VARCHAR2,
976                  x_msg_count             OUT NOCOPY NUMBER,
977                  x_return_status         OUT NOCOPY VARCHAR2)
978 RETURN VARCHAR2
979 IS
980 
981 Cursor c_check_contract_line IS
982 select id, chr_id
983 from okc_k_lines_b
984 where id = p_contract_line_id;
985 
986 l_contract_line_id NUMBER;
987 l_exists_flag VARCHAR2(1);
988 
989 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'is_contract_line_valid';
990 
991 
992 BEGIN
993    OPEN c_check_contract_line;
994    FETCH c_check_contract_line INTO l_contract_line_id, x_contract_id;
995    CLOSE c_check_contract_line;
996 
997    IF l_contract_line_id IS NOT NULL THEN
998      l_exists_flag := 'Y';
999    ELSE
1000      l_exists_flag := 'N';
1001    END IF;
1002 
1003   RETURN l_exists_flag;
1004 
1005 EXCEPTION
1006 
1007       WHEN OTHERS THEN
1008 
1009         FND_MESSAGE.SET_NAME(G_APP_NAME, G_DB_ERROR);
1010         FND_MESSAGE.SET_TOKEN(token => G_PROG_NAME_TOKEN, value => l_prog_name);
1011         FND_MESSAGE.SET_TOKEN(token => G_SQLCODE_TOKEN, value => SQLCODE);
1012         FND_MESSAGE.SET_TOKEN(token => G_SQLERRM_TOKEN, value => SQLERRM);
1013         FND_MSG_PUB.add;
1014 
1015         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1016         RETURN l_exists_flag;
1017 
1018 
1019 END;
1020 
1021 --======================================================
1022 -- IS_CONTRACT_VALID - for Contract Validation
1023 --======================================================
1024 
1025 -- Changed for R12 By mviswana
1026 FUNCTION IS_CONTRACT_VALID(
1027                  p_contract_id           IN         NUMBER,
1028                  x_msg_data              OUT NOCOPY VARCHAR2,
1029                  x_msg_count             OUT NOCOPY NUMBER,
1030                  x_return_status         OUT NOCOPY VARCHAR2)
1031 RETURN VARCHAR2
1032 IS
1033 
1034  --Commented this code AND PTY.OBJECT1_ID1 = p_customer_id
1035  --to resolve bug 3254006
1036 
1037  Cursor c_contract_check IS
1038   SELECT 'x'
1039   FROM OKC_K_HEADERS_ALL_B HDR
1040        --OKC_K_PARTY_ROLES_B PTY
1041   WHERE
1042   HDR.START_DATE IS NOT NULL AND
1043   HDR.END_DATE IS NOT NULL AND
1044   HDR.TEMPLATE_YN='N' AND
1045   -- HDR.ID=PTY.CHR_ID AND
1046   -- PTY.JTOT_OBJECT1_CODE='OKX_PARTY' AND
1047   HDR.ID = p_contract_id;
1048 
1049   -- Commented to Fix Bug # 3554509
1050 
1051   --AND
1052   --p_request_date between nvl(hdr.start_date,p_request_date) and
1053   --nvl(hdr.end_date,p_request_date);
1054   --AND PTY.OBJECT1_ID1 = p_customer_id  ;
1055 
1056 
1057 
1058 lv_exists_flag VARCHAR2(1) := 'N';
1059 lv_check_flag VARCHAR2(1) := 'N';
1060 
1061 
1062 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'is_contract_valid';
1063 
1064 BEGIN
1065 
1066 x_return_status := FND_API.G_RET_STS_SUCCESS;
1067 
1068 
1069   FOR v_contract_check in c_contract_check LOOP
1070     lv_check_flag := 'Y';
1071     ------DBMS_OUTPUT.PUT_LINE('Found contract');
1072 
1073   END LOOP;
1074 
1075   IF lv_check_flag = 'Y' THEN
1076     lv_exists_flag := 'Y';
1077   ELSE
1078     lv_exists_flag := 'N';
1079   END IF;
1080 
1081 
1082   RETURN lv_exists_flag;
1083 
1084 EXCEPTION
1085 
1086       WHEN OTHERS THEN
1087 
1088         FND_MESSAGE.SET_NAME(G_APP_NAME, G_DB_ERROR);
1089         FND_MESSAGE.SET_TOKEN(token => G_PROG_NAME_TOKEN, value => l_prog_name);
1090         FND_MESSAGE.SET_TOKEN(token => G_SQLCODE_TOKEN, value => SQLCODE);
1091         FND_MESSAGE.SET_TOKEN(token => G_SQLERRM_TOKEN, value => SQLERRM);
1092         FND_MSG_PUB.add;
1093 
1094         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1095         RETURN lv_exists_flag;
1096 
1097 END;
1098 
1099 --==============================================================
1100 -- FUNCTION GET_CONTRACT_LINE_ID
1101 --==============================================================
1102 
1103 FUNCTION GET_CONTRACT_LINE_ID(
1104                  p_coverage_id        IN         NUMBER,
1105                  x_msg_data           OUT NOCOPY VARCHAR2,
1106                  x_msg_count          OUT NOCOPY NUMBER,
1107                  x_return_status      OUT NOCOPY VARCHAR2) RETURN NUMBER IS
1108 
1109 CURSOR c_k_line IS
1110 SELECT cle_id
1111 FROM   okc_k_lines_b
1112 WHERE  id = p_coverage_id;
1113 
1114 lv_temp NUMBER := 0;
1115 
1116 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'get_contract_line_id';
1117 
1118 BEGIN
1119 
1120 x_return_status := FND_API.G_RET_STS_SUCCESS;
1121 
1122 OPEN c_k_line;
1123 FETCH c_k_line INTO lv_temp;
1124 CLOSE c_k_line;
1125 
1126 RETURN lv_temp;
1127 
1128 EXCEPTION
1129 
1130       WHEN OTHERS THEN
1131 
1132         FND_MESSAGE.SET_NAME(G_APP_NAME, G_DB_ERROR);
1133         FND_MESSAGE.SET_TOKEN(token => G_PROG_NAME_TOKEN, value => l_prog_name);
1134         FND_MESSAGE.SET_TOKEN(token => G_SQLCODE_TOKEN, value => SQLCODE);
1135         FND_MESSAGE.SET_TOKEN(token => G_SQLERRM_TOKEN, value => SQLERRM);
1136         FND_MSG_PUB.add;
1137 
1138         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1139         RETURN lv_temp;
1140 
1141 END GET_CONTRACT_LINE_ID;
1142 
1143 --========================================================
1144 -- IS_UOM_VALID - For Uom Validation
1145 --========================================================
1146 FUNCTION IS_UOM_VALID(p_uom_code       IN         VARCHAR2,
1147                       p_inv_id         IN         NUMBER,
1148                       x_msg_data       OUT NOCOPY VARCHAR2,
1149                       x_msg_count      OUT NOCOPY NUMBER,
1150                       x_return_status  OUT NOCOPY VARCHAR2)
1151 RETURN VARCHAR2
1152 IS
1153 
1154 
1155 Cursor c_uom_code(p_uom_code IN VARCHAR2,
1156                   p_inv_id IN NUMBER) IS
1157  SELECT   uom_code
1158    FROM   MTL_ITEM_UOMS_VIEW
1159    WHERE  uom_code = p_uom_code  AND
1160           inventory_item_id = P_INV_ID AND
1161           organization_id = cs_std.get_item_valdn_orgzn_id ;
1162 
1163 lv_exists_flag VARCHAR2(1) := 'N';
1164 
1165 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'is_uom_valid';
1166 
1167 BEGIN
1168 
1169 x_return_status := FND_API.G_RET_STS_SUCCESS;
1170 
1171   FOR v_uom_code IN c_uom_code(p_uom_code,
1172                                p_inv_id) LOOP
1173     lv_exists_flag := 'Y';
1174   END LOOP;
1175   RETURN lv_exists_flag;
1176 
1177 EXCEPTION
1178 
1179       WHEN OTHERS THEN
1180 
1181         FND_MESSAGE.SET_NAME(G_APP_NAME, G_DB_ERROR);
1182         FND_MESSAGE.SET_TOKEN(token => G_PROG_NAME_TOKEN, value => l_prog_name);
1183         FND_MESSAGE.SET_TOKEN(token => G_SQLCODE_TOKEN, value => SQLCODE);
1184         FND_MESSAGE.SET_TOKEN(token => G_SQLERRM_TOKEN, value => SQLERRM);
1185         FND_MSG_PUB.add;
1186 
1187         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1188         RETURN lv_exists_flag;
1189 END;
1190 
1191 --=========================================================
1192 -- IS_INSTANCE_FOR_INVENTORY
1193 --=========================================================
1194 FUNCTION IS_INSTANCE_FOR_INVENTORY(p_instance_id    IN         NUMBER,
1195                                    p_inv_id         IN         NUMBER,
1196                                    x_msg_data       OUT NOCOPY VARCHAR2,
1197                                    x_msg_count      OUT NOCOPY NUMBER,
1198                                    x_return_status  OUT NOCOPY VARCHAR2)
1199 RETURN VARCHAR2
1200 IS
1201 
1202 --Cursor to check valid instnace_id*
1203 
1204 Cursor c_instance(p_instance_id IN NUMBER,
1205                   p_inv_id      IN NUMBER) IS
1206   SELECT instance_id
1207     FROM csi_item_instances
1208    WHERE instance_id = p_instance_id
1209      AND inventory_item_id = p_inv_id;
1210      --AND INV_MASTER_ORGANIZATION_ID = cs_std.get_item_valdn_orgzn_id;
1211 
1212 lv_exists_flag VARCHAR2(1) := 'N';
1213 
1214 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'is_instance_for_inventory';
1215 
1216 BEGIN
1217 
1218 x_return_status := FND_API.G_RET_STS_SUCCESS;
1219 
1220   FOR v_instance IN c_instance(p_instance_id,
1221                                p_inv_id) LOOP
1222     lv_exists_flag := 'Y';
1223 
1224   END LOOP;
1225 
1226   RETURN lv_exists_flag;
1227 
1228 EXCEPTION
1229 
1230       WHEN OTHERS THEN
1231 
1232         FND_MESSAGE.SET_NAME(G_APP_NAME, G_DB_ERROR);
1233         FND_MESSAGE.SET_TOKEN(token => G_PROG_NAME_TOKEN, value => l_prog_name);
1234         FND_MESSAGE.SET_TOKEN(token => G_SQLCODE_TOKEN, value => SQLCODE);
1235         FND_MESSAGE.SET_TOKEN(token => G_SQLERRM_TOKEN, value => SQLERRM);
1236         FND_MSG_PUB.add;
1237 
1238         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1239         RETURN lv_exists_flag;
1240 END;
1241 
1242 --=========================================================
1243 -- IS_INSTANCE_VALID
1244 --=========================================================
1245 FUNCTION IS_INSTANCE_VALID(p_instance_id    IN         NUMBER,
1246                            p_party_id       IN         NUMBER,
1247                            x_msg_data       OUT NOCOPY VARCHAR2,
1248                            x_msg_count      OUT NOCOPY NUMBER,
1249                            x_return_status  OUT NOCOPY VARCHAR2)
1250 RETURN VARCHAR2
1251 IS
1252 
1253 CURSOR c_instance IS
1254    SELECT 'Y'
1255     FROM  CSI_ITEM_INSTANCES cp,
1256           MTL_SYSTEM_ITEMS_KFV ITEMS
1257     WHERE cp.instance_id = p_instance_id AND
1258           CP.OWNER_PARTY_SOURCE_TABLE = 'HZ_PARTIES' AND
1259           cp.owner_party_id = p_party_id AND
1260           ITEMS.INVENTORY_ITEM_ID = CP.INVENTORY_ITEM_ID AND
1261           ITEMS.ORGANIZATION_ID = cs_std.get_item_valdn_orgzn_id AND
1262           exists (select 'x'
1263                     from csi_i_parties cip
1264                     where cip.party_id = p_party_id
1265                           and cip.instance_id = cp.instance_id
1266                           and cip.party_source_table = 'HZ_PARTIES')AND
1267                           (
1268                           (fnd_profile.value('CS_SR_RESTRICT_IB') = 'YES'
1269                            and CP.LOCATION_TYPE_CODE IN('HZ_PARTY_SITES','HZ_LOCATIONS'))
1270                            or (fnd_profile.value('CS_SR_RESTRICT_IB') <> 'YES'));
1271 
1272 lv_exists_flag VARCHAR2(1) := 'N';
1273 
1274 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'is_instance_valid';
1275 
1276 BEGIN
1277 
1278 x_return_status := FND_API.G_RET_STS_SUCCESS;
1279 
1280 OPEN c_instance;
1281 FETCH c_instance INTO lv_exists_flag;
1282 CLOSE c_instance;
1283 
1284   RETURN lv_exists_flag;
1285 
1286 EXCEPTION
1287 
1288       WHEN OTHERS THEN
1289 
1290         FND_MESSAGE.SET_NAME(G_APP_NAME, G_DB_ERROR);
1291         FND_MESSAGE.SET_TOKEN(token => G_PROG_NAME_TOKEN, value => l_prog_name);
1292         FND_MESSAGE.SET_TOKEN(token => G_SQLCODE_TOKEN, value => SQLCODE);
1293         FND_MESSAGE.SET_TOKEN(token => G_SQLERRM_TOKEN, value => SQLERRM);
1294         FND_MSG_PUB.add;
1295 
1296         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1297         RETURN lv_exists_flag;
1298 END;
1299 
1300 --==========================================================
1301 --IS_INSTANCE_SERIAL_VALID
1302 --==========================================================
1303 
1304 FUNCTION IS_INSTANCE_SERIAL_VALID( p_instance_id   IN         NUMBER
1305                                   ,p_serial_number IN         VARCHAR
1306                                   ,x_msg_data      OUT NOCOPY VARCHAR2
1307                                   ,x_msg_count     OUT NOCOPY NUMBER
1308                                   ,x_return_status OUT NOCOPY VARCHAR2)
1309 
1310 RETURN VARCHAR2
1311 IS
1312 
1313 Cursor c_instance_serial_number IS
1314   SELECT 'Y'
1315     FROM csi_item_instances
1316    WHERE instance_id = p_instance_id
1317      AND serial_number = p_serial_number;
1318 
1319 lv_exists_flag VARCHAR2(1) := 'N';
1320 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'is_instance_serial_number_valid';
1321 
1322 BEGIN
1323 
1324 x_return_status := FND_API.G_RET_STS_SUCCESS;
1325 
1326 --DBMS_OUTPUT.PUT_LINE('In IS_INSTANCE_SERIAL_VALID ');
1327 
1328 OPEN c_instance_serial_number;
1329 FETCH c_instance_serial_number INTO lv_exists_flag;
1330 CLOSE c_instance_serial_number;
1331 
1332 --DBMS_OUTPUT.PUT_LINE('lv_exists_flag');
1333 
1334 RETURN lv_exists_flag;
1335 
1336 EXCEPTION
1337 
1338       WHEN OTHERS THEN
1339         --DBMS_OUTPUT.PUT_LINE('MAYA');
1340 
1341         FND_MESSAGE.SET_NAME(G_APP_NAME, G_DB_ERROR);
1342         FND_MESSAGE.SET_TOKEN(token => G_PROG_NAME_TOKEN, value => l_prog_name);
1343         FND_MESSAGE.SET_TOKEN(token => G_SQLCODE_TOKEN, value => SQLCODE);
1344         FND_MESSAGE.SET_TOKEN(token => G_SQLERRM_TOKEN, value => SQLERRM);
1345         FND_MSG_PUB.add;
1346 
1347         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1348         RETURN lv_exists_flag;
1349 
1350 END IS_INSTANCE_SERIAL_VALID ;
1351 
1352 --==========================================================
1353 --IS_PRICE_LIST_VALID
1354 --=========================================================
1355 FUNCTION IS_PRICE_LIST_VALID(p_price_list_id  IN         NUMBER,
1356                              x_msg_data       OUT NOCOPY VARCHAR2,
1357                              x_msg_count      OUT NOCOPY NUMBER,
1358                              x_return_status  OUT NOCOPY VARCHAR2
1359                            )
1360 RETURN VARCHAR2
1361 IS
1362 
1363 Cursor c_price_list(p_price_list_id IN NUMBER) IS
1364 SELECT list_header_id
1365 FROM   QP_LIST_HEADERS_B
1366 WHERE  list_type_code in ('PRL','AGR')
1367 AND    list_header_id = p_price_list_id
1368 AND    sysdate between nvl(start_date_active,sysdate) and
1369        nvl(end_date_active,sysdate);
1370 
1371 lv_exists_flag VARCHAR2(1) := 'N';
1372 
1373 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'is_price_list_valid';
1374 
1375 BEGIN
1376 
1377 x_return_status := FND_API.G_RET_STS_SUCCESS;
1378 
1379   FOR v_price_list in c_price_list(p_price_list_id) LOOP
1380     lv_exists_flag := 'Y';
1381   END LOOP;
1382 
1383   RETURN lv_exists_flag;
1384 
1385 EXCEPTION
1386 
1387       WHEN OTHERS THEN
1388 
1389         FND_MESSAGE.SET_NAME(G_APP_NAME, G_DB_ERROR);
1390         FND_MESSAGE.SET_TOKEN(token => G_PROG_NAME_TOKEN, value => l_prog_name);
1391         FND_MESSAGE.SET_TOKEN(token => G_SQLCODE_TOKEN, value => SQLCODE);
1392         FND_MESSAGE.SET_TOKEN(token => G_SQLERRM_TOKEN, value => SQLERRM);
1393         FND_MSG_PUB.add;
1394 
1395         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1396         RETURN lv_exists_flag;
1397 END;
1398 
1399 --=========================================================
1400 --IS_TXN_INV_ORG_VALID - for transaction inv org validation
1401 --=========================================================
1402 
1403 FUNCTION IS_TXN_INV_ORG_VALID(p_txn_inv_org    IN         NUMBER,
1404                               p_org_id         IN         NUMBER,
1405                               x_msg_data       OUT NOCOPY VARCHAR2,
1406                               x_msg_count      OUT NOCOPY NUMBER,
1407                               x_return_status  OUT NOCOPY VARCHAR2)
1408 RETURN VARCHAR2
1409 IS
1410 
1411 CURSOR c_oper_unit_for_inv_org (p_txn_inv_org number) IS
1412 SELECT
1413 TO_NUMBER(hoi2.org_information3) OPERATING_UNIT
1414 FROM
1415 hr_organization_units hou,
1416 hr_organization_information hoi1,
1417 hr_organization_information hoi2,
1418 mtl_parameters mp
1419 WHERE
1420 mp.organization_id = p_txn_inv_org
1421 AND mp.organization_id = hou.organization_id
1422 AND hou.organization_id = hoi1.organization_id
1423 AND hoi1.org_information1 = 'INV'
1424 AND hoi1.org_information2 = 'Y'
1425 AND hoi1.org_information_context = 'CLASS'
1426 AND hou.organization_id = hoi2.organization_id
1427 AND hoi1.organization_id = hoi2.organization_id
1428 AND hoi2.org_information_context = 'Accounting Information' ;
1429 
1430 lv_exists_flag VARCHAR2(1) := 'N';
1431 
1432 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'is_txn_inv_org_valid';
1433 
1434 BEGIN
1435 
1436 x_return_status := FND_API.G_RET_STS_SUCCESS;
1437 
1438  FOR v_oper_unit_for_inv_org IN c_oper_unit_for_inv_org (p_txn_inv_org) LOOP
1439 
1440   IF v_oper_unit_for_inv_org.OPERATING_UNIT = p_org_id THEN
1441      lv_exists_flag := 'Y';
1442      EXIT;
1443   END IF;
1444  END LOOP;
1445 
1446  RETURN lv_exists_flag;
1447 
1448 EXCEPTION
1449 
1450       WHEN OTHERS THEN
1451 
1452         FND_MESSAGE.SET_NAME(G_APP_NAME, G_DB_ERROR);
1453         FND_MESSAGE.SET_TOKEN(token => G_PROG_NAME_TOKEN, value => l_prog_name);
1454         FND_MESSAGE.SET_TOKEN(token => G_SQLCODE_TOKEN, value => SQLCODE);
1455         FND_MESSAGE.SET_TOKEN(token => G_SQLERRM_TOKEN, value => SQLERRM);
1456         FND_MSG_PUB.add;
1457 
1458         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1459         RETURN lv_exists_flag;
1460 
1461 END;
1462 
1463 --------------------------------------------------------------------------------
1464 -- FUNCTION IS_ESTIMATE_DETAIL_ID_VALID
1465 --------------------------------------------------------------------------------
1466 FUNCTION IS_ESTIMATE_DETAIL_ID_VALID (p_estimate_detail_id IN         NUMBER,
1467                                       x_msg_data           OUT NOCOPY VARCHAR2,
1468                                       x_msg_count          OUT NOCOPY NUMBER,
1469                                       x_return_status      OUT NOCOPY VARCHAR2) RETURN VARCHAR2 IS
1470 
1471 Cursor c_estimate_detail_id IS
1472   SELECT 1
1473    FROM CS_ESTIMATE_DETAILS
1474   WHERE estimate_detail_id = p_estimate_detail_id;
1475 
1476   lv_exists_flag VARCHAR2(1) := 'N';
1477 
1478 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'is_estimate_detail_id_valid';
1479 
1480 BEGIN
1481 
1482 x_return_status := FND_API.G_RET_STS_SUCCESS;
1483 
1484   FOR v_estimate_detail_id IN c_estimate_detail_id LOOP
1485     lv_exists_flag := 'Y';
1486   END LOOP;
1487 
1488 RETURN lv_exists_flag;
1489 
1490 EXCEPTION
1491 
1492       WHEN OTHERS THEN
1493 
1494         FND_MESSAGE.SET_NAME(G_APP_NAME, G_DB_ERROR);
1495         FND_MESSAGE.SET_TOKEN(token => G_PROG_NAME_TOKEN, value => l_prog_name);
1496         FND_MESSAGE.SET_TOKEN(token => G_SQLCODE_TOKEN, value => SQLCODE);
1497         FND_MESSAGE.SET_TOKEN(token => G_SQLERRM_TOKEN, value => SQLERRM);
1498         FND_MSG_PUB.add;
1499 
1500         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1501         RETURN lv_exists_flag;
1502 
1503 END IS_ESTIMATE_DETAIL_ID_VALID;
1504 
1505 --------------------------------------------------------------------------------
1506 -- FUNCTION IS_ITEM_REVISION_VALID
1507 --------------------------------------------------------------------------------
1508 FUNCTION IS_ITEM_REVISION_VALID (p_inventory_item_id IN         NUMBER,
1509                                  p_item_revision     IN         VARCHAR2,
1510                                       x_msg_data           OUT NOCOPY VARCHAR2,
1511                                       x_msg_count          OUT NOCOPY NUMBER,
1512                                       x_return_status      OUT NOCOPY VARCHAR2) RETURN VARCHAR2 IS
1513 
1514 Cursor c_item_revision IS
1515   SELECT 1
1516   FROM MTL_ITEM_REVISIONS
1517   WHERE inventory_item_id = p_inventory_item_id and
1518         revision = p_item_revision and
1519         organization_id = cs_std.get_item_valdn_orgzn_id ;
1520 
1521   lv_exists_flag VARCHAR2(1) := 'N';
1522 
1523 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'is_item_revision_valid';
1524 
1525 BEGIN
1526 
1527 x_return_status := FND_API.G_RET_STS_SUCCESS;
1528 
1529   FOR v_item_revision IN c_item_revision LOOP
1530     lv_exists_flag := 'Y';
1531   END LOOP;
1532 
1533 RETURN lv_exists_flag;
1534 
1535 EXCEPTION
1536 
1537       WHEN OTHERS THEN
1538 
1539         FND_MESSAGE.SET_NAME(G_APP_NAME, G_DB_ERROR);
1540         FND_MESSAGE.SET_TOKEN(token => G_PROG_NAME_TOKEN, value => l_prog_name);
1541         FND_MESSAGE.SET_TOKEN(token => G_SQLCODE_TOKEN, value => SQLCODE);
1542         FND_MESSAGE.SET_TOKEN(token => G_SQLERRM_TOKEN, value => SQLERRM);
1543         FND_MSG_PUB.add;
1544 
1545         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1546         RETURN lv_exists_flag;
1547 
1548 END IS_ITEM_REVISION_VALID;
1549 
1550 --------------------------------------------------------------------------------
1551 -- FUNCTION IS_LINE_NUMBER_VALID
1552 --------------------------------------------------------------------------------
1553 FUNCTION IS_LINE_NUMBER_VALID(
1554                  p_line_number       IN         NUMBER,
1555                  p_incident_id       IN         NUMBER,
1556                  x_msg_data           OUT NOCOPY VARCHAR2,
1557                  x_msg_count          OUT NOCOPY NUMBER,
1558                  x_return_status      OUT NOCOPY VARCHAR2) RETURN VARCHAR2 IS
1559 
1560 Cursor c_line_number IS
1561   SELECT line_number
1562   FROM CS_ESTIMATE_DETAILS
1563   WHERE incident_id = p_incident_id and
1564         line_number = p_line_number;
1565 
1566 lv_exists_flag VARCHAR2(1) := 'N';
1567 
1568 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'is_line_number_valid';
1569 
1570 BEGIN
1571 
1572 x_return_status := FND_API.G_RET_STS_SUCCESS;
1573 
1574   IF p_line_number <= 0 THEN
1575      lv_exists_flag := 'Y';
1576   ELSE
1577      FOR v_line_number IN c_line_number LOOP
1578      lv_exists_flag := 'Y';
1579      END LOOP;
1580   END IF;
1581 
1582 RETURN lv_exists_flag;
1583 
1584 EXCEPTION
1585 
1586       WHEN OTHERS THEN
1587 
1588         FND_MESSAGE.SET_NAME(G_APP_NAME, G_DB_ERROR);
1589         FND_MESSAGE.SET_TOKEN(token => G_PROG_NAME_TOKEN, value => l_prog_name);
1590         FND_MESSAGE.SET_TOKEN(token => G_SQLCODE_TOKEN, value => SQLCODE);
1591         FND_MESSAGE.SET_TOKEN(token => G_SQLERRM_TOKEN, value => SQLERRM);
1592         FND_MSG_PUB.add;
1593 
1594         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1595         RETURN lv_exists_flag;
1596 
1597 END IS_LINE_NUMBER_VALID;
1598 
1599 --==========================================================
1600 --==========================================================
1601 --  API for upstream to Create Charge Details
1602 --==========================================================
1603 PROCEDURE Create_Charge_Details(
1604       p_api_version           IN  	  NUMBER,
1605       p_init_msg_list         IN 	  VARCHAR2 	:= FND_API.G_FALSE,
1606       p_commit                IN 	  VARCHAR2 	:= FND_API.G_FALSE,
1607       p_validation_level      IN  	  NUMBER 	:= FND_API.G_VALID_LEVEL_FULL,
1608       x_return_status         OUT NOCOPY  VARCHAR2,
1609       x_msg_count             OUT NOCOPY  NUMBER,
1610       x_object_version_number OUT NOCOPY  NUMBER,
1611       x_estimate_detail_id    OUT NOCOPY  NUMBER,
1612       x_line_number           OUT NOCOPY  NUMBER,
1613       x_msg_data              OUT NOCOPY  VARCHAR2,
1614       p_resp_appl_id          IN          NUMBER := FND_GLOBAL.RESP_APPL_ID,
1615       p_resp_id               IN          NUMBER := FND_GLOBAL.RESP_ID,
1616       p_user_id               IN          NUMBER := FND_GLOBAL.USER_ID,
1617       p_login_id              IN  	  NUMBER := NULL,
1618       p_transaction_control   IN          VARCHAR2      := FND_API.G_TRUE,
1619       p_est_detail_rec        IN          CS_Charge_Details_PUB.Charges_Rec_Type
1620 			) IS
1621 
1622 l_api_version       NUMBER                   :=  1.0 ;
1623 l_api_name          CONSTANT VARCHAR2(30)    := 'Create_Charge_Details' ;
1624 l_api_name_full     CONSTANT VARCHAR2(61)    :=  G_PKG_NAME || '.' || l_api_name ;
1625 l_log_module        CONSTANT VARCHAR2(255)   := 'cs.plsql.' || l_api_name_full || '.';
1626 l_return_status     VARCHAR2(1) ;
1627 l_est_detail_rec    CS_Charge_Details_PUB.Charges_Rec_Type;
1628 l_line_num          NUMBER               := 1 ;
1629 l_ed_id             NUMBER ;
1630 lx_org_id           NUMBER ;
1631 lx_profile          VARCHAR2(1);
1632 l_org_id            NUMBER ;
1633 
1634 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'create_charge_details';
1635 
1636 
1637 --DEBUG
1638 l_errm VARCHAR2(100);
1639 
1640 BEGIN
1641 
1642 --DBMS_OUTPUT.PUT_LINE('BEGIN create_charge_details');
1643 --DBMS_OUTPUT.PUT_LINE('submit_error_message is '||p_est_detail_rec.submit_error_message);
1644 
1645   -- Standard start of API savepoint
1646   IF FND_API.To_Boolean(p_transaction_control) THEN
1647     SAVEPOINT Create_Charge_Details_PVT;
1648   END IF ;
1649 
1650   -- Standard call to check for call compatibility
1651   IF NOT FND_API.Compatible_API_Call(l_api_version,
1652      p_api_version,
1653      l_api_name,
1654      G_PKG_NAME) THEN
1655     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1656   END IF;
1657 
1658   -- Initialize message list if p_init_msg_list is set to TRUE
1659   IF FND_API.To_Boolean(p_init_msg_list) THEN
1660     FND_MSG_PUB.Initialize;
1661   END IF;
1662 
1663   -- Initialize API return status to success
1664   x_return_status := FND_API.G_RET_STS_SUCCESS;
1665 
1666 ----------------------- FND Logging -----------------------------------
1667   IF FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level
1668   THEN
1669     FND_LOG.String
1670     ( FND_LOG.level_procedure , L_LOG_MODULE || 'start'
1671     , 'Inside ' || L_API_NAME_FULL || ', called with parameters below:'
1672     );
1673     FND_LOG.String
1674     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
1675     , 'p_api_version:' || p_api_version
1676     );
1677     FND_LOG.String
1678     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
1679     , 'p_init_msg_list:' || p_init_msg_list
1680     );
1681     FND_LOG.String
1682     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
1683     , 'p_commit:' || p_commit
1684     );
1685     FND_LOG.String
1686     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
1687     , 'p_validation_level:' || p_validation_level
1688     );
1689     FND_LOG.String
1690     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
1691     , 'p_resp_appl_id:' || p_resp_appl_id
1692     );
1693     FND_LOG.String
1694     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
1695     , 'p_resp_id:' || p_resp_id
1696     );
1697     FND_LOG.String
1698     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
1699     , 'p_user_id:' || p_user_id
1700     );
1701     FND_LOG.String
1702     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
1703     , 'p_login_id:' || p_login_id
1704     );
1705     FND_LOG.String
1706     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
1707     , 'p_transaction_control:' || p_transaction_control
1708     );
1709 
1710  -- --------------------------------------------------------------------------
1711  -- This procedure Logs the charges record paramters.
1712  -- --------------------------------------------------------------------------
1713     CS_Charge_Details_PUB.Log_Charges_Rec_Parameters
1714     ( p_Charges_Rec             =>  p_est_detail_rec
1715     );
1716 
1717   END IF;
1718 
1719   -- Make the preprocessing call to the user hooks
1720   --
1721   -- Pre call to the customer type user hook
1722   --
1723   IF jtf_usr_hks.Ok_To_Execute('CS_CHARGE_DETAILS_PVT',
1724                                'Create_Charge_Details',
1725 			       'B','C') THEN
1726 
1727     CS_CHARGE_DETAILS_CUHK.Create_Charge_Details_Pre(
1728 		p_api_version      	   => l_api_version,
1729 		p_init_msg_list    	   => FND_API.G_FALSE,
1730 		p_commit           	   => p_commit,
1731 		p_validation_level 	   => p_validation_level,
1732 		x_return_status    	   => l_return_status,
1733 		x_msg_count       	   => x_msg_count,
1734 		x_object_version_number    => x_object_version_number,
1735         	x_estimate_detail_id       => l_ed_id,
1736     	    	x_line_number              => l_line_num,
1737 		x_msg_data         	   => x_msg_data,
1738 		p_resp_appl_id    	   => p_resp_appl_id,
1739 		p_resp_id          	   => p_resp_id,
1740     		p_user_id          	   => p_user_id,
1741 		p_login_id         	   => p_login_id,
1742         	p_transaction_control      => p_transaction_control,
1743 		p_est_detail_rec           => p_est_detail_rec);
1744 
1745 
1746     IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
1747       FND_MESSAGE.Set_Name('CS', 'CS_API_CHG_ERR_PRE_CUST_USR_HK');
1748       FND_MESSAGE.Set_Token('API_NAME', l_api_name_full);
1749       FND_MSG_PUB.Add;
1750       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1751     END IF;
1752 
1753   END IF;
1754 
1755   --
1756   -- Pre call to the Vertical Type User Hook
1757   --
1758   IF jtf_usr_hks.Ok_To_Execute('CS_CHARGE_DETAILS_PVT',
1759                                'Create_Charge_Details',
1760                                'B', 'V')  THEN
1761 
1762     CS_CHARGE_DETAILS_VUHK.Create_Charge_Details_Pre(
1763 		p_api_version      	   => l_api_version,
1764 		p_init_msg_list    	   => FND_API.G_FALSE,
1765 		p_commit           	   => p_commit,
1766 		p_validation_level 	   => p_validation_level,
1767 		x_return_status    	   => l_return_status,
1768 		x_msg_count       	   => x_msg_count,
1769 		x_object_version_number    => x_object_version_number,
1770                 x_estimate_detail_id       => l_ed_id,
1771                 x_line_number              => l_line_num,
1772 		x_msg_data         	   => x_msg_data,
1773 		p_resp_appl_id    	   => p_resp_appl_id,
1774 		p_resp_id          	   => p_resp_id,
1775     	        p_user_id          	   => p_user_id,
1776 		p_login_id         	   => p_login_id,
1777                 p_transaction_control      => p_transaction_control,
1778 		p_est_detail_rec           => p_est_detail_rec);
1779 
1780 
1781     IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
1782       FND_MESSAGE.Set_Name('CS', 'CS_API_CHG_ERR_PRE_VERT_USR_HK');
1783       FND_MESSAGE.Set_Token('API_NAME', l_api_name_full);
1784       FND_MSG_PUB.Add;
1785       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1786     END IF;
1787 
1788   END IF;
1789 
1790   -- ======================================================================
1791   -- Apply business-rule validation to all required and passed parameters
1792   -- if validation level is set.
1793   -- ======================================================================
1794 
1795   IF (p_validation_level > FND_API.G_VALID_LEVEL_NONE) THEN
1796 
1797     --DBMS_OUTPUT.PUT_LINE('Calling VALIDATE_WHO_INFO');
1798     --DBMS_OUTPUT.PUT_LINE('p_user_id '|| p_user_id);
1799     --DBMS_OUTPUT.PUT_LINE('p_login_id '||p_login_id);
1800 
1801     Validate_Who_Info (p_api_name             => l_api_name_full,
1802                        p_user_id              => p_user_id,
1803                        p_login_id             => p_login_id,
1804                        x_return_status        => l_return_status);
1805 
1806     --DBMS_OUTPUT.PUT_LINE('Back from VALIDATE_WHO_INFO '||l_return_status);
1807 
1808     IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
1809       RAISE FND_API.G_EXC_ERROR;
1810     END IF;
1811 
1812     -- --DBMS_OUTPUT.PUT_LINE('Calling VALIDATE_CHARGE_DETAILS');
1813 
1814     --Validate the Charge Detail Record that is passed in by the Upstream Module
1815     VALIDATE_CHARGE_DETAILS(p_api_name           => l_api_name,
1816                             p_charges_detail_rec => p_est_detail_rec,
1817                             p_validation_mode    => 'I',
1818                             p_user_id            => p_user_id,
1819                             p_login_id           => p_login_id,
1820                             x_charges_detail_rec => l_est_detail_rec,
1821                             x_msg_data           => x_msg_data,
1822                             x_msg_count          => x_msg_count,
1823                             x_return_status      => l_return_status);
1824 
1825 
1826 
1827     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
1828       FND_MESSAGE.Set_Name('CS', 'CS_CHG_VALIDATE_CHRG_DETAIL_ER');
1829       FND_MESSAGE.Set_Token('API_NAME', l_api_name_full);
1830       FND_MSG_PUB.Add;
1831       RAISE FND_API.G_EXC_ERROR;
1832     END IF;
1833 
1834   --Fixed Bug # 3795144
1835   ELSE
1836     --p_validation_level = FND_API.G_VALID_LEVEL_NONE
1837     IF (p_validation_level = FND_API.G_VALID_LEVEL_NONE) THEN
1838       --populate the l_est_detail_rec record
1839       l_est_detail_rec := p_est_detail_rec;
1840     END IF;
1841   END IF ;
1842 
1843   -----------------------------------------
1844   -- Prepare to INSERT record into database
1845   -----------------------------------------
1846   -- Added fix for the bug:5125385
1847   -- commented this out as billing_engine and copy_to_estimate are failing
1848 
1849   -- dbms_output.put_line('Value of charge line number ' || l_est_detail_rec.line_number);
1850 
1851   IF l_est_detail_rec.line_number IS NOT NULL AND
1852      l_est_detail_rec.line_number <> FND_API.G_MISS_NUM THEN
1853 
1854      l_line_num := l_est_detail_rec.line_number;
1855 
1856   ELSE
1857 
1858   SELECT max(line_number) + 1
1859   INTO   l_line_num
1860   FROM   CS_ESTIMATE_DETAILS
1861   WHERE  incident_id = p_est_detail_rec.incident_id;
1862 
1863   END IF;
1864 
1865   l_line_num := NVL(l_line_num,1);
1866 
1867 
1868   SELECT cs_estimate_details_s.nextval
1869   INTO   l_ed_id
1870   FROM   DUAL ;
1871 
1872   --DBMS_OUTPUT.PUT_LINE('Calling CS_ESTIMATE_DETAILS_PKG.INSERT_ROW');
1873   --DBMS_OUTPUT.PUT_LINE('l_org_id = '||l_est_detail_rec.org_id);
1874   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.incident_id = '||l_est_detail_rec.incident_id);
1875   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.original_source_id = '||l_est_detail_rec.original_source_id);
1876   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.original_source_code = '||l_est_detail_rec.original_source_code);
1877   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.source_id = '||l_est_detail_rec.source_id);
1878   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.source_code = '||l_est_detail_rec.source_code);
1879   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.contract_id = '||l_est_detail_rec.contract_id);
1880   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.coverage_id = '||l_est_detail_rec.coverage_id);
1881   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.coverage_txn_group_id = '||l_est_detail_rec.coverage_txn_group_id);
1882   --DBMS_OUTPUT.PUT_LINE('l_EST_DETAIL_rec.currency_code = '||l_EST_DETAIL_rec.currency_code);
1883   --DBMS_OUTPUT.PUT_LINE('l_EST_DETAIL_rec.conversion_rate = '||l_EST_DETAIL_rec.conversion_rate);
1884   --DBMS_OUTPUT.PUT_LINE('l_EST_DETAIL_rec.conversion_rate_date = '||l_EST_DETAIL_rec.conversion_rate_date);
1885   --DBMS_OUTPUT.PUT_LINE('l_EST_DETAIL_rec.conversion_type_code = '||l_EST_DETAIL_rec.conversion_type_code);
1886   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.invoice_to_org_id = '||l_est_detail_rec.invoice_to_org_id);
1887   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.ship_to_org_id = '||l_est_detail_rec.ship_to_org_id);
1888   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.purchase_order_num = '||l_est_detail_rec.purchase_order_num);
1889   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.order_line_id = '||l_est_detail_rec.order_line_id);
1890   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.line_type_id = '||l_est_detail_rec.line_type_id);
1891   --DBMS_OUTPUT.PUT_LINE('l_EST_DETAIL_rec.LINE_CATEGORY_CODE = '||l_EST_DETAIL_rec.LINE_CATEGORY_CODE);
1892   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.price_list_id = '||l_est_detail_rec.price_list_id);
1893   --DBMS_OUTPUT.PUT_LINE('l_line_num = '||l_line_num);
1894   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.inventory_item_id_in = '||l_est_detail_rec.inventory_item_id_in);
1895   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.item_revision = '||l_est_detail_rec.item_revision);
1896   --DBMS_OUTPUT.PUT_LINE('l_EST_DETAIL_rec.SERIAL_NUMBER = '||l_EST_DETAIL_rec.SERIAL_NUMBER);
1897   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.quantity_required = '||l_est_detail_rec.quantity_required);
1898   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.unit_of_measure_code = '||l_est_detail_rec.unit_of_measure_code);
1899   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.selling_price = '||l_est_detail_rec.selling_price);
1900   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.after_warranty_cost = '||l_est_detail_rec.after_warranty_cost);
1901   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.business_process_id = '||l_est_detail_rec.business_process_id);
1902   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.transaction_type_id = '||l_est_detail_rec.transaction_type_id);
1903   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.customer_product_id = '||l_est_detail_rec.customer_product_id);
1904   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.order_header_id = '||l_est_detail_rec.order_header_id);
1905   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.installed_cp_return_by_date = '||l_est_detail_rec.installed_cp_return_by_date);
1906   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.new_cp_return_by_date = '||l_est_detail_rec.new_cp_return_by_date);
1907   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.interface_to_oe_flag = '||l_est_detail_rec.interface_to_oe_flag);
1908   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.rollup_flag = '||l_est_detail_rec.rollup_flag);
1909   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.no_charge_flag = '||l_est_detail_rec.no_charge_flag);
1910   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.add_to_order_flag = '||l_est_detail_rec.add_to_order_flag);
1911   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.return_reason_code = '||l_est_detail_rec.return_reason_code);
1912   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.generated_by_bca_engine = '||l_est_detail_rec.generated_by_bca_engine);
1913   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.transaction_inventory_org = '||l_est_detail_rec.transaction_inventory_org);
1914   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.transaction_sub_inventory = '||l_est_detail_rec.transaction_sub_inventory);
1915   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.charge_line_type = '||l_est_detail_rec.charge_line_type);
1916   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.ship_to_account_id = '||l_est_detail_rec.ship_to_account_id);
1917   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.bill_to_account_id = '||l_est_detail_rec.bill_to_account_id);
1918   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.ship_to_contact_id = '||l_est_detail_rec.ship_to_contact_id);
1919   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.bill_to_contact_id = '||l_est_detail_rec.bill_to_contact_id);
1920   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.list_price = '||l_est_detail_rec.list_price);
1921   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.activity_start_time = '||TO_CHAR(l_est_detail_rec.activity_start_time, 'DD-MON-YYYY HH24:MI:SS'));
1922   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.activity_end_time = '||TO_CHAR(l_est_detail_rec.activity_end_time, 'DD-MON-YYYY HH24:MI:SS'));
1923   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.contract_discount_amount = '||l_est_detail_rec.contract_discount_amount);
1924   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.bill_to_party_id = '||l_est_detail_rec.bill_to_party_id);
1925   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.ship_to_party_id = '||l_est_detail_rec.ship_to_party_id);
1926   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.coverage_bill_rate_id = '||l_est_detail_rec.coverage_bill_rate_id);
1927   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.txn_billing_type_id = '||l_est_detail_rec.txn_billing_type_id);
1928   --DBMS_OUTPUT.PUT_LINE('p_login_id = '||p_login_id);
1929   --DBMS_OUTPUT.PUT_LINE('p_user_id = '||p_user_id);
1930   --DBMS_OUTPUT.PUT_LINE('p_user_id = '||p_user_id);
1931   --DBMS_OUTPUT.PUT_LINE('l_ed_id = '||l_ed_id);
1932 
1933   CS_ESTIMATE_DETAILS_PKG.Insert_Row(
1934     p_org_id                           => l_est_detail_rec.org_id,
1935     p_incident_id                      => l_est_detail_rec.incident_id,
1936     p_original_source_id               => l_est_detail_rec.original_source_id,
1937     p_original_source_code             => l_est_detail_rec.original_source_code,
1938     p_source_id                        => l_est_detail_rec.source_id,
1939     p_source_code                      => l_est_detail_rec.source_code,
1940     p_contract_line_id                 => l_est_detail_rec.contract_line_id,
1941     p_rate_type_code                   => l_est_detail_rec.rate_type_code,
1942     p_contract_id                      => l_est_detail_rec.contract_id,
1943     p_coverage_id                      => null,
1944     p_coverage_txn_group_id            => null,
1945     p_CURRENCY_CODE                    => l_EST_DETAIL_rec.currency_code,
1946     p_CONVERSION_RATE                  => l_EST_DETAIL_rec.conversion_rate,
1947     p_CONVERSION_TYPE_CODE             => l_EST_DETAIL_rec.conversion_type_code,
1948     p_CONVERSION_RATE_DATE             => l_EST_DETAIL_rec.conversion_rate_date,
1949     p_invoice_to_org_id                => l_est_detail_rec.invoice_to_org_id,
1950     p_ship_to_org_id                   => l_est_detail_rec.ship_to_org_id,
1951     p_purchase_order_num               => l_est_detail_rec.purchase_order_num,
1952     p_order_line_id                    => l_est_detail_rec.order_line_id,
1953     p_line_type_id                     => l_est_detail_rec.line_type_id,
1954     p_LINE_CATEGORY_CODE               => l_EST_DETAIL_rec.LINE_CATEGORY_CODE,
1955     p_price_list_header_id             => l_est_detail_rec.price_list_id,
1956     p_line_number                      => l_line_num,
1957     p_inventory_item_id                => l_est_detail_rec.inventory_item_id_in,
1958     p_item_revision	               => l_est_detail_rec.item_revision,
1959     p_SERIAL_NUMBER                    => l_EST_DETAIL_rec.SERIAL_NUMBER,
1960     p_quantity_required                => l_est_detail_rec.quantity_required,
1961     p_unit_of_measure_code             => l_est_detail_rec.unit_of_measure_code,
1962     p_selling_price                    => l_est_detail_rec.selling_price,
1963     p_after_warranty_cost              => l_est_detail_rec.after_warranty_cost,
1964     p_business_process_id              => l_est_detail_rec.business_process_id,
1965     p_transaction_type_id              => l_est_detail_rec.transaction_type_id,
1966     p_customer_product_id              => l_est_detail_rec.customer_product_id,
1967     p_order_header_id                  => l_est_detail_rec.order_header_id,
1968     p_installed_cp_return_by_date      => l_est_detail_rec.installed_cp_return_by_date,
1969     p_new_cp_return_by_date            => l_est_detail_rec.new_cp_return_by_date,
1970     p_interface_to_oe_flag             => nvl(l_est_detail_rec.interface_to_oe_flag, 'N'),
1971     p_rollup_flag                      => nvl(l_est_detail_rec.rollup_flag,'N'),
1972     p_no_charge_flag                   => nvl(l_est_detail_rec.no_charge_flag,'N'),
1973     p_add_to_order_flag                => nvl(l_est_detail_rec.add_to_order_flag,'N'),
1974     p_return_reason_code               => l_est_detail_rec.return_reason_code,
1975     p_generated_by_bca_engine_flag     => nvl(l_est_detail_rec.generated_by_bca_engine,'N'),
1976     p_transaction_inventory_org        => l_est_detail_rec.transaction_inventory_org,
1977     p_transaction_sub_inventory	       => l_est_detail_rec.transaction_sub_inventory,
1978     p_charge_line_type                 => l_est_detail_rec.charge_line_type,
1979     p_ship_to_account_id               => l_est_detail_rec.ship_to_account_id,
1980     p_invoice_to_account_id            => l_est_detail_rec.bill_to_account_id,
1981     p_ship_to_contact_id               => l_est_detail_rec.ship_to_contact_id,
1982     p_bill_to_contact_id               => l_est_detail_rec.bill_to_contact_id,
1983     p_list_price                       => l_est_detail_rec.list_price,
1984     p_activity_start_date_time         => l_est_detail_rec.activity_start_time,
1985     p_activity_end_date_time           => l_est_detail_rec.activity_end_time,
1986     p_contract_discount_amount         => l_est_detail_rec.contract_discount_amount,
1987     p_bill_to_party_id                 => l_est_detail_rec.bill_to_party_id,
1988     p_ship_to_party_id                 => l_est_detail_rec.ship_to_party_id,
1989     p_pricing_context                  => l_est_detail_rec.pricing_context,
1990     p_pricing_attribute1               => l_est_detail_rec.pricing_attribute1,
1991     p_pricing_attribute2               => l_est_detail_rec.pricing_attribute2,
1992     p_pricing_attribute3               => l_est_detail_rec.pricing_attribute3,
1993     p_pricing_attribute4               => l_est_detail_rec.pricing_attribute4,
1994     p_pricing_attribute5               => l_est_detail_rec.pricing_attribute5,
1995     p_pricing_attribute6               => l_est_detail_rec.pricing_attribute6,
1996     p_pricing_attribute7               => l_est_detail_rec.pricing_attribute7,
1997     p_pricing_attribute8               => l_est_detail_rec.pricing_attribute8,
1998     p_pricing_attribute9               => l_est_detail_rec.pricing_attribute9,
1999     p_pricing_attribute10              => l_est_detail_rec.pricing_attribute10,
2000     p_pricing_attribute11              => l_est_detail_rec.pricing_attribute11,
2001     p_pricing_attribute12              => l_est_detail_rec.pricing_attribute12,
2002     p_pricing_attribute13              => l_est_detail_rec.pricing_attribute13,
2003     p_pricing_attribute14              => l_est_detail_rec.pricing_attribute14,
2004     p_pricing_attribute15              => l_est_detail_rec.pricing_attribute15,
2005     p_pricing_attribute16              => l_est_detail_rec.pricing_attribute16,
2006     p_pricing_attribute17              => l_est_detail_rec.pricing_attribute17,
2007     p_pricing_attribute18              => l_est_detail_rec.pricing_attribute18,
2008     p_pricing_attribute19              => l_est_detail_rec.pricing_attribute19,
2009     p_pricing_attribute20              => l_est_detail_rec.pricing_attribute20,
2010     p_pricing_attribute21              => l_est_detail_rec.pricing_attribute21,
2011     p_pricing_attribute22              => l_est_detail_rec.pricing_attribute22,
2012     p_pricing_attribute23              => l_est_detail_rec.pricing_attribute23,
2013     p_pricing_attribute24              => l_est_detail_rec.pricing_attribute24,
2014     p_pricing_attribute25              => l_est_detail_rec.pricing_attribute25,
2015     p_pricing_attribute26              => l_est_detail_rec.pricing_attribute26,
2016     p_pricing_attribute27              => l_est_detail_rec.pricing_attribute27,
2017     p_pricing_attribute28              => l_est_detail_rec.pricing_attribute28,
2018     p_pricing_attribute29              => l_est_detail_rec.pricing_attribute29,
2019     p_pricing_attribute30              => l_est_detail_rec.pricing_attribute30,
2020     p_pricing_attribute31              => l_est_detail_rec.pricing_attribute31,
2021     p_pricing_attribute32              => l_est_detail_rec.pricing_attribute32,
2022     p_pricing_attribute33              => l_est_detail_rec.pricing_attribute33,
2023     p_pricing_attribute34              => l_est_detail_rec.pricing_attribute34,
2024     p_pricing_attribute35              => l_est_detail_rec.pricing_attribute35,
2025     p_pricing_attribute36              => l_est_detail_rec.pricing_attribute36,
2026     p_pricing_attribute37              => l_est_detail_rec.pricing_attribute37,
2027     p_pricing_attribute38              => l_est_detail_rec.pricing_attribute38,
2028     p_pricing_attribute39              => l_est_detail_rec.pricing_attribute39,
2029     p_pricing_attribute40              => l_est_detail_rec.pricing_attribute40,
2030     p_pricing_attribute41              => l_est_detail_rec.pricing_attribute41,
2031     p_pricing_attribute42              => l_est_detail_rec.pricing_attribute42,
2032     p_pricing_attribute43              => l_est_detail_rec.pricing_attribute43,
2033     p_pricing_attribute44              => l_est_detail_rec.pricing_attribute44,
2034     p_pricing_attribute45              => l_est_detail_rec.pricing_attribute45,
2035     p_pricing_attribute46              => l_est_detail_rec.pricing_attribute46,
2036     p_pricing_attribute47              => l_est_detail_rec.pricing_attribute47,
2037     p_pricing_attribute48              => l_est_detail_rec.pricing_attribute48,
2038     p_pricing_attribute49              => l_est_detail_rec.pricing_attribute49,
2039     p_pricing_attribute50              => l_est_detail_rec.pricing_attribute50,
2040     p_pricing_attribute51              => l_est_detail_rec.pricing_attribute51,
2041     p_pricing_attribute52              => l_est_detail_rec.pricing_attribute52,
2042     p_pricing_attribute53              => l_est_detail_rec.pricing_attribute53,
2043     p_pricing_attribute54              => l_est_detail_rec.pricing_attribute54,
2044     p_pricing_attribute55              => l_est_detail_rec.pricing_attribute55,
2045     p_pricing_attribute56              => l_est_detail_rec.pricing_attribute56,
2046     p_pricing_attribute57              => l_est_detail_rec.pricing_attribute57,
2047     p_pricing_attribute58              => l_est_detail_rec.pricing_attribute58,
2048     p_pricing_attribute59              => l_est_detail_rec.pricing_attribute59,
2049     p_pricing_attribute60              => l_est_detail_rec.pricing_attribute60,
2050     p_pricing_attribute61              => l_est_detail_rec.pricing_attribute61,
2051     p_pricing_attribute62              => l_est_detail_rec.pricing_attribute62,
2052     p_pricing_attribute63              => l_est_detail_rec.pricing_attribute63,
2053     p_pricing_attribute64              => l_est_detail_rec.pricing_attribute64,
2054     p_pricing_attribute65              => l_est_detail_rec.pricing_attribute65,
2055     p_pricing_attribute66              => l_est_detail_rec.pricing_attribute66,
2056     p_pricing_attribute67              => l_est_detail_rec.pricing_attribute67,
2057     p_pricing_attribute68              => l_est_detail_rec.pricing_attribute68,
2058     p_pricing_attribute69              => l_est_detail_rec.pricing_attribute69,
2059     p_pricing_attribute70              => l_est_detail_rec.pricing_attribute70,
2060     p_pricing_attribute71              => l_est_detail_rec.pricing_attribute71,
2061     p_pricing_attribute72              => l_est_detail_rec.pricing_attribute72,
2062     p_pricing_attribute73              => l_est_detail_rec.pricing_attribute73,
2063     p_pricing_attribute74              => l_est_detail_rec.pricing_attribute74,
2064     p_pricing_attribute75              => l_est_detail_rec.pricing_attribute75,
2065     p_pricing_attribute76              => l_est_detail_rec.pricing_attribute76,
2066     p_pricing_attribute77              => l_est_detail_rec.pricing_attribute77,
2067     p_pricing_attribute78              => l_est_detail_rec.pricing_attribute78,
2068     p_pricing_attribute79              => l_est_detail_rec.pricing_attribute79,
2069     p_pricing_attribute80              => l_est_detail_rec.pricing_attribute80,
2070     p_pricing_attribute81              => l_est_detail_rec.pricing_attribute81,
2071     p_pricing_attribute82              => l_est_detail_rec.pricing_attribute82,
2072     p_pricing_attribute83              => l_est_detail_rec.pricing_attribute83,
2073     p_pricing_attribute84              => l_est_detail_rec.pricing_attribute84,
2074     p_pricing_attribute85              => l_est_detail_rec.pricing_attribute85,
2075     p_pricing_attribute86              => l_est_detail_rec.pricing_attribute86,
2076     p_pricing_attribute87              => l_est_detail_rec.pricing_attribute87,
2077     p_pricing_attribute88              => l_est_detail_rec.pricing_attribute88,
2078     p_pricing_attribute89              => l_est_detail_rec.pricing_attribute89,
2079     p_pricing_attribute90              => l_est_detail_rec.pricing_attribute90,
2080     p_pricing_attribute91              => l_est_detail_rec.pricing_attribute91,
2081     p_pricing_attribute92              => l_est_detail_rec.pricing_attribute92,
2082     p_pricing_attribute93              => l_est_detail_rec.pricing_attribute93,
2083     p_pricing_attribute94              => l_est_detail_rec.pricing_attribute94,
2084     p_pricing_attribute95              => l_est_detail_rec.pricing_attribute95,
2085     p_pricing_attribute96              => l_est_detail_rec.pricing_attribute96,
2086     p_pricing_attribute97              => l_est_detail_rec.pricing_attribute97,
2087     p_pricing_attribute98              => l_est_detail_rec.pricing_attribute98,
2088     p_pricing_attribute99              => l_est_detail_rec.pricing_attribute99,
2089     p_pricing_attribute100             => l_est_detail_rec.pricing_attribute100,
2090     p_attribute1                       => l_est_detail_rec.attribute1,
2091     p_attribute2                       => l_est_detail_rec.attribute2,
2092     p_attribute3                       => l_est_detail_rec.attribute3,
2093     p_attribute4                       => l_est_detail_rec.attribute4,
2094     p_attribute5                       => l_est_detail_rec.attribute5,
2095     p_attribute6                       => l_est_detail_rec.attribute6,
2096     p_attribute7                       => l_est_detail_rec.attribute7,
2097     p_attribute8                       => l_est_detail_rec.attribute8,
2098     p_attribute9                       => l_est_detail_rec.attribute9,
2099     p_attribute10                      => l_est_detail_rec.attribute10,
2100     p_attribute11                      => l_est_detail_rec.attribute11,
2101     p_attribute12                      => l_est_detail_rec.attribute12,
2102     p_attribute13                      => l_est_detail_rec.attribute13,
2103     p_attribute14                      => l_est_detail_rec.attribute14,
2104     p_attribute15                      => l_est_detail_rec.attribute15,
2105     p_context                          => l_est_detail_rec.context,
2106     p_coverage_bill_rate_id            => l_est_detail_rec.coverage_bill_rate_id,
2107     p_coverage_billing_type_id         => null,
2108     p_txn_billing_type_id              => l_est_detail_rec.txn_billing_type_id,
2109     p_submit_restriction_message       => l_est_detail_rec.submit_restriction_message,
2110     p_submit_error_message             => l_est_detail_rec.submit_error_message,
2111     p_submit_from_system               => l_est_detail_rec.submit_from_system,
2112     p_line_submitted                   => nvl(l_est_detail_rec.line_submitted_flag, 'N'),
2113     p_last_update_date                 => sysdate,
2114     --p_last_update_login              => p_user_id,
2115     p_last_update_login                => p_login_id,
2116     p_last_updated_by                  => p_user_id,
2117     p_creation_date                    => sysdate,
2118     p_created_by                       => p_user_id,
2119     p_estimate_detail_id               => l_ed_id,
2120     x_object_version_number            => x_object_version_number );
2121 
2122   --DBMS_OUTPUT.PUT_LINE('Back from CS_ESTIMATE_DETAILS_PKG.INSERT_ROW. OVN '||x_object_version_number);
2123 
2124   -- hint: primary key should be returned.
2125   -- x_estimate_detail_id := x_estimate_detail_id;
2126 
2127   x_estimate_detail_id      := l_ed_id ;
2128   x_line_number             := nvl(l_line_num,1) ;
2129 
2130 
2131   -- Make the postprocessing call to the user hooks
2132   --
2133   -- Post call to the customer type user hook
2134   --
2135   IF jtf_usr_hks.Ok_To_Execute('CS_CHARGE_DETAILS_PVT',
2136  			       'Create_Charge_Details',
2137 			       'A','C') THEN
2138 
2139     CS_CHARGE_DETAILS_CUHK.Create_Charge_Details_Post(
2140 		p_api_version      	   => l_api_version,
2141 		p_init_msg_list    	   => FND_API.G_FALSE,
2142 		p_commit           	   => p_commit,
2143 		p_validation_level 	   => p_validation_level,
2144 		x_return_status    	   => l_return_status,
2145 		x_msg_count       	   => x_msg_count,
2146 		x_object_version_number    => x_object_version_number,
2147                 x_estimate_detail_id       => l_ed_id,
2148                 x_line_number              => l_line_num,
2149 		x_msg_data         	   => x_msg_data,
2150 		p_resp_appl_id    	   => p_resp_appl_id,
2151 		p_resp_id          	   => p_resp_id,
2152     	        p_user_id          	   => p_user_id,
2153 		p_login_id         	   => p_login_id,
2154                 p_transaction_control      => p_transaction_control,
2155 		p_est_detail_rec           => p_est_detail_rec);
2156 
2157 
2158     IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
2159       FND_MESSAGE.Set_Name('CS', 'CS_API_CHG_ERR_PST_CUST_USR_HK');
2160       FND_MESSAGE.Set_Token('API_NAME', l_api_name_full);
2161       FND_MSG_PUB.Add;
2162 
2163       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2164     END IF;
2165 
2166   END IF;
2167   --
2168   --
2169   -- Post call to the Vertical Type User Hook
2170   --
2171   IF jtf_usr_hks.Ok_To_Execute('CS_CHARGE_DETAILS_PVT',
2172                                'Create_Charge_Details',
2173                                'A', 'V')  THEN
2174 
2175     CS_CHARGE_DETAILS_VUHK.Create_Charge_Details_Post(
2176 		p_api_version      	   => l_api_version,
2177 		p_init_msg_list    	   => FND_API.G_FALSE,
2178 		p_commit           	   => p_commit,
2179 		p_validation_level 	   => p_validation_level,
2180 		x_return_status    	   => l_return_status,
2181 		x_msg_count       	   => x_msg_count,
2182 		x_object_version_number    => x_object_version_number,
2183        	        x_estimate_detail_id       => l_ed_id,
2184        	        x_line_number              => l_line_num,
2185 		x_msg_data         	   => x_msg_data,
2186 		p_resp_appl_id    	   => p_resp_appl_id,
2187 		p_resp_id          	   => p_resp_id,
2188     		p_user_id          	   => p_user_id,
2189 		p_login_id         	   => p_login_id,
2190        	        p_transaction_control      => p_transaction_control,
2191 		p_est_detail_rec           => p_est_detail_rec);
2192 
2193 
2194     IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
2195       FND_MESSAGE.Set_Name('CS', 'CS_API_CHG_ERR_PST_VERT_USR_HK');
2196       FND_MESSAGE.Set_Token('API_NAME', l_api_name_full);
2197       FND_MSG_PUB.Add;
2198       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2199     END IF;
2200   END IF;
2201 
2202 
2203   -- Standard check of p_commit
2204   IF FND_API.To_Boolean(p_commit) THEN
2205     COMMIT WORK;
2206   END IF;
2207 
2208   FND_MSG_PUB.Count_And_Get
2209     ( p_count => x_msg_count,
2210       p_data  => x_msg_data,
2211       p_encoded => FND_API.G_FALSE) ;
2212 
2213   EXCEPTION
2214 
2215     WHEN FND_API.G_EXC_ERROR THEN
2216 
2217       IF FND_API.To_Boolean(p_transaction_control) THEN
2218         ROLLBACK TO Create_Charge_Details_PVT;
2219       END IF ;
2220 
2221 
2222       FND_MSG_PUB.Count_And_Get(p_count    => x_msg_count,
2223                                 p_data     => x_msg_data,
2224                                 p_encoded  => FND_API.G_FALSE) ;
2225 
2226 
2227       x_return_status := FND_API.G_RET_STS_ERROR;
2228 
2229 
2230 
2231       WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2232 
2233       IF FND_API.To_Boolean(p_transaction_control) THEN
2234         ROLLBACK TO Create_Charge_Details_PVT;
2235       END IF ;
2236 
2237       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2238 
2239       FND_MSG_PUB.Count_And_Get(p_count => x_msg_count,
2240                               p_data    => x_msg_data,
2241                               p_encoded => FND_API.G_FALSE) ;
2242       WHEN OTHERS THEN
2243       --l_errm := SQLERRM;
2244       --DBMS_OUTPUT.PUT_LINE('OTHERS inside CREATE_CHARGE_DETAILS '||l_errm);
2245 
2246       IF FND_API.To_Boolean(p_transaction_control) THEN
2247         ROLLBACK TO Create_Charge_Details_PVT;
2248       END IF ;
2249 
2250       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2251 
2252       IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
2253         FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
2254       END IF;
2255 
2256       FND_MSG_PUB.Count_And_Get(p_count   => x_msg_count,
2257                                 p_data    => x_msg_data,
2258                                 p_encoded => FND_API.G_FALSE) ;
2259 
2260 END Create_Charge_Details;
2261 
2262 
2263 --=====================================================
2264 --API to Update Charge Details into CS_ESTIMATE_DETAILS
2265 --=====================================================
2266 
2267 PROCEDURE Update_Charge_Details(
2268         p_api_version           IN         NUMBER,
2269         p_init_msg_list         IN         VARCHAR2          := FND_API.G_FALSE,
2270         p_commit                IN         VARCHAR2          := FND_API.G_FALSE,
2271         p_validation_level      IN         NUMBER            := FND_API.G_VALID_LEVEL_FULL,
2272         x_return_status         OUT NOCOPY VARCHAR2,
2273         x_msg_count             OUT NOCOPY NUMBER,
2274         x_object_version_number OUT NOCOPY NUMBER,
2275         x_msg_data              OUT NOCOPY VARCHAR2,
2276       --p_resp_appl_id          IN         NUMBER            := NULL,
2277       --p_resp_id               IN         NUMBER            := NULL,
2278       --p_user_id               IN         NUMBER            := NULL,
2279         p_resp_appl_id          IN         NUMBER            := FND_GLOBAL.RESP_APPL_ID,
2280         p_resp_id               IN         NUMBER            := FND_GLOBAL.RESP_ID,
2281         p_user_id               IN         NUMBER            := FND_GLOBAL.USER_ID,
2282         p_login_id              IN         NUMBER            := NULL,
2283         p_transaction_control   IN         VARCHAR2          := FND_API.G_TRUE,
2284         p_est_detail_rec        IN         CS_Charge_Details_PUB.Charges_Rec_Type
2285                 ) IS
2286 
2287 l_api_version                     NUMBER                 :=  1.0 ;
2288 l_api_name                        VARCHAR2(30)           := 'Update_Charge_Details' ;
2289 l_api_name_full                   VARCHAR2(61)           :=  G_PKG_NAME || '.' || l_api_name ;
2290 l_log_module            CONSTANT  VARCHAR2(255)          := 'cs.plsql.' || l_api_name_full || '.';
2291 l_return_status                   VARCHAR2(1) ;
2292 
2293 l_line_num                        NUMBER                 :=  1 ;
2294 l_ed_id                           NUMBER ;
2295 l_org_id                          NUMBER ;
2296 l_est_detail_rec                  CS_Charge_Details_PUB.Charges_Rec_Type;
2297 
2298 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'update_charge_details';
2299 
2300 BEGIN
2301 
2302   --DBMS_OUTPUT.PUT_LINE('Updating Charge Details');
2303 
2304   -- Standard start of API savepoint
2305   IF FND_API.To_Boolean(p_transaction_control) THEN
2306     SAVEPOINT Update_Charge_Details_PVT;
2307   END IF ;
2308 
2309   -- Standard call to check for call compatibility
2310   IF NOT FND_API.Compatible_API_Call(l_api_version, p_api_version, l_api_name,
2311      G_PKG_NAME) THEN
2312     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2313   END IF;
2314 
2315   -- Initialize message list if p_init_msg_list is set to TRUE
2316   IF FND_API.To_Boolean(p_init_msg_list) THEN
2317     FND_MSG_PUB.Initialize;
2318   END IF;
2319 
2320   -- Initialize API return status to success
2321   x_return_status := FND_API.G_RET_STS_SUCCESS;
2322 
2323 ----------------------- FND Logging -----------------------------------
2324   IF FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level
2325   THEN
2326     FND_LOG.String
2327     ( FND_LOG.level_procedure , L_LOG_MODULE || 'start'
2328     , 'Inside ' || L_API_NAME_FULL || ', called with parameters below:'
2329     );
2330     FND_LOG.String
2331     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
2332     , 'p_api_version:' || p_api_version
2333     );
2334     FND_LOG.String
2335     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
2336     , 'p_init_msg_list:' || p_init_msg_list
2337     );
2338     FND_LOG.String
2339     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
2340     , 'p_commit:' || p_commit
2341     );
2342     FND_LOG.String
2343     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
2344     , 'p_validation_level:' || p_validation_level
2345     );
2346     FND_LOG.String
2347     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
2348     , 'p_resp_appl_id:' || p_resp_appl_id
2349     );
2350     FND_LOG.String
2351     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
2352     , 'p_resp_id:' || p_resp_id
2353     );
2354     FND_LOG.String
2355     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
2356     , 'p_user_id:' || p_user_id
2357     );
2358     FND_LOG.String
2359     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
2360     , 'p_login_id:' || p_login_id
2361     );
2362     FND_LOG.String
2363     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
2364     , 'p_transaction_control:' || p_transaction_control
2365     );
2366 
2367  -- --------------------------------------------------------------------------
2368  -- This procedure Logs the charges record paramters.
2369  -- --------------------------------------------------------------------------
2370     CS_Charge_Details_PUB.Log_Charges_Rec_Parameters
2371     ( p_Charges_Rec             =>  p_est_detail_rec
2372     );
2373 
2374   END IF;
2375 
2376   -- Make the preprocessing call to the user hooks
2377   --
2378   -- Pre call to the customer type user hook
2379   --
2380   IF jtf_usr_hks.Ok_To_Execute('CS_CHARGE_DETAILS_PVT',
2381                                'Update_Charge_Details',
2382                                'B','C') THEN
2383 
2384     CS_CHARGE_DETAILS_CUHK.Update_Charge_Details_Pre(
2385                   p_api_version              => l_api_version,
2386                   p_init_msg_list            => FND_API.G_FALSE,
2387                   p_commit                   => p_commit,
2388                   p_validation_level         => p_validation_level,
2389                   x_return_status            => l_return_status,
2390                   x_msg_count                => x_msg_count,
2391                   x_object_version_number    => x_object_version_number,
2392                   x_estimate_detail_id       => l_ed_id,
2393                   x_msg_data                 => x_msg_data,
2394                   p_resp_appl_id             => p_resp_appl_id,
2395                   p_resp_id                  => p_resp_id,
2396                   p_user_id                  => p_user_id,
2397                   p_login_id                 => p_login_id,
2398                   p_transaction_control      => p_transaction_control,
2399                   p_est_detail_rec           => p_est_detail_rec);
2400 
2401     IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
2402       FND_MESSAGE.Set_Name('CS', 'CS_API_CHG_ERR_PRE_CUST_USR_HK');
2403       FND_MESSAGE.Set_Token('API_NAME', l_api_name_full);
2404       FND_MSG_PUB.Add;
2405       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2406     END IF;
2407 
2408   END IF;
2409   --
2410   --
2411   -- Pre call to the Vertical Type User Hook
2412   --
2413   IF jtf_usr_hks.Ok_To_Execute('CS_CHARGE_DETAILS_PVT',
2414                                'Update_Charge_Details',
2415                                'B', 'V')  THEN
2416 
2417     CS_CHARGE_DETAILS_VUHK.Update_Charge_Details_Pre(
2418                 p_api_version              => l_api_version,
2419                 p_init_msg_list            => FND_API.G_FALSE,
2420                 p_commit                   => p_commit,
2421                 p_validation_level         => p_validation_level,
2422                 x_return_status            => l_return_status,
2423                 x_msg_count                => x_msg_count,
2424                 x_object_version_number    => x_object_version_number,
2425                 x_estimate_detail_id       => l_ed_id,
2426                 x_msg_data                 => x_msg_data,
2427                 p_resp_appl_id             => p_resp_appl_id,
2428                 p_resp_id                  => p_resp_id,
2429                 p_user_id                  => p_user_id,
2430                 p_login_id                 => p_login_id,
2431                 p_transaction_control      => p_transaction_control,
2432                 p_est_detail_rec           => p_est_detail_rec);
2433 
2434     IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
2435       FND_MESSAGE.Set_Name('CS', 'CS_API_CHG_ERR_PRE_VERT_USR_HK');
2436       FND_MESSAGE.Set_Token('API_NAME', l_api_name_full);
2437       FND_MSG_PUB.Add;
2438       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2439     END IF;
2440 
2441   END IF;
2442 
2443   -- ----------------------------------------------------------------------
2444   -- Apply business-rule validation to all required and passed parameters
2445   -- if validation level is set.
2446   -- ----------------------------------------------------------------------
2447   IF (p_validation_level > FND_API.G_VALID_LEVEL_NONE) THEN
2448 
2449     --  Validate the user and login ids
2450 
2451     Validate_Who_Info ( p_api_name             => l_api_name_full,
2452                         p_user_id              => NVL(p_user_id, -1),
2453                         p_login_id             => p_login_id,
2454                         x_return_status        => l_return_status);
2455 
2456     IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
2457       RAISE FND_API.G_EXC_ERROR;
2458     END IF;
2459 
2460     --DBMS_OUTPUT.PUT_LINE('validating charge details');
2461 
2462     -- Validate the Charge Detail Record that is passed in by the Upstream Module
2463     VALIDATE_CHARGE_DETAILS(p_api_name           => l_api_name,
2464                             p_charges_detail_rec => p_est_detail_rec,
2465                             p_validation_mode    => 'U',
2466                             p_user_id            => p_user_id,
2467                             p_login_id           => p_login_id,
2468                             x_charges_detail_rec => l_est_detail_rec,
2469                             x_msg_data           => x_msg_data,
2470                             x_msg_count          => x_msg_count,
2471                             x_return_status      => l_return_status);
2472 
2473     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2474       FND_MESSAGE.Set_Name('CS', 'CS_CHG_VALIDATE_CHRG_DETAIL_ER');
2475       FND_MESSAGE.Set_Token('API_NAME', l_api_name_full);
2476       FND_MSG_PUB.Add;
2477       RAISE FND_API.G_EXC_ERROR;
2478     END IF;
2479 
2480    --Fixed Bug # 3795144
2481    ELSE
2482     --p_validation_level = FND_API.G_VALID_LEVEL_NONE
2483     IF (p_validation_level = FND_API.G_VALID_LEVEL_NONE) THEN
2484       --populate the l_est_detail_rec record
2485       l_est_detail_rec := p_est_detail_rec;
2486     END IF;
2487    END IF ;
2488 
2489   --DBMS_OUTPUT.PUT_LINE('Calling CS_ESTIMATE_DETAILS_PKG.UPDATE_ROW');
2490   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.org_id = '||l_est_detail_rec.org_id);
2491   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.incident_id = '||l_est_detail_rec.incident_id);
2492   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.original_source_id = '||l_est_detail_rec.original_source_id);
2493   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.original_source_code = '||l_est_detail_rec.original_source_code);
2494   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.source_id = '||l_est_detail_rec.source_id);
2495   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.source_code = '||l_est_detail_rec.source_code);
2496   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.contract_id = '||l_est_detail_rec.contract_id);
2497   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.coverage_id = '||l_est_detail_rec.coverage_id);
2498   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.coverage_txn_group_id = '||l_est_detail_rec.coverage_txn_group_id);
2499   --DBMS_OUTPUT.PUT_LINE('l_EST_DETAIL_rec.currency_code = '||l_EST_DETAIL_rec.currency_code);
2500   --DBMS_OUTPUT.PUT_LINE('l_EST_DETAIL_rec.conversion_rate = '||l_EST_DETAIL_rec.conversion_rate);
2501   --DBMS_OUTPUT.PUT_LINE('l_EST_DETAIL_rec.conversion_rate_date = '||l_EST_DETAIL_rec.conversion_rate_date);
2502   --DBMS_OUTPUT.PUT_LINE('l_EST_DETAIL_rec.conversion_type_code = '||l_EST_DETAIL_rec.conversion_type_code);
2503   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.invoice_to_org_id = '||l_est_detail_rec.invoice_to_org_id);
2504   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.ship_to_org_id = '||l_est_detail_rec.ship_to_org_id);
2505   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.purchase_order_num = '||l_est_detail_rec.purchase_order_num);
2506   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.order_line_id = '||l_est_detail_rec.order_line_id);
2507   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.line_type_id = '||l_est_detail_rec.line_type_id);
2508   --DBMS_OUTPUT.PUT_LINE('l_EST_DETAIL_rec.LINE_CATEGORY_CODE = '||l_EST_DETAIL_rec.LINE_CATEGORY_CODE);
2509   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.price_list_id = '||l_est_detail_rec.price_list_id);
2510   --DBMS_OUTPUT.PUT_LINE('l_line_num = '||l_line_num);
2511   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.inventory_item_id_in = '||l_est_detail_rec.inventory_item_id_in);
2512   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.item_revision = '||l_est_detail_rec.item_revision);
2513   --DBMS_OUTPUT.PUT_LINE('l_EST_DETAIL_rec.SERIAL_NUMBER = '||l_EST_DETAIL_rec.SERIAL_NUMBER);
2514   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.quantity_required = '||l_est_detail_rec.quantity_required);
2515   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.unit_of_measure_code = '||l_est_detail_rec.unit_of_measure_code);
2516   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.selling_price = '||l_est_detail_rec.selling_price);
2517   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.after_warranty_cost = '||l_est_detail_rec.after_warranty_cost);
2518   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.business_process_id = '||l_est_detail_rec.business_process_id);
2519   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.transaction_type_id = '||l_est_detail_rec.transaction_type_id);
2520   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.customer_product_id = '||l_est_detail_rec.customer_product_id);
2521   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.order_header_id = '||l_est_detail_rec.order_header_id);
2522   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.installed_cp_return_by_date = '||l_est_detail_rec.installed_cp_return_by_date);
2523   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.new_cp_return_by_date = '||l_est_detail_rec.new_cp_return_by_date);
2524   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.interface_to_oe_flag = '||l_est_detail_rec.interface_to_oe_flag);
2525   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.rollup_flag = '||l_est_detail_rec.rollup_flag);
2526   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.no_charge_flag = '||l_est_detail_rec.no_charge_flag);
2527   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.add_to_order_flag = '||l_est_detail_rec.add_to_order_flag);
2528   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.return_reason_code = '||l_est_detail_rec.return_reason_code);
2529   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.generated_by_bca_engine = '||l_est_detail_rec.generated_by_bca_engine);
2530   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.transaction_inventory_org = '||l_est_detail_rec.transaction_inventory_org);
2531   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.transaction_sub_inventory = '||l_est_detail_rec.transaction_sub_inventory);
2532   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.charge_line_type = '||l_est_detail_rec.charge_line_type);
2533   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.ship_to_account_id = '||l_est_detail_rec.ship_to_account_id);
2534   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.bill_to_account_id = '||l_est_detail_rec.bill_to_account_id);
2535   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.ship_to_contact_id = '||l_est_detail_rec.ship_to_contact_id);
2536   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.bill_to_contact_id = '||l_est_detail_rec.bill_to_contact_id);
2537   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.list_price = '||l_est_detail_rec.list_price);
2538   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.activity_start_time = '||TO_CHAR(l_est_detail_rec.activity_start_time, 'DD-MON-YYYY HH24:MI:SS'));
2539   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.activity_end_time = '||TO_CHAR(l_est_detail_rec.activity_end_time, 'DD-MON-YYYY HH24:MI:SS'));
2540   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.contract_discount_amount = '||l_est_detail_rec.contract_discount_amount);
2541   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.bill_to_party_id = '||l_est_detail_rec.bill_to_party_id);
2542   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.ship_to_party_id = '||l_est_detail_rec.ship_to_party_id);
2543   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.coverage_bill_rate_id = '||l_est_detail_rec.coverage_bill_rate_id);
2544   --DBMS_OUTPUT.PUT_LINE('l_est_detail_rec.txn_billing_type_id = '||l_est_detail_rec.txn_billing_type_id);
2545   --DBMS_OUTPUT.PUT_LINE('p_login_id = '||p_login_id);
2546   --DBMS_OUTPUT.PUT_LINE('p_user_id = '||p_user_id);
2547   --DBMS_OUTPUT.PUT_LINE('p_user_id = '||p_user_id);
2548   --DBMS_OUTPUT.PUT_LINE('l_ed_id = '||l_ed_id);
2549   --DBMS_OUTPUT.PUT_LINE('Before  Update '||l_est_detail_rec.CONTRACT_ID);
2550 
2551   CS_ESTIMATE_DETAILS_PKG.Update_Row(
2552           x_object_version_number        => x_object_version_number,
2553           p_ESTIMATE_DETAIL_ID           => l_est_detail_rec.ESTIMATE_DETAIL_ID,
2554           p_ORG_ID                       => l_est_detail_rec.org_id,
2555           p_INCIDENT_ID                  => l_est_detail_rec.INCIDENT_ID,
2556           p_ORIGINAL_SOURCE_ID           => l_est_detail_rec.ORIGINAL_SOURCE_ID,
2557           p_ORIGINAL_SOURCE_CODE         => l_est_detail_rec.ORIGINAL_SOURCE_CODE,
2558           p_SOURCE_ID                    => l_est_detail_rec.SOURCE_ID,
2559           p_SOURCE_CODE                  => l_est_detail_rec.SOURCE_CODE,
2560           p_contract_line_id             => l_est_detail_rec.contract_line_id,
2561           p_rate_type_code               => l_est_detail_rec.rate_type_code,
2562           p_contract_id                  => l_est_detail_rec.CONTRACT_ID,
2563           p_coverage_id                  => null,
2564           p_coverage_txn_group_id        => null,
2565           --p_EXCEPTION_COVERAGE_USED    => l_est_detail_rec.EXCEPTION_COVERAGE_USED,
2566           p_CURRENCY_CODE                => l_est_detail_rec.currency_code,
2567           p_CONVERSION_RATE              => NULL,
2568           p_CONVERSION_TYPE_CODE         => NULL,
2569           p_CONVERSION_RATE_DATE         => NULL,
2570           p_INVOICE_TO_ORG_ID            => l_est_detail_rec.INVOICE_TO_ORG_ID,
2571           p_SHIP_TO_ORG_ID               => l_est_detail_rec.SHIP_TO_ORG_ID,
2572           p_PURCHASE_ORDER_NUM           => l_est_detail_rec.PURCHASE_ORDER_NUM,
2573           p_ORDER_LINE_ID                => l_est_detail_rec.ORDER_LINE_ID,
2574           p_LINE_TYPE_ID                 => l_est_detail_rec.LINE_TYPE_ID,
2575           p_LINE_CATEGORY_CODE           => l_est_detail_rec.LINE_CATEGORY_CODE,
2576           p_PRICE_LIST_HEADER_ID         => l_est_detail_rec.PRICE_LIST_ID,
2577           p_LINE_NUMBER                  => l_est_detail_rec.line_number,
2578           p_INVENTORY_ITEM_ID            => l_est_detail_rec.INVENTORY_ITEM_ID_in,
2579           p_ITEM_REVISION                => l_est_detail_rec.ITEM_REVISION,
2580           p_SERIAL_NUMBER                => l_est_detail_rec.SERIAL_NUMBER,
2581           p_QUANTITY_REQUIRED            => l_est_detail_rec.QUANTITY_REQUIRED,
2582           p_UNIT_OF_MEASURE_CODE         => l_est_detail_rec.UNIT_OF_MEASURE_CODE,
2583           p_SELLING_PRICE                => l_est_detail_rec.SELLING_PRICE,
2584           p_AFTER_WARRANTY_COST          => l_est_detail_rec.AFTER_WARRANTY_COST,
2585           --p_FUNC_CURR_AFT_WARR_COST    => l_est_detail_rec.FUNC_CURR_AFT_WARR_COST,
2586           p_BUSINESS_PROCESS_ID          => l_est_detail_rec.BUSINESS_PROCESS_ID,
2587           p_TRANSACTION_TYPE_ID          => l_est_detail_rec.TRANSACTION_TYPE_ID,
2588           p_CUSTOMER_PRODUCT_ID          => l_est_detail_rec.CUSTOMER_PRODUCT_ID,
2589           p_ORDER_HEADER_ID              => l_est_detail_rec.ORDER_HEADER_ID,
2590           p_INSTALLED_CP_RETURN_BY_DATE  => l_est_detail_rec.INSTALLED_CP_RETURN_BY_DATE,
2591           p_NEW_CP_RETURN_BY_DATE        => l_est_detail_rec.NEW_CP_RETURN_BY_DATE,
2592           p_INTERFACE_TO_OE_FLAG         => nvl(l_est_detail_rec.INTERFACE_TO_OE_FLAG, 'N'),
2593           p_ROLLUP_FLAG                  => nvl(l_est_detail_rec.ROLLUP_FLAG, 'N'),
2594           p_no_charge_flag               => nvl(l_est_detail_rec.NO_CHARGE_FLAG, 'N'),
2595           p_ADD_TO_ORDER_FLAG            => nvl(l_est_detail_rec.ADD_TO_ORDER_FLAG, 'N'),
2596           p_RETURN_REASON_CODE           => l_est_detail_rec.RETURN_REASON_CODE,
2597           p_GENERATED_BY_BCA_ENGINE_FLAG => nvl(l_est_detail_rec.GENERATED_BY_BCA_ENGINE, 'N'),
2598           p_TRANSACTION_INVENTORY_ORG    => l_est_detail_rec.TRANSACTION_INVENTORY_ORG,
2599           p_TRANSACTION_SUB_INVENTORY    => l_est_detail_rec.TRANSACTION_SUB_INVENTORY,
2600           p_CHARGE_LINE_TYPE             => l_est_detail_rec.CHARGE_LINE_TYPE,
2601           p_SHIP_TO_ACCOUNT_ID           => l_est_detail_rec.SHIP_TO_ACCOUNT_ID,
2602           p_INVOICE_TO_ACCOUNT_ID        => l_est_detail_rec.BILL_TO_ACCOUNT_ID,
2603           p_SHIP_TO_CONTACT_ID           => l_est_detail_rec.SHIP_TO_CONTACT_ID,
2604           p_BILL_TO_CONTACT_ID           => l_est_detail_rec.BILL_TO_CONTACT_ID,
2605           p_LIST_PRICE                   => l_est_detail_rec.LIST_PRICE,--mviswana
2606           p_ACTIVITY_START_DATE_TIME     => l_est_detail_rec.ACTIVITY_START_TIME,
2607           p_ACTIVITY_END_DATE_TIME       => l_est_detail_rec.ACTIVITY_END_TIME,
2608           p_CONTRACT_DISCOUNT_AMOUNT     => l_est_detail_rec.CONTRACT_DISCOUNT_AMOUNT,
2609           p_BILL_TO_PARTY_ID             => l_est_detail_rec.BILL_TO_PARTY_ID,
2610           p_SHIP_TO_PARTY_ID             => l_est_detail_rec.SHIP_TO_PARTY_ID,
2611           --p_tax_code                   => l_est_detail_rec.tax_code,
2612           --p_est_tax_amount             => l_est_detail_rec.est_tax_amount,
2613           p_PRICING_CONTEXT              => l_est_detail_rec.PRICING_CONTEXT,
2614           p_PRICING_ATTRIBUTE1           => l_est_detail_rec.PRICING_ATTRIBUTE1,
2615           p_PRICING_ATTRIBUTE2           => l_est_detail_rec.PRICING_ATTRIBUTE2,
2616           p_PRICING_ATTRIBUTE3           => l_est_detail_rec.PRICING_ATTRIBUTE3,
2617           p_PRICING_ATTRIBUTE4           => l_est_detail_rec.PRICING_ATTRIBUTE4,
2618           p_PRICING_ATTRIBUTE5           => l_est_detail_rec.PRICING_ATTRIBUTE5,
2619           p_PRICING_ATTRIBUTE6           => l_est_detail_rec.PRICING_ATTRIBUTE6,
2620           p_PRICING_ATTRIBUTE7           => l_est_detail_rec.PRICING_ATTRIBUTE7,
2621           p_PRICING_ATTRIBUTE8           => l_est_detail_rec.PRICING_ATTRIBUTE8,
2622           p_PRICING_ATTRIBUTE9           => l_est_detail_rec.PRICING_ATTRIBUTE9,
2623           p_PRICING_ATTRIBUTE10          => l_est_detail_rec.PRICING_ATTRIBUTE10,
2624           p_PRICING_ATTRIBUTE11          => l_est_detail_rec.PRICING_ATTRIBUTE11,
2625           p_PRICING_ATTRIBUTE12          => l_est_detail_rec.PRICING_ATTRIBUTE12,
2626           p_PRICING_ATTRIBUTE13          => l_est_detail_rec.PRICING_ATTRIBUTE13,
2627           p_PRICING_ATTRIBUTE14          => l_est_detail_rec.PRICING_ATTRIBUTE14,
2628           p_PRICING_ATTRIBUTE15          => l_est_detail_rec.PRICING_ATTRIBUTE15,
2629           p_PRICING_ATTRIBUTE16          => l_est_detail_rec.PRICING_ATTRIBUTE16,
2630           p_PRICING_ATTRIBUTE17          => l_est_detail_rec.PRICING_ATTRIBUTE17,
2631           p_PRICING_ATTRIBUTE18          => l_est_detail_rec.PRICING_ATTRIBUTE18,
2632           p_PRICING_ATTRIBUTE19          => l_est_detail_rec.PRICING_ATTRIBUTE19,
2633           p_PRICING_ATTRIBUTE20          => l_est_detail_rec.PRICING_ATTRIBUTE20,
2634           p_PRICING_ATTRIBUTE21          => l_est_detail_rec.PRICING_ATTRIBUTE21,
2635           p_PRICING_ATTRIBUTE22          => l_est_detail_rec.PRICING_ATTRIBUTE22,
2636           p_PRICING_ATTRIBUTE23          => l_est_detail_rec.PRICING_ATTRIBUTE23,
2637           p_PRICING_ATTRIBUTE24          => l_est_detail_rec.PRICING_ATTRIBUTE24,
2638           p_pricing_attribute25          => l_est_detail_rec.pricing_attribute25,
2639           p_pricing_attribute26          => l_est_detail_rec.pricing_attribute26,
2640           p_pricing_attribute27          => l_est_detail_rec.pricing_attribute27,
2641           p_pricing_attribute28          => l_est_detail_rec.pricing_attribute28,
2642           p_pricing_attribute29          => l_est_detail_rec.pricing_attribute29,
2643           p_pricing_attribute30          => l_est_detail_rec.pricing_attribute30,
2644           p_pricing_attribute31          => l_est_detail_rec.pricing_attribute31,
2645           p_pricing_attribute32          => l_est_detail_rec.pricing_attribute32,
2646           p_pricing_attribute33          => l_est_detail_rec.pricing_attribute33,
2647           p_pricing_attribute34          => l_est_detail_rec.pricing_attribute34,
2648           p_pricing_attribute35          => l_est_detail_rec.pricing_attribute35,
2649           p_pricing_attribute36          => l_est_detail_rec.pricing_attribute36,
2650           p_pricing_attribute37          => l_est_detail_rec.pricing_attribute37,
2651           p_pricing_attribute38          => l_est_detail_rec.pricing_attribute38,
2652           p_pricing_attribute39          => l_est_detail_rec.pricing_attribute39,
2653           p_pricing_attribute40          => l_est_detail_rec.pricing_attribute40,
2654           p_pricing_attribute41          => l_est_detail_rec.pricing_attribute41,
2655           p_pricing_attribute42          => l_est_detail_rec.pricing_attribute42,
2656           p_pricing_attribute43          => l_est_detail_rec.pricing_attribute43,
2657           p_pricing_attribute44          => l_est_detail_rec.pricing_attribute44,
2658           p_pricing_attribute45          => l_est_detail_rec.pricing_attribute45,
2659           p_pricing_attribute46          => l_est_detail_rec.pricing_attribute46,
2660           p_pricing_attribute47          => l_est_detail_rec.pricing_attribute47,
2661           p_pricing_attribute48          => l_est_detail_rec.pricing_attribute48,
2662           p_pricing_attribute49          => l_est_detail_rec.pricing_attribute49,
2663           p_pricing_attribute50          => l_est_detail_rec.pricing_attribute50,
2664           p_pricing_attribute51          => l_est_detail_rec.pricing_attribute51,
2665           p_pricing_attribute52          => l_est_detail_rec.pricing_attribute52,
2666           p_pricing_attribute53          => l_est_detail_rec.pricing_attribute53,
2667           p_pricing_attribute54          => l_est_detail_rec.pricing_attribute54,
2668           p_pricing_attribute55          => l_est_detail_rec.pricing_attribute55,
2669           p_pricing_attribute56          => l_est_detail_rec.pricing_attribute56,
2670           p_pricing_attribute57          => l_est_detail_rec.pricing_attribute57,
2671           p_pricing_attribute58          => l_est_detail_rec.pricing_attribute58,
2672           p_pricing_attribute59          => l_est_detail_rec.pricing_attribute59,
2673           p_pricing_attribute60          => l_est_detail_rec.pricing_attribute60,
2674           p_pricing_attribute61          => l_est_detail_rec.pricing_attribute61,
2675           p_pricing_attribute62          => l_est_detail_rec.pricing_attribute62,
2676           p_pricing_attribute63          => l_est_detail_rec.pricing_attribute63,
2677           p_pricing_attribute64          => l_est_detail_rec.pricing_attribute64,
2678           p_pricing_attribute65          => l_est_detail_rec.pricing_attribute65,
2679           p_pricing_attribute66          => l_est_detail_rec.pricing_attribute66,
2680           p_pricing_attribute67          => l_est_detail_rec.pricing_attribute67,
2681           p_pricing_attribute68          => l_est_detail_rec.pricing_attribute68,
2682           p_pricing_attribute69          => l_est_detail_rec.pricing_attribute69,
2683           p_pricing_attribute70          => l_est_detail_rec.pricing_attribute70,
2684           p_pricing_attribute71          => l_est_detail_rec.pricing_attribute71,
2685           p_pricing_attribute72          => l_est_detail_rec.pricing_attribute72,
2686           p_pricing_attribute73          => l_est_detail_rec.pricing_attribute73,
2687           p_pricing_attribute74          => l_est_detail_rec.pricing_attribute74,
2688           p_pricing_attribute75          => l_est_detail_rec.pricing_attribute75,
2689           p_pricing_attribute76          => l_est_detail_rec.pricing_attribute76,
2690           p_pricing_attribute77          => l_est_detail_rec.pricing_attribute77,
2691           p_pricing_attribute78          => l_est_detail_rec.pricing_attribute78,
2692           p_pricing_attribute79          => l_est_detail_rec.pricing_attribute79,
2693           p_pricing_attribute80          => l_est_detail_rec.pricing_attribute80,
2694           p_pricing_attribute81          => l_est_detail_rec.pricing_attribute81,
2695           p_pricing_attribute82          => l_est_detail_rec.pricing_attribute82,
2696           p_pricing_attribute83          => l_est_detail_rec.pricing_attribute83,
2697           p_pricing_attribute84          => l_est_detail_rec.pricing_attribute84,
2698           p_pricing_attribute85          => l_est_detail_rec.pricing_attribute85,
2699           p_pricing_attribute86          => l_est_detail_rec.pricing_attribute86,
2700           p_pricing_attribute87          => l_est_detail_rec.pricing_attribute87,
2701           p_pricing_attribute88          => l_est_detail_rec.pricing_attribute88,
2702           p_pricing_attribute89          => l_est_detail_rec.pricing_attribute89,
2703           p_pricing_attribute90          => l_est_detail_rec.pricing_attribute90,
2704           p_pricing_attribute91          => l_est_detail_rec.pricing_attribute91,
2705           p_pricing_attribute92          => l_est_detail_rec.pricing_attribute92,
2706           p_pricing_attribute93          => l_est_detail_rec.pricing_attribute93,
2707           p_pricing_attribute94          => l_est_detail_rec.pricing_attribute94,
2708           p_pricing_attribute95          => l_est_detail_rec.pricing_attribute95,
2709           p_pricing_attribute96          => l_est_detail_rec.pricing_attribute96,
2710           p_pricing_attribute97          => l_est_detail_rec.pricing_attribute97,
2711           p_pricing_attribute98          => l_est_detail_rec.pricing_attribute98,
2712           p_pricing_attribute99          => l_est_detail_rec.pricing_attribute99,
2713           p_pricing_attribute100         => l_est_detail_rec.pricing_attribute100,
2714           p_attribute1                   => l_est_detail_rec.attribute1,
2715           p_attribute2                   => l_est_detail_rec.attribute2,
2716           p_attribute3                   => l_est_detail_rec.attribute3,
2717           p_attribute4                   => l_est_detail_rec.attribute4,
2718           p_attribute5                   => l_est_detail_rec.attribute5,
2719           p_attribute6                   => l_est_detail_rec.attribute6,
2720           p_attribute7                   => l_est_detail_rec.attribute7,
2721           p_attribute8                   => l_est_detail_rec.attribute8,
2722           p_attribute9                   => l_est_detail_rec.attribute9,
2723           p_attribute10                  => l_est_detail_rec.attribute10,
2724           p_attribute11                  => l_est_detail_rec.attribute11,
2725           p_attribute12                  => l_est_detail_rec.attribute12,
2726           p_attribute13                  => l_est_detail_rec.attribute13,
2727           p_attribute14                  => l_est_detail_rec.attribute14,
2728           p_attribute15                  => l_est_detail_rec.attribute15,
2729           p_context                      => l_est_detail_rec.context,
2730           --p_organization_id            => l_est_detail_rec.organization_id,
2731           p_coverage_bill_rate_id        => l_est_detail_rec.coverage_bill_rate_id,
2732           p_coverage_billing_type_id     => null,
2733           p_txn_billing_type_id          => l_est_detail_rec.txn_billing_type_id,
2734           p_submit_restriction_message   => l_est_detail_rec.submit_restriction_message,
2735           p_submit_error_message         => l_est_detail_rec.submit_error_message,
2736           p_submit_from_system           => l_est_detail_rec.submit_from_system,
2737           p_line_submitted               => nvl(l_est_detail_rec.line_submitted_flag, 'N'),
2738           p_last_update_date             => sysdate,
2739           p_last_update_login            => p_login_id,
2740           p_last_updated_by              => p_user_id,
2741           p_creation_date                => sysdate,
2742           p_created_by                   => p_user_id
2743           );
2744 
2745         -- Make the postprocessing call to the user hooks
2746         --
2747         -- Post call to the customer type user hook
2748         --
2749         IF jtf_usr_hks.Ok_To_Execute('CS_CHARGE_DETAILS_PVT',
2750                                      'Update_Charge_Details',
2751                                      'A','C') THEN
2752 
2753         CS_CHARGE_DETAILS_CUHK.Update_Charge_Details_Post(
2754                 p_api_version               => l_api_version,
2755                 p_init_msg_list             => FND_API.G_FALSE,
2756                 p_commit                    => p_commit,
2757                 p_validation_level          => p_validation_level,
2758                 x_return_status             => l_return_status,
2759                 x_msg_count                 => x_msg_count,
2760                 x_object_version_number     => x_object_version_number,
2761                 x_estimate_detail_id        => l_ed_id,
2762                 x_msg_data                  => x_msg_data,
2763                 p_resp_appl_id              => p_resp_appl_id,
2764                 p_resp_id                   => p_resp_id,
2765                 p_user_id                   => p_user_id,
2766                 p_login_id                  => p_login_id,
2767                 p_transaction_control       => p_transaction_control,
2768                 p_est_detail_rec            => p_est_detail_rec);
2769 
2770         IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
2771           --DBMS_OUTPUT.PUT_LINE('Returned Error Status from the Pre Customer User Hook');
2772           FND_MESSAGE.Set_Name('CS', 'CS_API_CHG_ERR_PST_CUST_USR_HK');
2773           FND_MESSAGE.Set_Token('API_NAME', l_api_name_full);
2774           FND_MSG_PUB.Add;
2775           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2776         END IF;
2777 
2778   END IF;
2779   --
2780   --
2781   -- Post call to the Vertical Type User Hook
2782   --
2783   IF jtf_usr_hks.Ok_To_Execute('CS_CHARGE_DETAILS_PVT',
2784                                'Update_Charge_Details',
2785                                'A', 'V')  THEN
2786 
2787     CS_CHARGE_DETAILS_VUHK.Update_Charge_Details_Post(
2788                 p_api_version               => l_api_version,
2789                 p_init_msg_list             => FND_API.G_FALSE,
2790                 p_commit                    => p_commit,
2791                 p_validation_level          => p_validation_level,
2792                 x_return_status             => l_return_status,
2793                 x_msg_count                 => x_msg_count,
2794                 x_object_version_number     => x_object_version_number,
2795                 x_estimate_detail_id        => l_ed_id,
2796                 x_msg_data                  => x_msg_data,
2797                 p_resp_appl_id              => p_resp_appl_id,
2798                 p_resp_id                   => p_resp_id,
2799                 p_user_id                   => p_user_id,
2800                 p_login_id                  => p_login_id,
2801                 p_transaction_control       => p_transaction_control,
2802                 p_est_detail_rec            => p_est_detail_rec);
2803 
2804 
2805     IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
2806       FND_MESSAGE.Set_Name('CS', 'CS_API_CHG_ERR_PST_VERT_USR_HK');
2807       FND_MESSAGE.Set_Token('API_NAME', l_api_name_full);
2808       FND_MSG_PUB.Add;
2809       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2810     END IF;
2811 
2812   END IF;
2813   --
2814   --
2815 
2816   --Standard check of p_commit
2817   IF FND_API.To_Boolean(p_commit) THEN
2818     COMMIT WORK;
2819   END IF;
2820 
2821   -- Standard call to get message count and if count is 1, get message info
2822   FND_MSG_PUB.Count_And_Get
2823   (p_count => x_msg_count,
2824    p_data  => x_msg_data,
2825    p_encoded => FND_API.G_FALSE) ;
2826 
2827   -- Standard check of p_commit
2828   IF FND_API.To_Boolean(p_commit) THEN
2829     COMMIT WORK;
2830   END IF;
2831 
2832   -- Standard call to get message count and if count is 1, get message info
2833   FND_MSG_PUB.Count_And_Get
2834     ( p_count => x_msg_count,
2835       p_data  => x_msg_data
2836     );
2837 
2838 
2839   EXCEPTION
2840     WHEN FND_API.G_EXC_ERROR THEN
2841       IF FND_API.To_Boolean(p_transaction_control) THEN
2842         ROLLBACK TO Update_Charge_Details_PVT;
2843       END IF ;
2844       x_return_status := FND_API.G_RET_STS_ERROR;
2845       FND_MSG_PUB.Count_And_Get(
2846         p_count    => x_msg_count,
2847         p_data     => x_msg_data,
2848         p_encoded  => FND_API.G_FALSE) ;
2849 
2850     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2851       IF FND_API.To_Boolean(p_transaction_control) THEN
2852         ROLLBACK TO Update_Charge_Details_PVT;
2853       END IF ;
2854 
2855       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2856 
2857       FND_MSG_PUB.Count_And_Get(p_count => x_msg_count,
2858                                 p_data  => x_msg_data,
2859                                 p_encoded => FND_API.G_FALSE) ;
2860     WHEN OTHERS THEN
2861       IF FND_API.To_Boolean(p_transaction_control) THEN
2862         ROLLBACK TO Update_Charge_Details_PVT;
2863 
2864       END IF ;
2865 
2866       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2867 
2868       IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
2869         FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
2870       END IF;
2871 
2872       FND_MSG_PUB.Count_And_Get(p_count => x_msg_count,
2873                                 p_data  => x_msg_data,
2874                                 p_encoded => FND_API.G_FALSE) ;
2875 
2876 END Update_Charge_Details;
2877 
2878 --==========================================================
2879 -- API Delete Charge Details
2880 -- Purpose: Delete a given a charge detail line
2881 --          from CS_ESTIMATE_DETAILS based on the unique id
2882 --          estimate_detail_id
2883 --==========================================================
2884 
2885 Procedure  Delete_Charge_Details(
2886              p_api_version          IN         NUMBER,
2887              p_init_msg_list        IN         VARCHAR2 := FND_API.G_FALSE,
2888              p_commit               IN         VARCHAR2 := FND_API.G_FALSE,
2889              p_validation_level     IN         NUMBER   := FND_API.G_VALID_LEVEL_FULL,
2890              x_return_status        OUT NOCOPY VARCHAR2,
2891              x_msg_count            OUT NOCOPY NUMBER,
2892              x_msg_data             OUT NOCOPY VARCHAR2,
2893              p_transaction_control  IN         VARCHAR2 := FND_API.G_TRUE,
2894              p_estimate_detail_id   IN         NUMBER   := NULL)  AS
2895 
2896 l_api_name       CONSTANT  VARCHAR2(30) := 'Delete_Charge_Details' ;
2897 l_api_name_full  CONSTANT  VARCHAR2(61) := G_PKG_NAME || '.' || l_api_name ;
2898 l_log_module     CONSTANT VARCHAR2(255) := 'cs.plsql.' || l_api_name_full || '.';
2899 l_api_version    CONSTANT  NUMBER       := 1.0 ;
2900 
2901 l_resp_appl_id          NUMBER  ;
2902 l_resp_id               NUMBER  ;
2903 l_user_id               NUMBER  ;
2904 l_login_id              NUMBER  ;
2905 l_org_id                NUMBER          := NULL ;
2906 l_order_line_id         NUMBER ;
2907 l_gen_bca_flag          VARCHAR2(1);
2908 l_charge_line_type      VARCHAR2(30);
2909 l_return_status         VARCHAR2(1) ;
2910 
2911 l_estimate_detail_id    NUMBER := p_estimate_detail_id ;
2912 l_charge_det_rec        CS_Charge_Details_PUB.Charges_Rec_Type;
2913 
2914 
2915 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||'delete_charge_details';
2916 
2917 
2918 BEGIN
2919 
2920   --Standard Start of API Savepoint
2921   IF FND_API.To_Boolean( p_transaction_control ) THEN
2922     SAVEPOINT   Delete_Charge_Details_PUB ;
2923   END IF ;
2924 
2925   --Standard Call to check API compatibility
2926   IF NOT FND_API.Compatible_API_Call(l_api_version,
2927      p_api_version,
2928      l_api_name,
2929      G_PKG_NAME) THEN
2930     RAISE FND_API.G_EXC_UNEXPECTED_ERROR ;
2931   END IF ;
2932 
2933   --Initialize the message list  if p_msg_list is set to TRUE
2934   IF FND_API.To_Boolean(p_init_msg_list)   THEN
2935     FND_MSG_PUB.initialize ;
2936   END IF ;
2937 
2938   --Initialize the API Return Success to True
2939   x_return_status := FND_API.G_RET_STS_SUCCESS ;
2940 
2941 ----------------------- FND Logging -----------------------------------
2942   IF FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level
2943   THEN
2944     FND_LOG.String
2945     ( FND_LOG.level_procedure , L_LOG_MODULE || 'start'
2946     , 'Inside ' || L_API_NAME_FULL || ', called with parameters below:'
2947     );
2948     FND_LOG.String
2949     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
2950     , 'p_api_version:' || p_api_version
2951     );
2952     FND_LOG.String
2953     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
2954     , 'p_init_msg_list:' || p_init_msg_list
2955     );
2956     FND_LOG.String
2957     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
2958     , 'p_commit:' || p_commit
2959     );
2960     FND_LOG.String
2961     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
2962     , 'p_validation_level:' || p_validation_level
2963     );
2964     FND_LOG.String
2965     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
2966     , 'p_transaction_control:' || p_transaction_control
2967     );
2968     FND_LOG.String
2969     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
2970     , 'p_estimate_detail_id:' || p_estimate_detail_id
2971     );
2972 
2973   END IF;
2974 
2975   --Check for mandatory params estimate detail id
2976   --If  not passed or are null then raise error
2977 
2978   IF (p_estimate_detail_id IS NULL) THEN
2979     Add_Null_Parameter_Msg(l_api_name_full,
2980                            'p_estimate_detail_id') ;
2981 
2982     Add_Invalid_Argument_Msg(l_api_name_full,
2983                              to_char(p_estimate_detail_id),
2984                              'p_estimate_detail_id');
2985     RAISE FND_API.G_EXC_ERROR ;
2986   END IF ;
2987 
2988   -- Check to see if Transactions exits in Order Management
2989 
2990   Do_Txns_Exist(l_api_name_full,
2991                 p_estimate_detail_id,
2992                 l_order_line_id,
2993                 l_gen_bca_flag,
2994                 l_charge_line_type,
2995                 l_return_status) ;
2996 
2997   IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
2998     RAISE FND_API.G_EXC_ERROR ;
2999   END IF ;
3000 
3001   IF l_order_line_id IS NOT NULL THEN
3002     Cannot_Delete_Line_Msg(l_api_name_full) ;
3003     RAISE FND_API.G_EXC_ERROR ;
3004   END IF ;
3005 
3006   --Bug Fix for Bug # 3136630
3007 
3008   --IF l_gen_bca_flag IS NOT NULL THEN
3009   --  IF l_gen_bca_flag = 'Y' AND
3010   IF l_charge_line_type = 'IN PROGRESS' THEN
3011     Cannot_Delete_Line_Msg(l_api_name_full) ;
3012     RAISE FND_API.G_EXC_ERROR ;
3013   END IF ;
3014  -- END IF;
3015 
3016   DELETE FROM
3017   CS_ESTIMATE_DETAILS
3018   WHERE ESTIMATE_DETAIL_ID = p_estimate_detail_id ;
3019 
3020   --End of API Body
3021   --Standard Check of p_commit
3022   IF FND_API.To_Boolean( p_commit ) THEN
3023     COMMIT WORK ;
3024   END IF ;
3025 
3026   --Standard call to get  message count and if count is 1 , get message info
3027   FND_MSG_PUB.Count_And_Get(p_count =>x_msg_count,
3028                             p_data => x_msg_data) ;
3029 
3030   --Begin Exception Handling
3031 
3032 EXCEPTION
3033 
3034   WHEN FND_API.G_EXC_ERROR THEN
3035     IF FND_API.To_Boolean( p_transaction_control ) THEN
3036       ROLLBACK TO Delete_Charge_Details_PUB;
3037     END IF ;
3038   x_return_status :=  FND_API.G_RET_STS_ERROR ;
3039 
3040   FND_MSG_PUB.Count_And_Get(p_count => x_msg_count,
3041                             p_data  => x_msg_data,
3042                             p_encoded => FND_API.G_FALSE) ;
3043 
3044 
3045 
3046   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3047     IF FND_API.To_Boolean( p_transaction_control ) THEN
3048       ROLLBACK TO Delete_Charge_Details_PUB;
3049     END IF ;
3050   x_return_status :=  FND_API.G_RET_STS_UNEXP_ERROR ;
3051 
3052   FND_MSG_PUB.Count_And_Get(p_count => x_msg_count,
3053                             p_data  => x_msg_data,
3054                             p_encoded => FND_API.G_FALSE) ;
3055 
3056   WHEN OTHERS THEN
3057     IF FND_API.To_Boolean( p_transaction_control ) THEN
3058       ROLLBACK TO Delete_Charge_Details_PUB;
3059     END IF ;
3060   x_return_status :=  FND_API.G_RET_STS_UNEXP_ERROR ;
3061   IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
3062      FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME,l_api_name);
3063   END IF ;
3064   FND_MSG_PUB.Count_And_Get(p_count => x_msg_count,
3065                             p_data  => x_msg_data,
3066                             p_encoded => FND_API.G_FALSE) ;
3067 
3068 END  Delete_Charge_Details;   -- End of Procedure Delete Charge Details
3069 
3070 
3071 
3072 --==================================
3073 --Copy Estimates
3074 --==================================
3075 -- New API added for 11.5.10
3076 -- mviswana
3077 Procedure  Copy_Estimate(
3078         p_api_version         IN         NUMBER,
3079         p_init_msg_list       IN         VARCHAR2 := FND_API.G_FALSE,
3080         p_commit              IN         VARCHAR2 := FND_API.G_FALSE,
3081         p_transaction_control IN         VARCHAR2 := FND_API.G_TRUE,
3082         p_estimate_detail_id  IN         NUMBER   := NULL,
3083         x_estimate_detail_id  OUT NOCOPY NUMBER,
3084         x_return_status       OUT NOCOPY VARCHAR2,
3085         x_msg_count           OUT NOCOPY NUMBER,
3086         x_msg_data            OUT NOCOPY VARCHAR2 ) IS
3087 
3088 l_api_version       NUMBER               :=  1.0 ;
3089 l_api_name          VARCHAR2(30)         := 'Copy_Estimate' ;
3090 l_api_name_full     VARCHAR2(61)         :=  G_PKG_NAME || '.' || l_api_name ;
3091 l_log_module     CONSTANT VARCHAR2(255)  := 'cs.plsql.' || l_api_name_full || '.';
3092 l_return_status     VARCHAR2(1) ;
3093 l_est_detail_id     NUMBER;
3094 l_line_number       NUMBER;
3095 l_obj_ver_num       NUMBER;
3096 l_est_detail_rec    CS_Charge_Details_PUB.Charges_Rec_Type;
3097 
3098 cursor c_charges_rec(p_estimate_detail_id NUMBER) IS
3099 select *
3100 from cs_estimate_details
3101 where estimate_detail_id = p_estimate_detail_id;
3102 
3103 v_charges_rec c_charges_rec%ROWTYPE;
3104 x_cost_id number;
3105 
3106 l_prog_name CONSTANT VARCHAR2(61) := G_PKG_NAME||'.'||l_api_name;
3107 
3108 BEGIN
3109 
3110   --DBMS_OUTPUT.PUT_LINE('BEGIN copy_estimates');
3111 
3112   -- Standard start of API savepoint
3113   IF FND_API.To_Boolean(p_transaction_control) THEN
3114     SAVEPOINT Copy_Estimate_PVT;
3115   END IF ;
3116 
3117   -- Standard call to check for call compatibility
3118   IF NOT FND_API.Compatible_API_Call(l_api_version,
3119                                      p_api_version,
3120                                      l_api_name,
3121                                      G_PKG_NAME) THEN
3122     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3123   END IF;
3124 
3125   -- Initialize message list if p_init_msg_list is set to TRUE
3126   IF FND_API.To_Boolean(p_init_msg_list) THEN
3127     FND_MSG_PUB.Initialize;
3128   END IF;
3129 
3130   -- Initialize API return status to success
3131   x_return_status := FND_API.G_RET_STS_SUCCESS;
3132 
3133 ----------------------- FND Logging -----------------------------------
3134   IF FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level
3135   THEN
3136     FND_LOG.String
3137     ( FND_LOG.level_procedure , L_LOG_MODULE || 'start'
3138     , 'Inside ' || L_API_NAME_FULL || ', called with parameters below:'
3139     );
3140     FND_LOG.String
3141     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
3142     , 'p_api_version:' || p_api_version
3143     );
3144     FND_LOG.String
3145     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
3146     , 'p_init_msg_list:' || p_init_msg_list
3147     );
3148     FND_LOG.String
3149     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
3150     , 'p_commit:' || p_commit
3151     );
3152     FND_LOG.String
3153     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
3154     , 'p_transaction_control:' || p_transaction_control
3155     );
3156     FND_LOG.String
3157     ( FND_LOG.level_procedure , L_LOG_MODULE || ''
3158     , 'p_estimate_detail_id:' || p_estimate_detail_id
3159     );
3160 
3161   END IF;
3162 
3163   -- ======================================================================
3164   -- Actual start of the program body.
3165   -- ======================================================================
3166 
3167   -- =========================================
3168   -- Validate the incoming estimate_detail_id
3169   -- =========================================
3170 
3171   IF p_estimate_detail_id IS NULL THEN
3172     FND_MESSAGE.SET_NAME('CS', 'CS_CHG_NOT_A_VALID_CHARGE_LINE');
3173     FND_MESSAGE.SET_TOKEN('ESTIMATE_DETAIL_ID', p_estimate_detail_id);
3174     FND_MSG_PUB.ADD;
3175     RAISE FND_API.G_EXC_ERROR;
3176   END IF;
3177 
3178   --DBMS_OUTPUT.PUT_LINE('passed 1st val');
3179 
3180   OPEN c_charges_rec(p_estimate_detail_id);
3181   FETCH c_charges_rec INTO v_charges_rec;
3182   IF c_charges_rec%NOTFOUND THEN
3183     CLOSE c_charges_rec;
3184     FND_MESSAGE.SET_NAME('CS', 'CS_CHG_NOT_A_VALID_CHARGE_LINE');
3185     FND_MESSAGE.SET_TOKEN('ESTIMATE_DETAIL_ID', p_estimate_detail_id);
3186     FND_MSG_PUB.ADD;
3187     RAISE FND_API.G_EXC_ERROR;
3188   END IF;
3189   CLOSE c_charges_rec;
3190 
3191   --DBMS_OUTPUT.PUT_LINE('passed 2ndst val');
3192 
3193   IF v_charges_rec.charge_line_type <> 'ESTIMATE' THEN
3194     FND_MESSAGE.SET_NAME('CS', 'CS_CHG_NOT_AN_ESTIMATE');
3195     FND_MESSAGE.SET_TOKEN('ESTIMATE_DETAIL_ID', p_estimate_detail_id);
3196     FND_MSG_PUB.ADD;
3197     RAISE FND_API.G_EXC_ERROR;
3198   END IF;
3199 
3200   --DBMS_OUTPUT.PUT_LINE('passed 3rd val');
3201 
3202   --populate the charges rec with values from v_charges_rec
3203 
3204   l_est_detail_rec.incident_id                  :=   v_charges_rec.incident_id;
3205   l_est_detail_rec.charge_line_type             :=   'ACTUAL';
3206   -- fix for bug:5125385
3207   -- l_est_detail_rec.line_number               :=   1;
3208   l_est_detail_rec.line_number                  :=   NULL;
3209   l_est_detail_rec.business_process_id          :=   v_charges_rec.business_process_id;
3210   l_est_detail_rec.transaction_type_id          :=   v_charges_rec.transaction_type_id;
3211   l_est_detail_rec.inventory_item_id_in         :=   v_charges_rec.inventory_item_id;
3212   l_est_detail_rec.item_revision                :=   v_charges_rec.item_revision;
3213   l_est_detail_rec.billing_flag                 :=   NULL;
3214   l_est_detail_rec.txn_billing_type_id          :=   v_charges_rec.txn_billing_type_id;
3215   l_est_detail_rec.unit_of_measure_code         :=   v_charges_rec.unit_of_measure_code;
3216   l_est_detail_rec.quantity_required            :=   v_charges_rec.quantity_required;
3217   l_est_detail_rec.return_reason_code           :=   v_charges_rec.return_reason_code;
3218   l_est_detail_rec.customer_product_id          :=   v_charges_rec.customer_product_id;
3219   l_est_detail_rec.serial_number                :=   v_charges_rec.serial_number;
3220   l_est_detail_rec.installed_cp_return_by_date  :=   v_charges_rec.installed_cp_return_by_date;
3221   l_est_detail_rec.new_cp_return_by_date        :=   v_charges_rec.new_cp_return_by_date;
3222   l_est_detail_rec.bill_to_party_id             :=   v_charges_rec.bill_to_party_id;
3223   l_est_detail_rec.bill_to_account_id           :=   v_charges_rec.INVOICE_TO_ACCOUNT_ID;
3224   l_est_detail_rec.bill_to_contact_id           :=   v_charges_rec.bill_to_contact_id;
3225   l_est_detail_rec.invoice_to_org_id            :=   v_charges_rec.invoice_to_org_id;
3226   l_est_detail_rec.ship_to_party_id             :=   v_charges_rec.ship_to_party_id;
3227   l_est_detail_rec.ship_to_account_id           :=   v_charges_rec.ship_to_account_id;
3228   l_est_detail_rec.ship_to_contact_id           :=   v_charges_rec.ship_to_contact_id;
3229   l_est_detail_rec.ship_to_org_id               :=   v_charges_rec.ship_to_org_id;
3230   l_est_detail_rec.contract_id                  :=   v_charges_rec.contract_id;
3231   l_est_detail_rec.contract_line_id             :=   v_charges_rec.contract_line_id;
3232   l_est_detail_rec.coverage_id                  :=   v_charges_rec.coverage_id;
3233   l_est_detail_rec.coverage_txn_group_id        :=   v_charges_rec.coverage_txn_group_id;
3234   l_est_detail_rec.coverage_bill_rate_id        :=   v_charges_rec.coverage_bill_rate_id;
3235   l_est_detail_rec.coverage_billing_type_id     :=   v_charges_rec.coverage_billing_type_id;
3236   l_est_detail_rec.price_list_id                :=   v_charges_rec.PRICE_LIST_HEADER_ID;
3237   l_est_detail_rec.currency_code                :=   v_charges_rec.currency_code;
3238   l_est_detail_rec.purchase_order_num           :=   v_charges_rec.purchase_order_num;
3239   l_est_detail_rec.list_price                   :=   v_charges_rec.list_price;
3240 
3241 
3242 
3243   --how do we know this we do not trap this value
3244   l_est_detail_rec.con_pct_over_list_price      :=   null;
3245   l_est_detail_rec.selling_price                :=   v_charges_rec.selling_price;
3246   l_est_detail_rec.contract_discount_amount     :=   v_charges_rec.contract_discount_amount;
3247 
3248   --how do we know when to apply contract discount if we do not trap this value
3249   l_est_detail_rec.apply_contract_discount      :=   'N' ;
3250 
3251 
3252   l_est_detail_rec.after_warranty_cost          :=   v_charges_rec.after_warranty_cost;
3253   l_est_detail_rec.transaction_inventory_org    :=   v_charges_rec.transaction_inventory_org;
3254   l_est_detail_rec.transaction_sub_inventory    :=   v_charges_rec.transaction_sub_inventory;
3255   l_est_detail_rec.rollup_flag                  :=   v_charges_rec.rollup_flag;
3256   l_est_detail_rec.add_to_order_flag            :=   v_charges_rec.add_to_order_flag;
3257   l_est_detail_rec.order_header_id              :=   v_charges_rec.order_header_id;
3258   l_est_detail_rec.interface_to_oe_flag         :=   v_charges_rec.interface_to_oe_flag;
3259   l_est_detail_rec.no_charge_flag               :=   v_charges_rec.no_charge_flag;
3260   l_est_detail_rec.line_category_code           :=   v_charges_rec.line_category_code;
3261   l_est_detail_rec.line_type_id                 :=   v_charges_rec.line_type_id;
3262   l_est_detail_rec.order_line_id                :=   v_charges_rec.order_line_id;
3263   l_est_detail_rec.conversion_rate              :=   v_charges_rec.conversion_rate;
3264   l_est_detail_rec.conversion_type_code         :=   v_charges_rec.conversion_type_code;
3265   l_est_detail_rec.conversion_rate_date         :=   v_charges_rec.conversion_rate_date;
3266   l_est_detail_rec.original_source_id           :=   v_charges_rec.original_source_id;
3267   l_est_detail_rec.original_source_code         :=   v_charges_rec.original_source_code;
3268   l_est_detail_rec.source_id                    :=   v_charges_rec.source_id;
3269   l_est_detail_rec.source_code                  :=   v_charges_rec.source_code;
3270   l_est_detail_rec.org_id                       :=   v_charges_rec.org_id;
3271 
3272 
3273 
3274   --Error Handling
3275   l_est_detail_rec.submit_restriction_message   :=   v_charges_rec.submit_restriction_message;
3276   l_est_detail_rec.submit_error_message         :=   v_charges_rec.submit_error_message;
3277 
3278   --DBMS_OUTPUT.PUT_LINE('submit_restriction_message is '||l_est_detail_rec.submit_restriction_message);
3279   --DBMS_OUTPUT.PUT_LINE('submit_error_message is '||l_est_detail_rec.submit_error_message);
3280 
3281 
3282   --Auto Submission Process
3283   l_est_detail_rec.submit_from_system           :=   v_charges_rec.submit_from_system;
3284 
3285   --Billing Engine
3286   --Fixed Bug # 3362046
3287   l_est_detail_rec.activity_start_time          :=   v_charges_rec.activity_start_date_time;
3288   l_est_detail_rec.activity_end_time            :=   v_charges_rec.activity_end_date_time;
3289   l_est_detail_rec.generated_by_bca_engine      :=   v_charges_rec.generated_by_bca_engine_flag;
3290 
3291   l_est_detail_rec.attribute1                   :=   v_charges_rec.attribute1;
3292   l_est_detail_rec.attribute2                   :=   v_charges_rec.attribute2;
3293   l_est_detail_rec.attribute3                   :=   v_charges_rec.attribute3;
3294   l_est_detail_rec.attribute4                   :=   v_charges_rec.attribute4;
3295   l_est_detail_rec.attribute5                   :=   v_charges_rec.attribute5;
3296   l_est_detail_rec.attribute6                   :=   v_charges_rec.attribute6;
3297   l_est_detail_rec.attribute7                   :=   v_charges_rec.attribute7;
3298   l_est_detail_rec.attribute8                   :=   v_charges_rec.attribute8;
3299   l_est_detail_rec.attribute9                   :=   v_charges_rec.attribute9;
3300   l_est_detail_rec.attribute10                  :=   v_charges_rec.attribute10;
3301   l_est_detail_rec.attribute11                  :=   v_charges_rec.attribute11;
3302   l_est_detail_rec.attribute12                  :=   v_charges_rec.attribute12;
3303   l_est_detail_rec.attribute13                  :=   v_charges_rec.attribute13;
3304   l_est_detail_rec.attribute14                  :=   v_charges_rec.attribute14;
3305   l_est_detail_rec.attribute15                  :=   v_charges_rec.attribute15;
3306   l_est_detail_rec.context                      :=   v_charges_rec.context;
3307   l_est_detail_rec.pricing_context              :=   v_charges_rec.pricing_context;
3308   l_est_detail_rec.pricing_attribute1           :=   v_charges_rec.pricing_attribute1;
3309   l_est_detail_rec.pricing_attribute2           :=   v_charges_rec.pricing_attribute2 ;
3310   l_est_detail_rec.pricing_attribute3           :=   v_charges_rec.pricing_attribute3 ;
3311   l_est_detail_rec.pricing_attribute4           :=   v_charges_rec.pricing_attribute4 ;
3312   l_est_detail_rec.pricing_attribute5           :=   v_charges_rec.pricing_attribute5 ;
3313   l_est_detail_rec.pricing_attribute6           :=   v_charges_rec.pricing_attribute6 ;
3314   l_est_detail_rec.pricing_attribute7           :=   v_charges_rec.pricing_attribute7 ;
3315   l_est_detail_rec.pricing_attribute8           :=   v_charges_rec.pricing_attribute8 ;
3316   l_est_detail_rec.pricing_attribute9           :=   v_charges_rec.pricing_attribute9 ;
3317   l_est_detail_rec.pricing_attribute10          :=   v_charges_rec.pricing_attribute10;
3318   l_est_detail_rec.pricing_attribute11          :=   v_charges_rec.pricing_attribute11;
3319   l_est_detail_rec.pricing_attribute12          :=   v_charges_rec.pricing_attribute12;
3320   l_est_detail_rec.pricing_attribute13          :=   v_charges_rec.pricing_attribute13;
3321   l_est_detail_rec.pricing_attribute14          :=   v_charges_rec.pricing_attribute14;
3322   l_est_detail_rec.pricing_attribute15          :=   v_charges_rec.pricing_attribute15;
3323   l_est_detail_rec.pricing_attribute16          :=   v_charges_rec.pricing_attribute16;
3324   l_est_detail_rec.pricing_attribute17          :=   v_charges_rec.pricing_attribute17;
3325   l_est_detail_rec.pricing_attribute18          :=   v_charges_rec.pricing_attribute18;
3326   l_est_detail_rec.pricing_attribute19          :=   v_charges_rec.pricing_attribute19;
3327   l_est_detail_rec.pricing_attribute20          :=   v_charges_rec.pricing_attribute20;
3328   l_est_detail_rec.pricing_attribute21          :=   v_charges_rec.pricing_attribute21;
3329   l_est_detail_rec.pricing_attribute22          :=   v_charges_rec.pricing_attribute22;
3330   l_est_detail_rec.pricing_attribute23          :=   v_charges_rec.pricing_attribute23;
3331   l_est_detail_rec.pricing_attribute24          :=   v_charges_rec.pricing_attribute24;
3332   l_est_detail_rec.pricing_attribute25          :=   v_charges_rec.pricing_attribute25;
3333   l_est_detail_rec.pricing_attribute26          :=   v_charges_rec.pricing_attribute26;
3334   l_est_detail_rec.pricing_attribute27          :=   v_charges_rec.pricing_attribute27;
3335   l_est_detail_rec.pricing_attribute28          :=   v_charges_rec.pricing_attribute28;
3336   l_est_detail_rec.pricing_attribute29          :=   v_charges_rec.pricing_attribute29;
3337   l_est_detail_rec.pricing_attribute30          :=   v_charges_rec.pricing_attribute30;
3338   l_est_detail_rec.pricing_attribute31          :=   v_charges_rec.pricing_attribute31;
3339   l_est_detail_rec.pricing_attribute32          :=   v_charges_rec.pricing_attribute32;
3340   l_est_detail_rec.pricing_attribute33          :=   v_charges_rec.pricing_attribute33;
3341   l_est_detail_rec.pricing_attribute34          :=   v_charges_rec.pricing_attribute34;
3342   l_est_detail_rec.pricing_attribute35          :=   v_charges_rec.pricing_attribute35;
3343   l_est_detail_rec.pricing_attribute36          :=   v_charges_rec.pricing_attribute36;
3344   l_est_detail_rec.pricing_attribute37          :=   v_charges_rec.pricing_attribute37;
3345   l_est_detail_rec.pricing_attribute38          :=   v_charges_rec.pricing_attribute38;
3346   l_est_detail_rec.pricing_attribute39          :=   v_charges_rec.pricing_attribute39;
3347   l_est_detail_rec.pricing_attribute40          :=   v_charges_rec.pricing_attribute40;
3348   l_est_detail_rec.pricing_attribute41          :=   v_charges_rec.pricing_attribute41;
3349   l_est_detail_rec.pricing_attribute42          :=   v_charges_rec.pricing_attribute42;
3350   l_est_detail_rec.pricing_attribute43          :=   v_charges_rec.pricing_attribute43;
3351   l_est_detail_rec.pricing_attribute44          :=   v_charges_rec.pricing_attribute44;
3352   l_est_detail_rec.pricing_attribute45          :=   v_charges_rec.pricing_attribute45;
3353   l_est_detail_rec.pricing_attribute46          :=   v_charges_rec.pricing_attribute46;
3354   l_est_detail_rec.pricing_attribute47          :=   v_charges_rec.pricing_attribute47;
3355   l_est_detail_rec.pricing_attribute48          :=   v_charges_rec.pricing_attribute48;
3356   l_est_detail_rec.pricing_attribute49          :=   v_charges_rec.pricing_attribute49;
3357   l_est_detail_rec.pricing_attribute50          :=   v_charges_rec.pricing_attribute50;
3358   l_est_detail_rec.pricing_attribute51          :=   v_charges_rec.pricing_attribute51;
3359   l_est_detail_rec.pricing_attribute52          :=   v_charges_rec.pricing_attribute52;
3360   l_est_detail_rec.pricing_attribute53          :=   v_charges_rec.pricing_attribute53;
3361   l_est_detail_rec.pricing_attribute54          :=   v_charges_rec.pricing_attribute54;
3362   l_est_detail_rec.pricing_attribute55          :=   v_charges_rec.pricing_attribute56;
3363   l_est_detail_rec.pricing_attribute56          :=   v_charges_rec.pricing_attribute56;
3364   l_est_detail_rec.pricing_attribute57          :=   v_charges_rec.pricing_attribute57;
3365   l_est_detail_rec.pricing_attribute58          :=   v_charges_rec.pricing_attribute58;
3366   l_est_detail_rec.pricing_attribute59          :=   v_charges_rec.pricing_attribute59;
3367   l_est_detail_rec.pricing_attribute60          :=   v_charges_rec.pricing_attribute60;
3368   l_est_detail_rec.pricing_attribute61          :=   v_charges_rec.pricing_attribute61;
3369   l_est_detail_rec.pricing_attribute62          :=   v_charges_rec.pricing_attribute62;
3370   l_est_detail_rec.pricing_attribute63          :=   v_charges_rec.pricing_attribute63;
3371   l_est_detail_rec.pricing_attribute64          :=   v_charges_rec.pricing_attribute64;
3372   l_est_detail_rec.pricing_attribute65          :=   v_charges_rec.pricing_attribute65;
3373   l_est_detail_rec.pricing_attribute66          :=   v_charges_rec.pricing_attribute66;
3374   l_est_detail_rec.pricing_attribute67          :=   v_charges_rec.pricing_attribute67;
3375   l_est_detail_rec.pricing_attribute68          :=   v_charges_rec.pricing_attribute68;
3376   l_est_detail_rec.pricing_attribute69          :=   v_charges_rec.pricing_attribute69;
3377   l_est_detail_rec.pricing_attribute70          :=   v_charges_rec.pricing_attribute70;
3378   l_est_detail_rec.pricing_attribute71          :=   v_charges_rec.pricing_attribute71;
3379   l_est_detail_rec.pricing_attribute72          :=   v_charges_rec.pricing_attribute72;
3380   l_est_detail_rec.pricing_attribute73          :=   v_charges_rec.pricing_attribute73;
3381   l_est_detail_rec.pricing_attribute74          :=   v_charges_rec.pricing_attribute74;
3382   l_est_detail_rec.pricing_attribute75          :=   v_charges_rec.pricing_attribute75;
3383   l_est_detail_rec.pricing_attribute76          :=   v_charges_rec.pricing_attribute76;
3384   l_est_detail_rec.pricing_attribute77          :=   v_charges_rec.pricing_attribute77;
3385   l_est_detail_rec.pricing_attribute78          :=   v_charges_rec.pricing_attribute78;
3386   l_est_detail_rec.pricing_attribute79          :=   v_charges_rec.pricing_attribute79;
3387   l_est_detail_rec.pricing_attribute80          :=   v_charges_rec.pricing_attribute80;
3388   l_est_detail_rec.pricing_attribute81          :=   v_charges_rec.pricing_attribute81;
3389   l_est_detail_rec.pricing_attribute82          :=   v_charges_rec.pricing_attribute82;
3390   l_est_detail_rec.pricing_attribute83          :=   v_charges_rec.pricing_attribute83;
3391   l_est_detail_rec.pricing_attribute84          :=   v_charges_rec.pricing_attribute84;
3392   l_est_detail_rec.pricing_attribute85          :=   v_charges_rec.pricing_attribute85;
3393   l_est_detail_rec.pricing_attribute86          :=   v_charges_rec.pricing_attribute86;
3394   l_est_detail_rec.pricing_attribute87          :=   v_charges_rec.pricing_attribute87;
3395   l_est_detail_rec.pricing_attribute88          :=   v_charges_rec.pricing_attribute88;
3396   l_est_detail_rec.pricing_attribute89          :=   v_charges_rec.pricing_attribute89;
3397   l_est_detail_rec.pricing_attribute90          :=   v_charges_rec.pricing_attribute90;
3398   l_est_detail_rec.pricing_attribute91          :=   v_charges_rec.pricing_attribute91;
3399   l_est_detail_rec.pricing_attribute92          :=   v_charges_rec.pricing_attribute92;
3400   l_est_detail_rec.pricing_attribute93          :=   v_charges_rec.pricing_attribute93;
3401   l_est_detail_rec.pricing_attribute94          :=   v_charges_rec.pricing_attribute94;
3402   l_est_detail_rec.pricing_attribute95          :=   v_charges_rec.pricing_attribute95;
3403   l_est_detail_rec.pricing_attribute96          :=   v_charges_rec.pricing_attribute96;
3404   l_est_detail_rec.pricing_attribute97          :=   v_charges_rec.pricing_attribute97;
3405   l_est_detail_rec.pricing_attribute98          :=   v_charges_rec.pricing_attribute98;
3406   l_est_detail_rec.pricing_attribute99          :=   v_charges_rec.pricing_attribute99;
3407   l_est_detail_rec.pricing_attribute100         :=   v_charges_rec.pricing_attribute100;
3408 
3409 
3410   -- Call Create Charge Details to create line
3411 
3412   --DBMS_OUTPUT.PUT_LINE('Calling CS_Charge_Details_PUB.Create_Charge_Details');
3413 
3414 
3415   CS_Charge_Details_PUB.Create_Charge_Details(
3416     p_api_version    => l_api_version,
3417     p_commit         => fnd_api.g_false,
3418     p_init_msg_list  => fnd_api.g_false,
3419     x_msg_count      => x_msg_count,
3420     x_msg_data       => x_msg_data,
3421     x_return_status  => l_return_status,
3422     p_Charges_Rec    => l_est_detail_rec,
3423     p_create_cost_detail => 'Y' ,       --Added for  Service Costing
3424     x_cost_id             => x_cost_id, --Added for Service Costing
3425     x_estimate_detail_id  =>  x_estimate_detail_id,
3426     x_line_number        =>  l_line_number,
3427     x_object_version_number => l_obj_ver_num
3428     ) ;
3429 
3430 
3431 
3432 
3433  --DBMS_OUTPUT.PUT_LINE('Estimate detail Id is'||l_est_detail_id);
3434 
3435   IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
3436     RAISE FND_API.G_EXC_ERROR;
3437   ELSIF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
3438     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3439   END IF;
3440 
3441   --End of API Body
3442   --Standard Check of p_commit
3443   IF FND_API.To_Boolean( p_commit ) THEN
3444     COMMIT WORK ;
3445   END IF ;
3446 
3447   --Standard call to get  message count and if count is 1 , get message info
3448   FND_MSG_PUB.Count_And_Get(p_count =>x_msg_count,
3449                             p_data => x_msg_data) ;
3450 
3451 
3452 
3453   --Begin Exception Handling
3454 
3455   EXCEPTION
3456 
3457   WHEN FND_API.G_EXC_ERROR THEN
3458     IF FND_API.To_Boolean( p_transaction_control ) THEN
3459       ROLLBACK TO Copy_Estimates_PVT;
3460     END IF ;
3461 
3462   x_return_status :=  FND_API.G_RET_STS_ERROR ;
3463 
3464   FND_MSG_PUB.Count_And_Get(p_count   => x_msg_count,
3465                             p_data    => x_msg_data,
3466                             p_encoded => FND_API.G_FALSE) ;
3467 
3468 
3469   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3470     IF FND_API.To_Boolean( p_transaction_control ) THEN
3471       ROLLBACK TO Copy_Estimates_PVT;
3472     END IF ;
3473 
3474   x_return_status :=  FND_API.G_RET_STS_UNEXP_ERROR ;
3475 
3476   FND_MSG_PUB.Count_And_Get(p_count => x_msg_count,
3477                             p_data  => x_msg_data,
3478                             p_encoded => FND_API.G_FALSE) ;
3479   WHEN OTHERS THEN
3480     IF FND_API.To_Boolean( p_transaction_control ) THEN
3481       ROLLBACK TO Copy_Estimates_PVT;
3482     END IF ;
3483 
3484   x_return_status :=  FND_API.G_RET_STS_UNEXP_ERROR ;
3485 
3486   IF FND_MSG_PUB.Check_Msg_Level
3487     (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
3488     FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME,l_api_name);
3489   END IF ;
3490 
3491   FND_MSG_PUB.Count_And_Get(p_count => x_msg_count,
3492                             p_data  => x_msg_data,
3493                             p_encoded => FND_API.G_FALSE) ;
3494 
3495 END Copy_Estimate;
3496 
3497 
3498 --==================================
3499 -- Validate_Chrg_Dtls
3500 --==================================
3501 PROCEDURE VALIDATE_CHARGE_DETAILS(
3502                  P_API_NAME                  IN            VARCHAR2,
3503                  P_CHARGES_DETAIL_REC        IN            CS_Charge_Details_PUB.Charges_Rec_Type,
3504                  P_VALIDATION_MODE           IN            VARCHAR2,
3505                  P_USER_ID                   IN            NUMBER,
3506                  P_LOGIN_ID                  IN            NUMBER,
3507                  X_CHARGES_DETAIL_REC        OUT NOCOPY    CS_Charge_Details_PUB.Charges_Rec_Type,
3508                  X_MSG_DATA                  OUT NOCOPY    VARCHAR2,
3509                  X_MSG_COUNT                 OUT NOCOPY    NUMBER,
3510                  X_RETURN_STATUS             OUT NOCOPY    VARCHAR2)
3511 IS
3512 
3513 l_api_name                  CONSTANT   VARCHAR2(30) := 'Validate_Charge_Details' ;
3514 l_api_name_full             CONSTANT   VARCHAR2(61) :=  G_PKG_NAME || '.' || l_api_name ;
3515 l_log_module                CONSTANT VARCHAR2(255)  := 'cs.plsql.' || l_api_name_full || '.';
3516 l_business_process_id                  NUMBER;
3517 l_line_order_category_code             VARCHAR2(30);
3518 l_no_charge_flag                       VARCHAR2(1);
3519 l_create_charge_flag		       VARCHAR2(1); --costing enhancement
3520 l_interface_to_oe_flag                 VARCHAR2(1);
3521 l_update_ib_flag                       VARCHAR2(1);
3522 l_src_reference_reqd_flag              VARCHAR2(1);
3523 l_src_return_reqd_flag                 VARCHAR2(1);
3524 l_non_src_reference_reqd_flag          VARCHAR2(1);
3525 l_non_src_return_reqd                  VARCHAR2(1);
3526 l_non_src_return_reqd_flag             VARCHAR2(1);
3527 l_serial_control_flag                  VARCHAR2(1);
3528 l_rev_control_flag                     VARCHAR2(1);
3529 l_billing_flag                         VARCHAR2(30);
3530 l_tbl_uom                              TBL_UOM;
3531 l_primary_uom                          VARCHAR2(3);
3532 l_txn_billing_type_id                  NUMBER;
3533 l_line_type_id                         NUMBER;
3534 l_order_header_id                      NUMBER;
3535 l_def_bp_from_sr                       VARCHAR2(1) := 'N';
3536 l_org_id                               NUMBER;
3537 
3538 l_msg_data                             VARCHAR2(2000);
3539 l_msg_count                            NUMBER;
3540 l_profile                              VARCHAR2(200);
3541 l_source_id                            NUMBER;
3542 l_return_status                        VARCHAR2(1);
3543 l_customer_id                          NUMBER;
3544 l_customer_site_id                     NUMBER;
3545 --Changed this to fix bug # 3667210
3546 --Changed to VARCHAR2(50) as per table specification
3547 l_cust_po_number                       VARCHAR2(50);
3548 l_cust_product_id                      NUMBER;
3549 l_system_id                            NUMBER;
3550 l_inventory_item_id                    NUMBER;
3551 l_account_id                           NUMBER;
3552 l_bill_to_party_id                     NUMBER;
3553 l_bill_to_account_id                   NUMBER;
3554 l_bill_to_contact_id                   NUMBER;
3555 l_bill_to_site_id                      NUMBER;
3556 l_ship_to_party_id                     NUMBER;
3557 l_ship_to_account_id                   NUMBER;
3558 l_ship_to_contact_id                   NUMBER;
3559 l_ship_to_site_id                      NUMBER;
3560 l_contract_id                          NUMBER;
3561 l_contract_service_id                  NUMBER;
3562 l_po_number                            VARCHAR2(50);
3563 l_price_list_exists                    VARCHAR2(1);
3564 l_price_list_id                        NUMBER;
3565 -- Changed length of the currency code to 15 for bug # 4120556
3566 l_currency_code                        VARCHAR2(15);
3567 l_conversion_needed_flag               VARCHAR2(1);
3568 l_convert_currency                     VARCHAR2(10);
3569 l_rate NUMBER;
3570 l_numerator                            NUMBER;
3571 l_denominator                          NUMBER;
3572 l_list_price                           NUMBER;
3573 l_contract_discount                    NUMBER;
3574 l_db_rec                               CS_ESTIMATE_DETAILS%ROWTYPE;
3575 
3576 l_transaction_type_changed             VARCHAR2(1);
3577 l_item_changed                         VARCHAR2(1);
3578 
3579 l_incident_date                        DATE;
3580 l_creation_date                        DATE;
3581 l_request_date                         DATE;
3582 l_contract_line_id                     NUMBER;
3583 
3584 --RF
3585 l_db_det_rec                           CS_ESTIMATE_DETAILS%ROWTYPE;
3586 l_calc_sp                              VARCHAR2(1);
3587 
3588 --Fix for Bug # 3362130
3589 l_comms_trackable_flag                 VARCHAR2(1);
3590 
3591 l_in_oe_flag                           VARCHAR2(1) := 'N';
3592 l_in_ib_flag                           VARCHAR2(1) := 'N';
3593 l_rollup_flag                          VARCHAR2(1) := 'N';
3594 l_bp_changed                           VARCHAR2(1) := 'N';
3595 l_update_org                           VARCHAR2(10);
3596 
3597 l_valid_check                          VARCHAR2(1);
3598 
3599 
3600 l_disallow_new_charge                  VARCHAR2(1);
3601 l_disallow_charge_update               VARCHAR2(1);
3602 
3603 -- Added to fix Bug # 3819167
3604 -- Fixed Bug # 3913707
3605 -- l_absolute_quantity_required           NUMBER;
3606 
3607 -- Added for bug # 4395867
3608 l_original_source VARCHAR2(30);
3609 l_source VARCHAR2(30);
3610 l_pricing_date Date; -- Bug 	7117553
3611 l_profile_value Varchar2(100); -- Bug 	7117553
3612 
3613 -- Added for bug#5125934
3614 l_serial_number                         VARCHAR2(30);
3615 
3616 
3617 --taklam
3618 l_internal_party_id                    NUMBER;
3619 l_src_change_owner                     VARCHAR2(1);
3620 
3621 -- Depot Loaner fix - Bug# 4586140
3622 l_action_code   varchar2(30);
3623 
3624 Cursor C_SRC_CHANGE_OWNER(p_txn_billing_type_id NUMBER) IS
3625 SELECT src_change_owner
3626 FROM CSI_IB_TXN_TYPES
3627 WHERE cs_transaction_type_id = p_txn_billing_type_id;
3628 
3629 -- Depot Loaner fix - Bug# 4586140
3630 -- Cursor to get depot details
3631 /* Fix bug:5198520 */
3632 Cursor c_get_depot_txns_details (p_estimate_detail_id in number) is
3633 SELECT action_code
3634 FROM   csd_product_transactions
3635 WHERE  estimate_detail_id = p_estimate_detail_id;
3636 
3637 /* Select action_code
3638 from csd_product_txns_v
3639 where estimate_detail_id = p_estimate_detail_id; */
3640 
3641 -- Added for bug#5125934
3642 Cursor c_serial_number(p_instance_id NUMBER) IS
3643 SELECT serial_number
3644 FROM   csi_item_instances
3645 WHERE  instance_id = p_instance_id;
3646 
3647 BEGIN
3648 
3649   --Standard Start of API Savepoint
3650   SAVEPOINT Validate_Charge_Details_PUB;
3651 
3652   --Initialize the API Return Success to True
3653   x_return_status := FND_API.G_RET_STS_SUCCESS;
3654 
3655   --DBMS_OUTPUT.PUT_LINE('BEGIN VALIDATE_CHARGE_DETAILS');
3656   --DBMS_OUTPUT.PUT_LINE('Cust_product_id is '||P_CHARGES_DETAIL_REC.customer_product_id);
3657   --DBMS_OUTPUT.PUT_LINE('Apply contract_discount '||P_CHARGES_DETAIL_REC.apply_contract_discount);
3658 
3659   --=============================
3660   --Estimate Detail ID Validation
3661   --==============================
3662   --DBMS_OUTPUT.PUT_LINE('Estimate Detail ID Validation ...');
3663 
3664   --DBMS_OUTPUT.PUT_LINE('Estimate Detail Id : '||p_charges_detail_rec.estimate_detail_id);
3665 
3666   --Check to see that estimate_detail_id is passed
3667   --If not passed the give error
3668   --If passed then validate and then
3669   --get the charges record from the database
3670 
3671   IF p_validation_mode = 'U' THEN
3672     IF p_charges_detail_rec.estimate_detail_id IS NULL OR
3673        p_charges_detail_rec.estimate_detail_id = FND_API.G_MISS_NUM THEN
3674 
3675       Add_Null_Parameter_Msg(l_api_name,
3676                              'estimate_detail_id') ;
3677 
3678       Add_Invalid_Argument_Msg(l_api_name,
3679                                TO_CHAR(p_charges_detail_rec.estimate_detail_id),
3680                                'estimate_detail_id');
3681       RAISE FND_API.G_EXC_ERROR;
3682 
3683     ELSE
3684 
3685       IF IS_ESTIMATE_DETAIL_ID_VALID(p_estimate_detail_id => p_charges_detail_rec.estimate_detail_id,
3686                                      x_msg_data           => l_msg_data,
3687                                      x_msg_count          => l_msg_count,
3688                                      x_return_status      => l_return_status) = 'U' THEN
3689 
3690         --raise unexpected error
3691         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3692 
3693       ELSIF IS_ESTIMATE_DETAIL_ID_VALID(p_estimate_detail_id => p_charges_detail_rec.estimate_detail_id,
3694                                      x_msg_data           => l_msg_data,
3695                                      x_msg_count          => l_msg_count,
3696                                      x_return_status      => l_return_status) = 'N' THEN
3697 
3698         Add_Invalid_Argument_Msg(l_api_name,
3699                                TO_CHAR(p_charges_detail_rec.estimate_detail_id),
3700                                'estimate_detail_id');
3701         RAISE FND_API.G_EXC_ERROR;
3702 
3703       ELSE
3704         --estimate detail id is valid
3705         --assign to out record
3706         x_charges_detail_rec.estimate_detail_id := p_charges_detail_rec.estimate_detail_id;
3707 
3708         -- Get existing Charges record for this estimate detail_id
3709         Get_Charge_Detail_Rec(p_api_name             => l_api_name_full,
3710                               p_estimate_detail_id   => p_charges_detail_rec.estimate_detail_id,
3711                               x_charge_detail_rec    => l_db_det_rec,
3712                               x_msg_data             => l_msg_data,
3713                               x_msg_count            => l_msg_count,
3714                               x_return_status        => l_return_status);
3715 
3716         IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
3717           RAISE FND_API.G_EXC_ERROR;
3718         ELSIF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
3719           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3720         END IF;
3721 
3722       END IF;
3723     END IF;
3724   END IF;
3725 
3726 
3727   --========================
3728   --Incident ID Validation
3729   --========================
3730   --DBMS_OUTPUT.PUT_LINE('Incident ID Validation ...');
3731 
3732   IF p_validation_mode = 'I' THEN
3733 
3734     --If incident_id is not passed the
3735     --raise error
3736     --else validate the incident_id and assign to out record
3737     --and get the SR defaults
3738 
3739     IF p_charges_detail_rec.incident_id IS NULL THEN
3740 
3741       Add_Null_Parameter_Msg(l_api_name,
3742                              'p_incident_id') ;
3743 
3744       Add_Invalid_Argument_Msg(l_api_name,
3745                                to_char(p_charges_detail_rec.incident_id),
3746                                'incident_id');
3747       RAISE FND_API.G_EXC_ERROR;
3748 
3749     ELSE
3750       -- The incident_id IS NOT NULL
3751       l_valid_check := IS_INCIDENT_ID_VALID( p_incident_id   => p_charges_detail_rec.incident_id,
3752                                x_msg_data      => l_msg_data,
3753                                x_msg_count     => l_msg_count,
3754                                x_return_status => l_return_status);
3755 
3756       IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
3757         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3758       ELSIF l_return_status = G_RET_STS_ERROR THEN
3759         RAISE FND_API.G_EXC_ERROR;
3760       END IF;
3761 
3762       IF l_valid_check <> 'Y' THEN
3763 
3764         Add_Invalid_Argument_Msg(l_api_name,
3765                                  to_char(p_charges_detail_rec.incident_id),
3766                                  'incident_id');
3767 
3768         RAISE FND_API.G_EXC_ERROR;
3769 
3770       ELSE
3771         -- assign it to the out record
3772         x_charges_detail_rec.incident_id := p_charges_detail_rec.incident_id;
3773 
3774         -- get the defaults from Service Request for the incident id
3775         get_sr_defaults(p_api_name              => p_api_name,
3776                         p_incident_id           => x_charges_detail_rec.incident_id,
3777                         x_business_process_id   => l_business_process_id,
3778                         x_customer_id           => l_customer_id,
3779                         x_customer_site_id      => l_customer_site_id,
3780                         x_cust_po_number        => l_cust_po_number,
3781                         x_customer_product_id   => l_cust_product_id,
3782                         x_system_id             => l_system_id,       -- Fix bug
3783                         x_inventory_item_id     => l_inventory_item_id, -- Fix bug
3784                         x_account_id            => l_account_id,
3785                         x_bill_to_party_id      => l_bill_to_party_id,
3786                         x_bill_to_account_id    => l_bill_to_account_id,
3787                         x_bill_to_contact_id    => l_bill_to_contact_id,
3788                         x_bill_to_site_id       => l_bill_to_site_id,
3789                         x_ship_to_party_id      => l_ship_to_party_id,
3790                         x_ship_to_account_id    => l_ship_to_account_id,
3791                         x_ship_to_contact_id    => l_ship_to_contact_id,
3792                         x_ship_to_site_id       => l_ship_to_site_id,
3793                         x_contract_id           => l_contract_id,
3794                         x_contract_service_id   => l_contract_service_id,
3795                         x_incident_date         => l_incident_date,
3796                         x_creation_date         => l_creation_date,
3797                         x_msg_data              => l_msg_data,
3798                         x_msg_count             => l_msg_count,
3799                         x_return_status         => l_return_status);
3800 
3801         --DBMS_OUTPUT.PUT_LINE('Back from GET_SR_DEFAULTS l_bill_to_party_id '||l_bill_to_party_id);
3802         --DBMS_OUTPUT.PUT_LINE('Back from GET_SR_DEFAULTS l_ship_to_party_id '||l_ship_to_party_id);
3803 
3804         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3805           RAISE FND_API.G_EXC_ERROR ;
3806         END IF;
3807 
3808         --DBMS_OUTPUT.PUT_LINE('l_incident_date '||l_incident_date);
3809         --DBMS_OUTPUT.PUT_LINE('l_creation_date '||l_creation_date);
3810 
3811       END IF;
3812     END IF;
3813   END IF;
3814 
3815   -- This needs to be merged with the above validation
3816 
3817   IF p_validation_mode = 'U' THEN
3818 
3819      --DBMS_OUTPUT.PUT_LINE('Incident_id '||l_db_det_rec.incident_id);
3820      -- Incident Id cannot be changed, assign from the database
3821 
3822       x_charges_detail_rec.incident_id := l_db_det_rec.incident_id;
3823 
3824       -- get the defaults from Service Request for the incident id
3825       get_sr_defaults(p_api_name              => p_api_name,
3826                       p_incident_id           => x_charges_detail_rec.incident_id,
3827                       x_business_process_id   => l_business_process_id,
3828                       x_customer_id           => l_customer_id,
3829                       x_customer_site_id      => l_customer_site_id,
3830                       x_cust_po_number        => l_cust_po_number,
3831                       x_customer_product_id   => l_cust_product_id,
3832                       x_system_id             => l_system_id,         -- Fix bug
3833                       x_inventory_item_id     => l_inventory_item_id, -- Fix bug
3834                       x_account_id            => l_account_id,
3835                       x_bill_to_party_id      => l_bill_to_party_id,
3836                       x_bill_to_account_id    => l_bill_to_account_id,
3837                       x_bill_to_contact_id    => l_bill_to_contact_id,
3838                       x_bill_to_site_id       => l_bill_to_site_id,
3839                       x_ship_to_party_id      => l_ship_to_party_id,
3840                       x_ship_to_account_id    => l_ship_to_account_id,
3841                       x_ship_to_contact_id    => l_ship_to_contact_id,
3842                       x_ship_to_site_id       => l_ship_to_site_id,
3843                       x_contract_id           => l_contract_id,
3844                       x_contract_service_id   => l_contract_service_id,
3845                       x_incident_date         => l_incident_date,
3846                       x_creation_date         => l_creation_date,
3847                       x_msg_data              => l_msg_data,
3848                       x_msg_count             => l_msg_count,
3849                       x_return_status         => l_return_status
3850                       );
3851 
3852       --DBMS_OUTPUT.PUT_LINE('business_process_id'||l_business_process_id);
3853       --DBMS_OUTPUT.PUT_LINE('customer_id'||l_customer_id);
3854       --DBMS_OUTPUT.PUT_LINE('customer_site_id'||l_customer_site_id);
3855       --DBMS_OUTPUT.PUT_LINE('cust_po_number'||l_cust_po_number);
3856       --DBMS_OUTPUT.PUT_LINE('customer_product_id'||l_cust_product_id);
3857       --DBMS_OUTPUT.PUT_LINE('account_id'||l_account_id);
3858       --DBMS_OUTPUT.PUT_LINE('bill_to_party_id'|| l_bill_to_party_id);
3859       --DBMS_OUTPUT.PUT_LINE('bill_to_account_id'||l_bill_to_account_id);
3860       --DBMS_OUTPUT.PUT_LINE('bill_to_contact_id'||l_bill_to_contact_id);
3861       --DBMS_OUTPUT.PUT_LINE('bill_to_site_id'||l_bill_to_site_id);
3862       --DBMS_OUTPUT.PUT_LINE('ship_to_party_id'||l_ship_to_account_id);
3863       --DBMS_OUTPUT.PUT_LINE('ship_to_account_id'||l_ship_to_account_id);
3864       --DBMS_OUTPUT.PUT_LINE('ship_to_contact_id'||l_ship_to_contact_id);
3865       --DBMS_OUTPUT.PUT_LINE('ship_to_site_id'||l_ship_to_site_id);
3866       --DBMS_OUTPUT.PUT_LINE('contract_id'||l_contract_id);
3867       --DBMS_OUTPUT.PUT_LINE('contract_service_id'||l_contract_service_id);
3868       --DBMS_OUTPUT.PUT_LINE('msg_data'||l_msg_data);
3869       --DBMS_OUTPUT.PUT_LINE('msg_count'|| l_msg_count);
3870       --DBMS_OUTPUT.PUT_LINE('return_status'||l_return_status);
3871 
3872 
3873       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
3874         RAISE FND_API.G_EXC_ERROR ;
3875       END IF;
3876 
3877   ELSE
3878 
3879     null;
3880 
3881   END IF;
3882 
3883  --===================================================
3884  -- Get the disallow_new_charge_flag and
3885  -- disallow_charge_update_flag for the incident_id
3886  --===================================================
3887 
3888  --DBMS_OUTPUT.PUT_LINE('getting status form SR');
3889  --Bug Fix for Bug # 3086455
3890  get_charge_flags_from_sr(p_api_name               => p_api_name,
3891                           p_incident_id            => x_charges_detail_rec.incident_id,
3892                           x_disallow_new_charge    => l_disallow_new_charge,
3893                           x_disallow_charge_update => l_disallow_charge_update,
3894                           x_msg_data               => l_msg_data,
3895                           x_msg_count              => l_msg_count,
3896                           x_return_status          => l_return_status
3897                           );
3898 
3899  --DBMS_OUTPUT.PUT_LINE('l_disallow_new_charge is '||l_disallow_new_charge);
3900  --DBMS_OUTPUT.PUT_LINE('l_disallow_charge_update is '||l_disallow_charge_update);
3901 
3902  IF p_validation_mode = 'I' THEN
3903    IF l_disallow_new_charge  = 'Y' THEN
3904      --DBMS_OUTPUT.PUT_LINE('l_disallow_new_charge is '||l_disallow_new_charge);
3905      --raise error
3906      FND_MESSAGE.SET_NAME('CS', 'CS_CHG_CANNOT_INSERT');
3907      FND_MSG_PUB.ADD;
3908      RAISE FND_API.G_EXC_ERROR;
3909    END IF;
3910  ELSIF p_validation_mode = 'U' THEN
3911    IF l_disallow_charge_update = 'Y' THEN
3912      --raise error
3913      FND_MESSAGE.SET_NAME('CS', 'CS_CHG_CANNOT_UPDATE');
3914      FND_MSG_PUB.ADD;
3915      RAISE FND_API.G_EXC_ERROR;
3916    END IF;
3917  END IF;
3918 
3919 
3920  --===================================================
3921  --Assign values to columns that don't need validation
3922  --mviswana need to verify and change this
3923  --===================================================
3924 
3925   --DBMS_OUTPUT.PUT_LINE('Assign values to columns that do not need validation ...');
3926 
3927   IF p_validation_mode = 'I' THEN
3928 
3929     --IF p_charges_detail_rec.interface_to_oe_flag IS NOT NULL THEN
3930     --  x_charges_detail_rec.interface_to_oe_flag := p_charges_detail_rec.interface_to_oe_flag;
3931     --ELSE
3932     --  x_charges_detail_rec.interface_to_oe_flag := 'Y';
3933     --END IF;
3934 
3935     -- Added for Bug # 5135284
3936     IF p_charges_detail_rec.rollup_flag IS NOT NULL AND
3937        p_charges_detail_rec.rollup_flag IN ('Y', 'N') THEN
3938       x_charges_detail_rec.rollup_flag := p_charges_detail_rec.rollup_flag;
3939     ELSE
3940       x_charges_detail_rec.rollup_flag := 'N';
3941     END IF;
3942 
3943     -- Added for Bug # 5135284
3944     -- commenting for now
3945     IF p_charges_detail_rec.add_to_order_flag IS NOT NULL AND
3946        p_charges_detail_rec.add_to_order_flag IN ('Y', 'N', 'F') THEN
3947       x_charges_detail_rec.add_to_order_flag := p_charges_detail_rec.add_to_order_flag;
3948     ELSE
3949       x_charges_detail_rec.add_to_order_flag := 'N';
3950     END IF;
3951 
3952     IF p_charges_detail_rec.apply_contract_discount IS NULL THEN
3953       x_charges_detail_rec.apply_contract_discount := 'N';
3954     ELSE
3955       x_charges_detail_rec.apply_contract_discount := p_charges_detail_rec.apply_contract_discount;
3956     END IF;
3957 
3958     x_charges_detail_rec.estimate_detail_id          := NULL;
3959     x_charges_detail_rec.order_line_id               := NULL;
3960     x_charges_detail_rec.coverage_bill_rate_id       := p_charges_detail_rec.coverage_bill_rate_id;
3961     x_charges_detail_rec.transaction_sub_inventory   := p_charges_detail_rec.transaction_sub_inventory;
3962     x_charges_detail_rec.submit_restriction_message  := p_charges_detail_rec.submit_restriction_message;
3963     x_charges_detail_rec.submit_error_message        := p_charges_detail_rec.submit_error_message;
3964     x_charges_detail_rec.submit_from_system          := p_charges_detail_rec.submit_from_system;
3965 
3966 
3967     --DBMS_OUTPUT.PUT_LINE('ORDER_LINE_ID IS '||x_charges_detail_rec.order_line_id);
3968 
3969   ELSIF p_validation_mode = 'U' THEN
3970 
3971     --Resolve Bug # 3078244
3972     --Resolve Bug # 3084879
3973 
3974     --DBMS_OUTPUT.PUT_LINE(' In Update Validation');
3975     --DBMS_OUTPUT.PUT_LINE(' p_charges_detail_rec.add_to_order_flag '||p_charges_detail_rec.add_to_order_flag );
3976     --DBMS_OUTPUT.PUT_LINE(' p_charges_detail_rec.coverage_bill_rate_id '||p_charges_detail_rec.coverage_bill_rate_id);
3977     --DBMS_OUTPUT.PUT_LINE(' p_charges_detail_rec.transaction_sub_inventory '||p_charges_detail_rec.transaction_sub_inventory);
3978 
3979     -- Check to see if add_to_order_flag is passed
3980     -- If not passed then assign from database
3981     -- If passed as null then assign 'N'
3982     -- If passed then assign to the out parameter
3983 
3984     IF p_charges_detail_rec.add_to_order_flag = FND_API.G_MISS_CHAR THEN
3985       x_charges_detail_rec.add_to_order_flag :=  l_db_det_rec.add_to_order_flag;
3986     ELSIF p_charges_detail_rec.add_to_order_flag IS NULL THEN
3987       x_charges_detail_rec.add_to_order_flag :=  'N';
3988     ELSE
3989       -- Added for Bug # 5135284
3990       IF p_charges_detail_rec.add_to_order_flag IN ('Y', 'N', 'F') THEN
3991         x_charges_detail_rec.add_to_order_flag :=  p_charges_detail_rec.add_to_order_flag;
3992       ELSE
3993         x_charges_detail_rec.add_to_order_flag :=  'N';
3994       END IF;
3995     END IF;
3996 
3997     --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.add_to_order_flag'||x_charges_detail_rec.add_to_order_flag);
3998 
3999     -- Check to see if coverage_bill_rate_id is passed
4000     -- If not passed then assign from database
4001     -- If passed as null then assign NULL
4002     -- If passed then assign to the out parameter
4003 
4004     IF p_charges_detail_rec.coverage_bill_rate_id = FND_API.G_MISS_NUM THEN
4005       x_charges_detail_rec.coverage_bill_rate_id :=  l_db_det_rec.coverage_bill_rate_id;
4006     ELSIF p_charges_detail_rec.coverage_bill_rate_id IS NULL THEN
4007       x_charges_detail_rec.coverage_bill_rate_id :=  null;
4008     ELSE
4009       x_charges_detail_rec.coverage_bill_rate_id :=  p_charges_detail_rec.coverage_bill_rate_id;
4010     END IF;
4011 
4012     --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.coverage_bill_rate_id'||x_charges_detail_rec.coverage_bill_rate_id);
4013 
4014     -- Check to see if transaction_sub_inventory is passed
4015     -- If not passed then assign from database
4016     -- If passed as null then assign NULL
4017     -- If passed then assign to the out parameter
4018 
4019     IF p_charges_detail_rec.transaction_sub_inventory = FND_API.G_MISS_CHAR THEN
4020       x_charges_detail_rec.transaction_sub_inventory :=  l_db_det_rec.transaction_sub_inventory;
4021     ELSIF p_charges_detail_rec.transaction_sub_inventory IS NULL THEN
4022       x_charges_detail_rec.transaction_sub_inventory :=  null;
4023     ELSE
4024       x_charges_detail_rec.transaction_sub_inventory :=  p_charges_detail_rec.transaction_sub_inventory;
4025     END IF;
4026 
4027 
4028     --DBMS_OUTPUT.PUT_LINE(' x_charges_detail_rec.transaction_sub_inventory '|| x_charges_detail_rec.transaction_sub_inventory);
4029 
4030     -- Check to see if interface_to_oe_flag is passed
4031     -- If not passed then assign from database
4032     -- If passed as null then assign NULL
4033     -- If passed then assign to the out parameter
4034 
4035     --IF p_charges_detail_rec.interface_to_oe_flag = FND_API.G_MISS_CHAR THEN
4036     --  x_charges_detail_rec.interface_to_oe_flag :=  l_db_det_rec.interface_to_oe_flag;
4037     --ELSIF p_charges_detail_rec.interface_to_oe_flag IS NULL THEN
4038     --  x_charges_detail_rec.interface_to_oe_flag :=  'N';
4039     --ELSE
4040     --  x_charges_detail_rec.interface_to_oe_flag :=  p_charges_detail_rec.interface_to_oe_flag;
4041     --END IF;
4042 
4043     --DBMS_OUTPUT.PUT_LINE(' x_charges_detail_rec.interface_to_oe_flag '||x_charges_detail_rec.interface_to_oe_flag);
4044 
4045     -- Check to see if apply_contract_discount is passed
4046     -- If not passed then assign from database
4047     -- If passed as null then assign NULL
4048     -- If passed then assign to the out parameter
4049 
4050     IF p_charges_detail_rec.apply_contract_discount = FND_API.G_MISS_CHAR OR
4051        p_charges_detail_rec.apply_contract_discount IS NULL THEN
4052        x_charges_detail_rec.apply_contract_discount := 'N';
4053     ELSE
4054       x_charges_detail_rec.apply_contract_discount := p_charges_detail_rec.apply_contract_discount;
4055     END IF;
4056 
4057     --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.apply_contract_discount'||x_charges_detail_rec.apply_contract_discount);
4058 
4059     -- Check to see if con_pct_over_list_price is passed
4060     -- If not passed then OR
4061     -- If passed as null then assign NULL
4062     -- If passed then assign to the out parameter
4063 
4064     IF p_charges_detail_rec.con_pct_over_list_price = FND_API.G_MISS_NUM OR
4065        p_charges_detail_rec.con_pct_over_list_price IS NULL THEN
4066        x_charges_detail_rec.con_pct_over_list_price := NULL;
4067     ELSE
4068       x_charges_detail_rec.con_pct_over_list_price  := p_charges_detail_rec.con_pct_over_list_price;
4069     END IF;
4070 
4071     x_charges_detail_rec.order_line_id := l_db_det_rec.order_line_id;
4072 
4073     -- Check to see if submit_restriction_message is passed
4074     -- If not passed then assign the value in the database
4075     -- If passed as NULL then assign NULL
4076     -- If passed then assign to out parameter
4077 
4078     IF p_charges_detail_rec.submit_restriction_message = FND_API.G_MISS_CHAR THEN
4079       x_charges_detail_rec.submit_restriction_message :=  l_db_det_rec.submit_restriction_message;
4080     ELSIF p_charges_detail_rec.submit_restriction_message IS NULL THEN
4081       x_charges_detail_rec.submit_restriction_message :=  NULL;
4082     ELSE
4083       x_charges_detail_rec.submit_restriction_message :=  p_charges_detail_rec.submit_restriction_message;
4084     END IF;
4085 
4086     -- Check to see if submit_error_message is passed
4087     -- If not passed then assign the value in the database
4088     -- If passed as NULL then assign NULL
4089     -- If passed then assign to out parameter
4090 
4091     IF p_charges_detail_rec.submit_error_message = FND_API.G_MISS_CHAR THEN
4092       x_charges_detail_rec.submit_error_message :=  l_db_det_rec.submit_error_message;
4093     ELSIF p_charges_detail_rec.submit_error_message IS NULL THEN
4094       x_charges_detail_rec.submit_error_message :=  NULL;
4095     ELSE
4096       x_charges_detail_rec.submit_error_message :=  p_charges_detail_rec.submit_error_message;
4097     END IF;
4098 
4099     -- Check to see if submit_from_system  is passed
4100     -- If not passed then assign the value in the database
4101     -- If passed as NULL then assign NULL
4102     -- If passed then assign to out parameter
4103 
4104     IF p_charges_detail_rec.submit_from_system = FND_API.G_MISS_CHAR THEN
4105       x_charges_detail_rec.submit_from_system :=  l_db_det_rec.submit_from_system;
4106     ELSIF p_charges_detail_rec.submit_from_system IS NULL THEN
4107       x_charges_detail_rec.submit_from_system :=  NULL;
4108     ELSE
4109       x_charges_detail_rec.submit_from_system :=  p_charges_detail_rec.submit_from_system;
4110     END IF;
4111 
4112   END IF;
4113 
4114 --=====================================
4115 -- Validate the Org_id Passed
4116 --====================================
4117 
4118   -- Get Org ID from Source for Incident ID
4119   --   CS_Multiorg_PVT.Get_OrgId(
4120   --                P_API_VERSION    => 1.2,
4121   --                P_INIT_MSG_LIST  => FND_API.G_FALSE,
4122   --                X_RETURN_STATUS  => l_return_status,
4123   --                X_MSG_COUNT      => l_msg_count,
4124   --                X_MSG_DATA       => l_msg_data,
4125   --                P_INCIDENT_ID    => p_charges_detail_rec.incident_id,
4126   --                X_ORG_ID         => l_org_id,
4127   --                X_PROFILE        => l_profile);
4128 
4129   -- -- --DBMS_OUTPUT.PUT_LINE('Back from CS_Multiorg_PVT.Get_OrgId '||l_return_status);
4130   -- -- --DBMS_OUTPUT.PUT_LINE('X Profile '||l_profile);
4131   -- -- --DBMS_OUTPUT.PUT_LINE('l_org_id '||l_org_id);
4132 
4133 
4134   -- Get Org ID from Source for Incident ID
4135   -- Call CS_MultiOrg_PUB.Get_OrgID
4136   -- This uses the new multi org public API
4137   --
4138   CS_Multiorg_PUB.Get_OrgId(
4139                 P_API_VERSION       => 1.0,
4140                 P_INIT_MSG_LIST     => FND_API.G_FALSE,
4141                 -- Fix bug 3236597 P_COMMIT            => 'T',
4142                 P_COMMIT            => 'F',  -- Fix bug 3236597
4143                 P_VALIDATION_LEVEL  => FND_API.G_VALID_LEVEL_FULL,
4144                 X_RETURN_STATUS     => l_return_status,
4145                 X_MSG_COUNT         => l_msg_count,
4146                 X_MSG_DATA          => l_msg_data,
4147                 P_INCIDENT_ID       => p_charges_detail_rec.incident_id,
4148                 X_ORG_ID            => l_org_id,
4149                 X_PROFILE           => l_profile);
4150 
4151   --DBMS_OUTPUT.PUT_LINE('Back from CS_Multiorg_PVT.Get_OrgId '||l_return_status);
4152   --DBMS_OUTPUT.PUT_LINE('X Profile '||l_profile);
4153   --DBMS_OUTPUT.PUT_LINE('l_org_id '||l_org_id);
4154 
4155 
4156   IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4157     RAISE FND_API.G_EXC_ERROR ;
4158   END IF;
4159 
4160   IF p_validation_mode = 'I' THEN
4161     IF l_profile = 'Y' THEN
4162       IF p_charges_detail_rec.org_id IS NOT NULL THEN
4163         VALIDATE_ORG_ID(
4164                   P_API_NAME       => l_api_name,
4165                   P_ORG_ID         => p_charges_detail_rec.org_id,
4166                   X_RETURN_STATUS  => l_return_status,
4167                   X_MSG_COUNT      => l_msg_count,
4168                   X_MSG_DATA       => l_msg_data);
4169 
4170         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4171           RAISE FND_API.G_EXC_ERROR ;
4172         END IF;
4173         x_charges_detail_rec.org_id := p_charges_detail_rec.org_id;
4174       ELSE
4175         --use the default
4176         x_charges_detail_rec.org_id := l_org_id;
4177       END IF;
4178     ELSE
4179       -- l_profile = 'N'
4180       IF p_charges_detail_rec.org_id IS NOT NULL THEN
4181         IF p_charges_detail_rec.org_id <> l_org_id THEN
4182           --raise error
4183           --Need to define error here
4184           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_CANNOT_CHANGE_OU');
4185           FND_MESSAGE.SET_TOKEN('API_NAME', p_api_name);
4186           FND_MSG_PUB.ADD;
4187           RAISE FND_API.G_EXC_ERROR;
4188         ELSE
4189           x_charges_detail_rec.org_id := p_charges_detail_rec.org_id;
4190         END IF;
4191       ELSE
4192         --p_charges_detail_rec.org_id IS NULL
4193         --assign default
4194         x_charges_detail_rec.org_id := l_org_id;
4195       END IF;
4196     END IF;
4197 
4198   ELSIF p_validation_mode = 'U' THEN
4199     -- Get Org ID from Source for Incident ID
4200     -- Resolve Bug # 3078244
4201 
4202     IF l_profile = 'Y' THEN
4203 
4204       -- If l_profile = 'Y' THEN if org_id is not passed
4205       -- or org_id is null then assign the value from the database
4206       -- else if passed then validate the org_id and if valid then
4207       -- assign the value to the out parameter
4208 
4209       IF p_charges_detail_rec.org_id = FND_API.G_MISS_NUM OR
4210          p_charges_detail_rec.org_id IS NULL THEN
4211          --use the value from the database
4212          x_charges_detail_rec.org_id := l_db_det_rec.org_id;
4213 
4214       ELSE
4215         VALIDATE_ORG_ID(
4216                   P_API_NAME       => l_api_name,
4217                   P_ORG_ID         => p_charges_detail_rec.org_id,
4218                   X_RETURN_STATUS  => l_return_status,
4219                   X_MSG_COUNT      => l_msg_count,
4220                   X_MSG_DATA       => l_msg_data);
4221 
4222         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4223           RAISE FND_API.G_EXC_ERROR ;
4224         END IF;
4225         x_charges_detail_rec.org_id := p_charges_detail_rec.org_id;
4226 
4227       END IF;
4228 
4229     ELSE
4230       -- l_profile = 'N'
4231       -- If l_profile = 'N' THEN if org_id is not passed
4232       -- or org_id is null then assign the value from the database
4233       -- else if passed then validate the org_id and if valid then
4234       -- assign the value to the out parameter
4235 
4236       IF p_charges_detail_rec.org_id = FND_API.G_MISS_NUM OR
4237          p_charges_detail_rec.org_id IS NULL THEN
4238         --use the value from the database
4239         x_charges_detail_rec.org_id := l_db_det_rec.org_id;
4240 
4241       ELSE
4242         IF p_charges_detail_rec.org_id <> l_db_det_rec.org_id THEN
4243           --raise error
4244           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_CANNOT_CHANGE_OU');
4245           FND_MESSAGE.SET_TOKEN('API_NAME', p_api_name);
4246           FND_MSG_PUB.ADD;
4247           RAISE FND_API.G_EXC_ERROR;
4248         ELSE
4249           x_charges_detail_rec.org_id := p_charges_detail_rec.org_id;
4250         END IF;
4251       END IF;
4252     END IF;
4253   END IF;
4254 
4255   --DBMS_OUTPUT.PUT_LINE('org_id '||x_charges_detail_rec.org_id);
4256 
4257 --=====================================
4258 --Validate Original Source
4259 --=====================================
4260   --DBMS_OUTPUT.PUT_LINE('Validate Original Source ...');
4261   IF p_validation_mode = 'I' THEN
4262     IF (p_charges_detail_rec.original_source_code IS NULL) OR (p_charges_detail_rec.original_source_id IS NULL) THEN
4263 
4264       FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_ORIGINAL_SOURCE');
4265       FND_MESSAGE.SET_TOKEN('ORIG_SOURCE_ID', p_charges_detail_rec.original_source_id);
4266       FND_MESSAGE.SET_TOKEN('ORIG_SOURCE_CODE', p_charges_detail_rec.original_source_code);
4267       FND_MSG_PUB.ADD;
4268       RAISE FND_API.G_EXC_ERROR;
4269 
4270     ELSE
4271       VALIDATE_SOURCE(
4272                 P_API_NAME         => p_api_name,
4273                 P_SOURCE_CODE      => p_charges_detail_rec.original_source_code,
4274                 P_SOURCE_ID        => p_charges_detail_rec.original_source_id,
4275                 P_ORG_ID           => x_charges_detail_rec.org_id,
4276                 X_SOURCE_ID        => l_source_id,
4277                 X_MSG_DATA         => l_msg_data,
4278                 X_MSG_COUNT        => l_msg_count,
4279                 X_RETURN_STATUS    => l_return_status) ;
4280 
4281       --DBMS_OUTPUT.PUT_LINE('Back from VALIDATE_SOURCE for ORIG SOURCE '||l_return_status);
4282 
4283       --IF l_return_status <> 'S' THEN
4284       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4285         --raise error
4286         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_ORIGINAL_SOURCE');
4287         FND_MESSAGE.SET_TOKEN('ORIG_SOURCE_ID', p_charges_detail_rec.original_source_id);
4288         FND_MESSAGE.SET_TOKEN('ORIG_SOURCE_CODE', p_charges_detail_rec.original_source_code);
4289         FND_MSG_PUB.ADD;
4290         RAISE FND_API.G_EXC_ERROR;
4291       END IF;
4292 
4293       -- assign to out record
4294       x_charges_detail_rec.original_source_code := p_charges_detail_rec.original_source_code;
4295       x_charges_detail_rec.original_source_id := p_charges_detail_rec.original_source_id;
4296 
4297     END IF;
4298 
4299 
4300     IF (p_charges_detail_rec.source_code IS NOT NULL) AND (p_charges_detail_rec.source_id IS NOT NULL) THEN
4301       -- Call the Validate Source Procedure
4302 
4303       --DBMS_OUTPUT.PUT_LINE('source '||p_charges_detail_rec.source_code);
4304       --DBMS_OUTPUT.PUT_LINE('p_charges_detail_rec.source_id'||p_charges_detail_rec.source_id);
4305 
4306       VALIDATE_SOURCE(
4307            P_API_NAME         => p_api_name,
4308            P_SOURCE_CODE      => p_charges_detail_rec.source_code,
4309            P_SOURCE_ID        => p_charges_detail_rec.source_id,
4310            --P_ORG_ID         => l_org_id,
4311            P_ORG_ID           => x_charges_detail_rec.org_id,
4312            X_SOURCE_ID        => l_source_id,
4313            X_MSG_DATA         => l_msg_data,
4314            X_MSG_COUNT        => l_msg_count,
4315            X_RETURN_STATUS    => l_return_status) ;
4316 
4317       --DBMS_OUTPUT.PUT_LINE('Back from VALIDATE_SOURCE for SOURCE '||l_return_status);
4318 
4319       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4320         RAISE FND_API.G_EXC_ERROR ;
4321       END IF;
4322 
4323       --assign the values source_code, source_id to out record
4324       x_charges_detail_rec.source_code := p_charges_detail_rec.source_code;
4325       x_charges_detail_rec.source_id   := p_charges_detail_rec.source_id;
4326 
4327     ELSE
4328       --Default using original source code and original source id
4329       --assign the values source_code, source_id to out record
4330       x_charges_detail_rec.source_code := p_charges_detail_rec.original_source_code;
4331       x_charges_detail_rec.source_id   := p_charges_detail_rec.original_source_id;
4332 
4333     END IF;
4334 
4335   ELSIF p_validation_mode = 'U' THEN
4336 
4337     -- assign attributes from db record for original source id and
4338     -- original source code as both cannot be changed
4339     x_charges_detail_rec.original_source_id := l_db_det_rec.original_source_id;
4340     x_charges_detail_rec.original_source_code := l_db_det_rec.original_source_code;
4341 
4342 
4343 
4344     IF p_charges_detail_rec.source_code  = FND_API.G_MISS_CHAR OR
4345        p_charges_detail_rec.source_code IS NULL AND
4346        p_charges_detail_rec.source_id = FND_API.G_MISS_NUM OR
4347        p_charges_detail_rec.source_id IS NULL THEN
4348 
4349        --Default attributes using db record
4350        x_charges_detail_rec.source_code := l_db_det_rec.source_code;
4351        x_charges_detail_rec.source_id   := l_db_det_rec.source_id;
4352 
4353     ELSE
4354 
4355         VALIDATE_SOURCE(
4356            P_API_NAME         => p_api_name,
4357            P_SOURCE_CODE      => p_charges_detail_rec.source_code,
4358            P_SOURCE_ID        => p_charges_detail_rec.source_id,
4359            --P_ORG_ID         => l_org_id,
4360            P_ORG_ID           => x_charges_detail_rec.org_id,
4361            X_SOURCE_ID        => l_source_id,
4362            X_MSG_DATA         => l_msg_data,
4363            X_MSG_COUNT        => l_msg_count,
4364            X_RETURN_STATUS    => l_return_status) ;
4365 
4366         --DBMS_OUTPUT.PUT_LINE('Back from VALIDATE_SOURCE for SOURCE '||l_return_status);
4367 
4368         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
4369           RAISE FND_API.G_EXC_ERROR ;
4370         END IF;
4371 
4372         --assign the values source_code, source_id to out record
4373         x_charges_detail_rec.source_code := p_charges_detail_rec.source_code;
4374         x_charges_detail_rec.source_id   := p_charges_detail_rec.source_id;
4375 
4376     END IF;
4377 
4378   END IF;
4379 
4380   --DBMS_OUTPUT.PUT_LINE('Completed Source ID and Source Code Validation');
4381 
4382 --================================================================
4383 -- For Update Only
4384 -- Estimate Detail Record cannot be updated based
4385 -- on certain restrictions
4386 -- If order lines exist for the record then we cannot update line
4387 -- If the line is generated by billing engine then we cannot
4388 -- update anything other than the after_warranty_cost
4389 --================================================================
4390   IF p_validation_mode = 'U' THEN
4391 
4392     --Bug Fix for Bug # 2878503
4393 
4394     IF l_db_det_rec.order_line_id IS NOT NULL THEN
4395       l_in_oe_flag  := 'Y' ;
4396     ELSE
4397       l_in_oe_flag := 'N' ;
4398     END IF ;
4399 
4400     --DBMS_OUTPUT.PUT_LINE('l_in_oe_flag '||l_in_oe_flag);
4401 
4402     IF l_in_oe_flag = 'Y' THEN
4403 
4404       --DBMS_OUTPUT.PUT_LINE(' l_db_det_rec.original_source_code '||l_db_det_rec.original_source_code);
4405       --DBMS_OUTPUT.PUT_LINE(' p_charges_detail_rec.source_code '||p_charges_detail_rec.source_code);
4406 
4407       -- If the Charge Line is Interfaced to OM the upstream can only change the
4408       -- source code from SR to DR and vice versa
4409       -- everything else is not updateable
4410 
4411       IF  l_db_det_rec.original_source_code IN ('SR', 'DR') AND
4412           p_charges_detail_rec.source_code <> FND_API.G_MISS_CHAR AND
4413           p_charges_detail_rec.source_code IS NOT NULL AND
4414           p_charges_detail_rec.source_code IN ('DR', 'SR') THEN
4415 
4416           --DBMS_OUTPUT.PUT_LINE(' Calling validate_source');
4417 
4418             VALIDATE_SOURCE(
4419                 P_API_NAME         => p_api_name,
4420                 P_SOURCE_CODE      => p_charges_detail_rec.original_source_code,
4421                 P_SOURCE_ID        => p_charges_detail_rec.original_source_id,
4422                 P_ORG_ID           => x_charges_detail_rec.org_id,
4423                 X_SOURCE_ID        => l_source_id,
4424                 X_MSG_DATA         => l_msg_data,
4425                 X_MSG_COUNT        => l_msg_count,
4426                 X_RETURN_STATUS    => l_return_status) ;
4427 
4428             IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
4429               RAISE FND_API.G_EXC_ERROR;
4430             ELSIF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
4431               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4432             END IF;
4433 
4434             --DBMS_OUTPUT.PUT_LINE(' l_source_id '||l_source_id);
4435 
4436             x_charges_detail_rec.source_id := l_source_id ;
4437             x_charges_detail_rec.source_code := p_charges_detail_rec.source_code ;
4438 
4439       ELSE
4440         --DBMS_OUTPUT.PUT_LINE('Coming to the else');
4441         FND_MESSAGE.Set_Name('CS', 'CS_CHG_CANNOT_UPDATE_CHRG_LINE');
4442         FND_MSG_PUB.Add;
4443         RAISE FND_API.G_EXC_ERROR;
4444       END IF;
4445 
4446       IF (p_charges_detail_rec.charge_line_type                <> FND_API.G_MISS_CHAR OR
4447           p_charges_detail_rec.line_number                     <> FND_API.G_MISS_NUM OR
4448           p_charges_detail_rec.business_process_id             <> FND_API.G_MISS_NUM  OR
4449           p_charges_detail_rec.transaction_type_id             <> FND_API.G_MISS_NUM  OR
4450           p_charges_detail_rec.inventory_item_id_in            <> FND_API.G_MISS_NUM  OR
4451           p_charges_detail_rec.item_revision                   <> FND_API.G_MISS_CHAR OR
4452           p_charges_detail_rec.billing_flag                    <> FND_API.G_MISS_CHAR OR
4453           p_charges_detail_rec.txn_billing_type_id             <> FND_API.G_MISS_NUM  OR
4454           p_charges_detail_rec.unit_of_measure_code            <> FND_API.G_MISS_CHAR OR
4455           p_charges_detail_rec.quantity_required               <> FND_API.G_MISS_NUM  OR
4456           p_charges_detail_rec.return_reason_code              <> FND_API.G_MISS_CHAR OR
4457           p_charges_detail_rec.customer_product_id             <> FND_API.G_MISS_NUM  OR
4458           p_charges_detail_rec.serial_number                   <> FND_API.G_MISS_CHAR OR
4459           p_charges_detail_rec.installed_cp_return_by_date     <> FND_API.G_MISS_DATE OR
4460           p_charges_detail_rec.new_cp_return_by_date           <> FND_API.G_MISS_DATE OR
4461           p_charges_detail_rec.sold_to_party_id                <> FND_API.G_MISS_NUM  OR
4462           p_charges_detail_rec.bill_to_party_id                <> FND_API.G_MISS_NUM  OR
4463           p_charges_detail_rec.bill_to_account_id              <> FND_API.G_MISS_NUM  OR
4464           p_charges_detail_rec.bill_to_contact_id              <> FND_API.G_MISS_NUM  OR
4465           p_charges_detail_rec.invoice_to_org_id               <> FND_API.G_MISS_NUM  OR
4466           p_charges_detail_rec.ship_to_party_id                <> FND_API.G_MISS_NUM  OR
4467           p_charges_detail_rec.ship_to_account_id              <> FND_API.G_MISS_NUM  OR
4468           p_charges_detail_rec.ship_to_contact_id              <> FND_API.G_MISS_NUM  OR
4469           p_charges_detail_rec.ship_to_org_id                  <> FND_API.G_MISS_NUM  OR
4470           p_charges_detail_rec.contract_id                     <> FND_API.G_MISS_NUM  OR
4471           p_charges_detail_rec.contract_line_id                <> FND_API.G_MISS_NUM  OR
4472           p_charges_detail_rec.coverage_id                     <> FND_API.G_MISS_NUM  OR
4473           p_charges_detail_rec.coverage_txn_group_id           <> FND_API.G_MISS_NUM  OR
4474           p_charges_detail_rec.coverage_bill_rate_id           <> FND_API.G_MISS_NUM  OR
4475           p_charges_detail_rec.coverage_billing_type_id        <> FND_API.G_MISS_NUM  OR
4476           p_charges_detail_rec.price_list_id                   <> FND_API.G_MISS_NUM  OR
4477           p_charges_detail_rec.currency_code                   <> FND_API.G_MISS_CHAR OR
4478           p_charges_detail_rec.purchase_order_num              <> FND_API.G_MISS_CHAR OR
4479           p_charges_detail_rec.list_price                      <> FND_API.G_MISS_NUM  OR
4480           p_charges_detail_rec.con_pct_over_list_price         <> FND_API.G_MISS_NUM  OR
4481           p_charges_detail_rec.selling_price                   <> FND_API.G_MISS_NUM  OR
4482           p_charges_detail_rec.contract_discount_amount        <> FND_API.G_MISS_NUM  OR
4483           p_charges_detail_rec.apply_contract_discount         <> FND_API.G_MISS_CHAR OR
4484           p_charges_detail_rec.after_warranty_cost             <> FND_API.G_MISS_NUM  OR
4485           p_charges_detail_rec.transaction_inventory_org       <> FND_API.G_MISS_NUM OR
4486           p_charges_detail_rec.transaction_sub_inventory       <> FND_API.G_MISS_CHAR OR
4487           p_charges_detail_rec.rollup_flag                     <> FND_API.G_MISS_CHAR OR
4488           p_charges_detail_rec.add_to_order_flag               <> FND_API.G_MISS_CHAR OR
4489           p_charges_detail_rec.order_header_id                 <> FND_API.G_MISS_NUM  OR
4490           p_charges_detail_rec.interface_to_oe_flag            <> FND_API.G_MISS_CHAR OR
4491           p_charges_detail_rec.no_charge_flag                  <> FND_API.G_MISS_CHAR OR
4492           p_charges_detail_rec.line_category_code              <> FND_API.G_MISS_CHAR OR
4493           p_charges_detail_rec.line_type_id                    <> FND_API.G_MISS_NUM  OR
4494           p_charges_detail_rec.order_line_id                   <> FND_API.G_MISS_NUM  OR
4495           p_charges_detail_rec.conversion_rate                 <> FND_API.G_MISS_NUM  OR
4496           p_charges_detail_rec.conversion_type_code            <> FND_API.G_MISS_CHAR OR
4497           p_charges_detail_rec.conversion_rate_date            <> FND_API.G_MISS_DATE OR
4498           p_charges_detail_rec.org_id                          <> FND_API.G_MISS_NUM  OR
4499           p_charges_detail_rec.activity_start_time             <> FND_API.G_MISS_DATE OR
4500           p_charges_detail_rec.activity_end_time               <> FND_API.G_MISS_DATE OR
4501           p_charges_detail_rec.generated_by_bca_engine         <> FND_API.G_MISS_CHAR OR
4502           p_charges_detail_rec.submit_restriction_message      <> FND_API.G_MISS_CHAR OR
4503           p_charges_detail_rec.submit_error_message            <> FND_API.G_MISS_CHAR OR
4504           p_charges_detail_rec.submit_from_system              <> FND_API.G_MISS_CHAR OR
4505           p_charges_detail_rec.attribute1                      <> FND_API.G_MISS_CHAR OR
4506           p_charges_detail_rec.attribute2                      <> FND_API.G_MISS_CHAR OR
4507           p_charges_detail_rec.attribute3                      <> FND_API.G_MISS_CHAR OR
4508           p_charges_detail_rec.attribute4                      <> FND_API.G_MISS_CHAR OR
4509           p_charges_detail_rec.attribute5                      <> FND_API.G_MISS_CHAR OR
4510           p_charges_detail_rec.attribute6                      <> FND_API.G_MISS_CHAR OR
4511           p_charges_detail_rec.attribute7                      <> FND_API.G_MISS_CHAR OR
4512           p_charges_detail_rec.attribute8                      <> FND_API.G_MISS_CHAR OR
4513           p_charges_detail_rec.attribute9                      <> FND_API.G_MISS_CHAR OR
4514           p_charges_detail_rec.attribute10                     <> FND_API.G_MISS_CHAR OR
4515           p_charges_detail_rec.attribute11                     <> FND_API.G_MISS_CHAR OR
4516           p_charges_detail_rec.attribute12                     <> FND_API.G_MISS_CHAR OR
4517           p_charges_detail_rec.attribute13                     <> FND_API.G_MISS_CHAR OR
4518           p_charges_detail_rec.attribute14                     <> FND_API.G_MISS_CHAR OR
4519           p_charges_detail_rec.attribute15                     <> FND_API.G_MISS_CHAR OR
4520           p_charges_detail_rec.context                         <> FND_API.G_MISS_CHAR OR
4521           p_charges_detail_rec.pricing_context                 <> FND_API.G_MISS_CHAR OR
4522           p_charges_detail_rec.pricing_attribute1              <> FND_API.G_MISS_CHAR OR
4523           p_charges_detail_rec.pricing_attribute2              <> FND_API.G_MISS_CHAR OR
4524           p_charges_detail_rec.pricing_attribute3              <> FND_API.G_MISS_CHAR OR
4525           p_charges_detail_rec.pricing_attribute4              <> FND_API.G_MISS_CHAR OR
4526           p_charges_detail_rec.pricing_attribute5              <> FND_API.G_MISS_CHAR OR
4527           p_charges_detail_rec.pricing_attribute6              <> FND_API.G_MISS_CHAR OR
4528           p_charges_detail_rec.pricing_attribute7              <> FND_API.G_MISS_CHAR OR
4529           p_charges_detail_rec.pricing_attribute8              <> FND_API.G_MISS_CHAR OR
4530           p_charges_detail_rec.pricing_attribute9              <> FND_API.G_MISS_CHAR OR
4531           p_charges_detail_rec.pricing_attribute10             <> FND_API.G_MISS_CHAR OR
4532           p_charges_detail_rec.pricing_attribute11             <> FND_API.G_MISS_CHAR OR
4533           p_charges_detail_rec.pricing_attribute12             <> FND_API.G_MISS_CHAR OR
4534           p_charges_detail_rec.pricing_attribute13             <> FND_API.G_MISS_CHAR OR
4535           p_charges_detail_rec.pricing_attribute14             <> FND_API.G_MISS_CHAR OR
4536           p_charges_detail_rec.pricing_attribute15             <> FND_API.G_MISS_CHAR OR
4537           p_charges_detail_rec.pricing_attribute16             <> FND_API.G_MISS_CHAR OR
4538           p_charges_detail_rec.pricing_attribute17             <> FND_API.G_MISS_CHAR OR
4539           p_charges_detail_rec.pricing_attribute18             <> FND_API.G_MISS_CHAR OR
4540           p_charges_detail_rec.pricing_attribute19             <> FND_API.G_MISS_CHAR OR
4541           p_charges_detail_rec.pricing_attribute20             <> FND_API.G_MISS_CHAR OR
4542           p_charges_detail_rec.pricing_attribute21             <> FND_API.G_MISS_CHAR OR
4543           p_charges_detail_rec.pricing_attribute22             <> FND_API.G_MISS_CHAR OR
4544           p_charges_detail_rec.pricing_attribute23             <> FND_API.G_MISS_CHAR OR
4545           p_charges_detail_rec.pricing_attribute24             <> FND_API.G_MISS_CHAR OR
4546           p_charges_detail_rec.pricing_attribute25             <> FND_API.G_MISS_CHAR OR
4547           p_charges_detail_rec.pricing_attribute26             <> FND_API.G_MISS_CHAR OR
4548           p_charges_detail_rec.pricing_attribute27             <> FND_API.G_MISS_CHAR OR
4549           p_charges_detail_rec.pricing_attribute28             <> FND_API.G_MISS_CHAR OR
4550           p_charges_detail_rec.pricing_attribute29             <> FND_API.G_MISS_CHAR OR
4551           p_charges_detail_rec.pricing_attribute30             <> FND_API.G_MISS_CHAR OR
4552           p_charges_detail_rec.pricing_attribute31             <> FND_API.G_MISS_CHAR OR
4553           p_charges_detail_rec.pricing_attribute32             <> FND_API.G_MISS_CHAR OR
4554           p_charges_detail_rec.pricing_attribute33             <> FND_API.G_MISS_CHAR OR
4555           p_charges_detail_rec.pricing_attribute34             <> FND_API.G_MISS_CHAR OR
4556           p_charges_detail_rec.pricing_attribute35             <> FND_API.G_MISS_CHAR OR
4557           p_charges_detail_rec.pricing_attribute36             <> FND_API.G_MISS_CHAR OR
4558           p_charges_detail_rec.pricing_attribute37             <> FND_API.G_MISS_CHAR OR
4559           p_charges_detail_rec.pricing_attribute38             <> FND_API.G_MISS_CHAR OR
4560           p_charges_detail_rec.pricing_attribute39             <> FND_API.G_MISS_CHAR OR
4561           p_charges_detail_rec.pricing_attribute40             <> FND_API.G_MISS_CHAR OR
4562           p_charges_detail_rec.pricing_attribute41             <> FND_API.G_MISS_CHAR OR
4563           p_charges_detail_rec.pricing_attribute42             <> FND_API.G_MISS_CHAR OR
4564           p_charges_detail_rec.pricing_attribute43             <> FND_API.G_MISS_CHAR OR
4565           p_charges_detail_rec.pricing_attribute44             <> FND_API.G_MISS_CHAR OR
4566           p_charges_detail_rec.pricing_attribute45             <> FND_API.G_MISS_CHAR OR
4567           p_charges_detail_rec.pricing_attribute46             <> FND_API.G_MISS_CHAR OR
4568           p_charges_detail_rec.pricing_attribute47             <> FND_API.G_MISS_CHAR OR
4569           p_charges_detail_rec.pricing_attribute48             <> FND_API.G_MISS_CHAR OR
4570           p_charges_detail_rec.pricing_attribute49             <> FND_API.G_MISS_CHAR OR
4571           p_charges_detail_rec.pricing_attribute50             <> FND_API.G_MISS_CHAR OR
4572           p_charges_detail_rec.pricing_attribute51             <> FND_API.G_MISS_CHAR OR
4573           p_charges_detail_rec.pricing_attribute52             <> FND_API.G_MISS_CHAR OR
4574           p_charges_detail_rec.pricing_attribute53             <> FND_API.G_MISS_CHAR OR
4575           p_charges_detail_rec.pricing_attribute54             <> FND_API.G_MISS_CHAR OR
4576           p_charges_detail_rec.pricing_attribute55             <> FND_API.G_MISS_CHAR OR
4577           p_charges_detail_rec.pricing_attribute56             <> FND_API.G_MISS_CHAR OR
4578           p_charges_detail_rec.pricing_attribute57             <> FND_API.G_MISS_CHAR OR
4579           p_charges_detail_rec.pricing_attribute58             <> FND_API.G_MISS_CHAR OR
4580           p_charges_detail_rec.pricing_attribute59             <> FND_API.G_MISS_CHAR OR
4581           p_charges_detail_rec.pricing_attribute60             <> FND_API.G_MISS_CHAR OR
4582           p_charges_detail_rec.pricing_attribute61             <> FND_API.G_MISS_CHAR OR
4583           p_charges_detail_rec.pricing_attribute62             <> FND_API.G_MISS_CHAR OR
4584           p_charges_detail_rec.pricing_attribute63             <> FND_API.G_MISS_CHAR OR
4585           p_charges_detail_rec.pricing_attribute64             <> FND_API.G_MISS_CHAR OR
4586           p_charges_detail_rec.pricing_attribute65             <> FND_API.G_MISS_CHAR OR
4587           p_charges_detail_rec.pricing_attribute66             <> FND_API.G_MISS_CHAR OR
4588           p_charges_detail_rec.pricing_attribute67             <> FND_API.G_MISS_CHAR OR
4589           p_charges_detail_rec.pricing_attribute68             <> FND_API.G_MISS_CHAR OR
4590           p_charges_detail_rec.pricing_attribute69             <> FND_API.G_MISS_CHAR OR
4591           p_charges_detail_rec.pricing_attribute70             <> FND_API.G_MISS_CHAR OR
4592           p_charges_detail_rec.pricing_attribute71             <> FND_API.G_MISS_CHAR OR
4593           p_charges_detail_rec.pricing_attribute72             <> FND_API.G_MISS_CHAR OR
4594           p_charges_detail_rec.pricing_attribute73             <> FND_API.G_MISS_CHAR OR
4595           p_charges_detail_rec.pricing_attribute74             <> FND_API.G_MISS_CHAR OR
4596           p_charges_detail_rec.pricing_attribute75             <> FND_API.G_MISS_CHAR OR
4597           p_charges_detail_rec.pricing_attribute76             <> FND_API.G_MISS_CHAR OR
4598           p_charges_detail_rec.pricing_attribute77             <> FND_API.G_MISS_CHAR OR
4599           p_charges_detail_rec.pricing_attribute78             <> FND_API.G_MISS_CHAR OR
4600           p_charges_detail_rec.pricing_attribute79             <> FND_API.G_MISS_CHAR OR
4601           p_charges_detail_rec.pricing_attribute80             <> FND_API.G_MISS_CHAR OR
4602           p_charges_detail_rec.pricing_attribute81             <> FND_API.G_MISS_CHAR OR
4603           p_charges_detail_rec.pricing_attribute82             <> FND_API.G_MISS_CHAR OR
4604           p_charges_detail_rec.pricing_attribute83             <> FND_API.G_MISS_CHAR OR
4605           p_charges_detail_rec.pricing_attribute84             <> FND_API.G_MISS_CHAR OR
4606           p_charges_detail_rec.pricing_attribute85             <> FND_API.G_MISS_CHAR OR
4607           p_charges_detail_rec.pricing_attribute86             <> FND_API.G_MISS_CHAR OR
4608           p_charges_detail_rec.pricing_attribute87             <> FND_API.G_MISS_CHAR OR
4609           p_charges_detail_rec.pricing_attribute88             <> FND_API.G_MISS_CHAR OR
4610           p_charges_detail_rec.pricing_attribute89             <> FND_API.G_MISS_CHAR OR
4611           p_charges_detail_rec.pricing_attribute90             <> FND_API.G_MISS_CHAR OR
4612           p_charges_detail_rec.pricing_attribute91             <> FND_API.G_MISS_CHAR OR
4613           p_charges_detail_rec.pricing_attribute92             <> FND_API.G_MISS_CHAR OR
4614           p_charges_detail_rec.pricing_attribute93             <> FND_API.G_MISS_CHAR OR
4615           p_charges_detail_rec.pricing_attribute94             <> FND_API.G_MISS_CHAR OR
4616           p_charges_detail_rec.pricing_attribute95             <> FND_API.G_MISS_CHAR OR
4617           p_charges_detail_rec.pricing_attribute96             <> FND_API.G_MISS_CHAR OR
4618           p_charges_detail_rec.pricing_attribute97             <> FND_API.G_MISS_CHAR OR
4619           p_charges_detail_rec.pricing_attribute98             <> FND_API.G_MISS_CHAR OR
4620           p_charges_detail_rec.pricing_attribute99             <> FND_API.G_MISS_CHAR OR
4621           p_charges_detail_rec.pricing_attribute100            <> FND_API.G_MISS_CHAR ) THEN
4622 
4623           FND_MESSAGE.Set_Name('CS', 'CS_CHG_CANNOT_UPDATE_CHRG_LINE');
4624           FND_MSG_PUB.Add;
4625           RAISE FND_API.G_EXC_ERROR;
4626       END IF;
4627    ELSE
4628      --l_in_oe_flag = 'N'
4629      --DBMS_OUTPUT.PUT_LINE('l_in_oe_flag is N ');
4630      null;
4631    END IF;
4632 
4633 
4634 
4635    -- Fixed Bug # 4395867
4636    -- If the original source is 'SR' and source is 'SD' then restrict the line from getting updated
4637    -- from Service Debrief
4638    --
4639 
4640    -- get the current_source for the update transaction
4641 
4642    IF p_charges_detail_rec.source_code IS NOT NULL AND
4643       p_charges_detail_rec.source_code <> FND_API.G_MISS_CHAR THEN
4644       l_source := p_charges_detail_rec.source_code;
4645    ELSE
4646       l_source := l_db_det_rec.source_code;
4647    END IF;
4648 
4649    -- get the original_source for the update transaction
4650       l_original_source := l_db_det_rec.original_source_code;
4651 
4652 
4653    IF l_db_det_rec.generated_by_bca_engine_flag = 'Y' AND
4654       l_original_source = 'SR' AND
4655       l_source = 'SD'  THEN
4656     -- cannot update any other field other than after_warranty_cost
4657         IF (p_charges_detail_rec.charge_line_type                <> FND_API.G_MISS_CHAR OR
4658             p_charges_detail_rec.line_number                     <> FND_API.G_MISS_NUM OR
4659             p_charges_detail_rec.business_process_id             <> FND_API.G_MISS_NUM  OR
4660             p_charges_detail_rec.transaction_type_id             <> FND_API.G_MISS_NUM  OR
4661             p_charges_detail_rec.inventory_item_id_in            <> FND_API.G_MISS_NUM  OR
4662             p_charges_detail_rec.item_revision                   <> FND_API.G_MISS_CHAR OR
4663             p_charges_detail_rec.billing_flag                    <> FND_API.G_MISS_CHAR OR
4664             p_charges_detail_rec.txn_billing_type_id             <> FND_API.G_MISS_NUM  OR
4665             p_charges_detail_rec.unit_of_measure_code            <> FND_API.G_MISS_CHAR OR
4666             p_charges_detail_rec.quantity_required               <> FND_API.G_MISS_NUM  OR
4667             p_charges_detail_rec.return_reason_code              <> FND_API.G_MISS_CHAR OR
4668             p_charges_detail_rec.customer_product_id             <> FND_API.G_MISS_NUM  OR
4669             p_charges_detail_rec.serial_number                   <> FND_API.G_MISS_CHAR OR
4670             p_charges_detail_rec.installed_cp_return_by_date     <> FND_API.G_MISS_DATE OR
4671             p_charges_detail_rec.new_cp_return_by_date           <> FND_API.G_MISS_DATE OR
4672             p_charges_detail_rec.sold_to_party_id                <> FND_API.G_MISS_NUM  OR
4673             p_charges_detail_rec.bill_to_party_id                <> FND_API.G_MISS_NUM  OR
4674             p_charges_detail_rec.bill_to_account_id              <> FND_API.G_MISS_NUM  OR
4675             p_charges_detail_rec.bill_to_contact_id              <> FND_API.G_MISS_NUM  OR
4676             p_charges_detail_rec.invoice_to_org_id               <> FND_API.G_MISS_NUM  OR
4677             p_charges_detail_rec.ship_to_party_id                <> FND_API.G_MISS_NUM  OR
4678             p_charges_detail_rec.ship_to_account_id              <> FND_API.G_MISS_NUM  OR
4679             p_charges_detail_rec.ship_to_contact_id              <> FND_API.G_MISS_NUM  OR
4680             p_charges_detail_rec.ship_to_org_id                  <> FND_API.G_MISS_NUM  OR
4681             p_charges_detail_rec.contract_id                     <> FND_API.G_MISS_NUM  OR
4682             p_charges_detail_rec.coverage_id                     <> FND_API.G_MISS_NUM  OR
4683             p_charges_detail_rec.coverage_txn_group_id           <> FND_API.G_MISS_NUM  OR
4684             p_charges_detail_rec.coverage_bill_rate_id           <> FND_API.G_MISS_NUM  OR
4685             p_charges_detail_rec.coverage_billing_type_id        <> FND_API.G_MISS_NUM  OR
4686             p_charges_detail_rec.price_list_id                   <> FND_API.G_MISS_NUM  OR
4687             p_charges_detail_rec.currency_code                   <> FND_API.G_MISS_CHAR OR
4688             p_charges_detail_rec.purchase_order_num              <> FND_API.G_MISS_CHAR OR
4689             p_charges_detail_rec.list_price                      <> FND_API.G_MISS_NUM  OR
4690             p_charges_detail_rec.con_pct_over_list_price         <> FND_API.G_MISS_NUM  OR
4691             p_charges_detail_rec.selling_price                   <> FND_API.G_MISS_NUM  OR
4692             p_charges_detail_rec.contract_discount_amount        <> FND_API.G_MISS_NUM  OR
4693             p_charges_detail_rec.apply_contract_discount         <> FND_API.G_MISS_CHAR OR
4694             p_charges_detail_rec.transaction_inventory_org       <> FND_API.G_MISS_NUM OR
4695             p_charges_detail_rec.transaction_sub_inventory       <> FND_API.G_MISS_CHAR OR
4696             p_charges_detail_rec.rollup_flag                     <> FND_API.G_MISS_CHAR OR
4697             p_charges_detail_rec.add_to_order_flag               <> FND_API.G_MISS_CHAR OR
4698             p_charges_detail_rec.order_header_id                 <> FND_API.G_MISS_NUM  OR
4699             p_charges_detail_rec.interface_to_oe_flag            <> FND_API.G_MISS_CHAR OR
4700             p_charges_detail_rec.no_charge_flag                  <> FND_API.G_MISS_CHAR OR
4701             p_charges_detail_rec.line_category_code              <> FND_API.G_MISS_CHAR OR
4702             p_charges_detail_rec.line_type_id                    <> FND_API.G_MISS_NUM  OR
4703             p_charges_detail_rec.order_line_id                   <> FND_API.G_MISS_NUM  OR
4704             p_charges_detail_rec.conversion_rate                 <> FND_API.G_MISS_NUM  OR
4705             p_charges_detail_rec.conversion_type_code            <> FND_API.G_MISS_CHAR OR
4706             p_charges_detail_rec.conversion_rate_date            <> FND_API.G_MISS_DATE OR
4707             p_charges_detail_rec.original_source_id              <> FND_API.G_MISS_NUM  OR
4708             p_charges_detail_rec.original_source_code            <> FND_API.G_MISS_CHAR OR
4709             p_charges_detail_rec.org_id                          <> FND_API.G_MISS_NUM  OR
4710             p_charges_detail_rec.activity_start_time             <> FND_API.G_MISS_DATE OR
4711             p_charges_detail_rec.activity_end_time               <> FND_API.G_MISS_DATE OR
4712             p_charges_detail_rec.generated_by_bca_engine         <> FND_API.G_MISS_CHAR OR
4713             p_charges_detail_rec.submit_restriction_message      <> FND_API.G_MISS_CHAR OR
4714             p_charges_detail_rec.submit_error_message            <> FND_API.G_MISS_CHAR OR
4715             p_charges_detail_rec.submit_from_system              <> FND_API.G_MISS_CHAR OR
4716             p_charges_detail_rec.attribute1                      <> FND_API.G_MISS_CHAR OR
4717             p_charges_detail_rec.attribute2                      <> FND_API.G_MISS_CHAR OR
4718             p_charges_detail_rec.attribute3                      <> FND_API.G_MISS_CHAR OR
4719             p_charges_detail_rec.attribute4                      <> FND_API.G_MISS_CHAR OR
4720             p_charges_detail_rec.attribute5                      <> FND_API.G_MISS_CHAR OR
4721             p_charges_detail_rec.attribute6                      <> FND_API.G_MISS_CHAR OR
4722             p_charges_detail_rec.attribute7                      <> FND_API.G_MISS_CHAR OR
4723             p_charges_detail_rec.attribute8                      <> FND_API.G_MISS_CHAR OR
4724             p_charges_detail_rec.attribute9                      <> FND_API.G_MISS_CHAR OR
4725             p_charges_detail_rec.attribute10                     <> FND_API.G_MISS_CHAR OR
4726             p_charges_detail_rec.attribute11                     <> FND_API.G_MISS_CHAR OR
4727             p_charges_detail_rec.attribute12                     <> FND_API.G_MISS_CHAR OR
4728             p_charges_detail_rec.attribute13                     <> FND_API.G_MISS_CHAR OR
4729             p_charges_detail_rec.attribute14                     <> FND_API.G_MISS_CHAR OR
4730             p_charges_detail_rec.attribute15                     <> FND_API.G_MISS_CHAR OR
4731             p_charges_detail_rec.context                         <> FND_API.G_MISS_CHAR OR
4732             p_charges_detail_rec.pricing_context                 <> FND_API.G_MISS_CHAR OR
4733             p_charges_detail_rec.pricing_attribute1              <> FND_API.G_MISS_CHAR OR
4734             p_charges_detail_rec.pricing_attribute2              <> FND_API.G_MISS_CHAR OR
4735             p_charges_detail_rec.pricing_attribute3              <> FND_API.G_MISS_CHAR OR
4736             p_charges_detail_rec.pricing_attribute4              <> FND_API.G_MISS_CHAR OR
4737             p_charges_detail_rec.pricing_attribute5              <> FND_API.G_MISS_CHAR OR
4738             p_charges_detail_rec.pricing_attribute6              <> FND_API.G_MISS_CHAR OR
4739             p_charges_detail_rec.pricing_attribute7              <> FND_API.G_MISS_CHAR OR
4740             p_charges_detail_rec.pricing_attribute8              <> FND_API.G_MISS_CHAR OR
4741             p_charges_detail_rec.pricing_attribute9              <> FND_API.G_MISS_CHAR OR
4742             p_charges_detail_rec.pricing_attribute10             <> FND_API.G_MISS_CHAR OR
4743             p_charges_detail_rec.pricing_attribute11             <> FND_API.G_MISS_CHAR OR
4744             p_charges_detail_rec.pricing_attribute12             <> FND_API.G_MISS_CHAR OR
4745             p_charges_detail_rec.pricing_attribute13             <> FND_API.G_MISS_CHAR OR
4746             p_charges_detail_rec.pricing_attribute14             <> FND_API.G_MISS_CHAR OR
4747             p_charges_detail_rec.pricing_attribute15             <> FND_API.G_MISS_CHAR OR
4748             p_charges_detail_rec.pricing_attribute16             <> FND_API.G_MISS_CHAR OR
4749             p_charges_detail_rec.pricing_attribute17             <> FND_API.G_MISS_CHAR OR
4750             p_charges_detail_rec.pricing_attribute18             <> FND_API.G_MISS_CHAR OR
4751             p_charges_detail_rec.pricing_attribute19             <> FND_API.G_MISS_CHAR OR
4752             p_charges_detail_rec.pricing_attribute20             <> FND_API.G_MISS_CHAR OR
4753             p_charges_detail_rec.pricing_attribute21             <> FND_API.G_MISS_CHAR OR
4754             p_charges_detail_rec.pricing_attribute22             <> FND_API.G_MISS_CHAR OR
4755             p_charges_detail_rec.pricing_attribute23             <> FND_API.G_MISS_CHAR OR
4756             p_charges_detail_rec.pricing_attribute24             <> FND_API.G_MISS_CHAR OR
4757             p_charges_detail_rec.pricing_attribute25             <> FND_API.G_MISS_CHAR OR
4758             p_charges_detail_rec.pricing_attribute26             <> FND_API.G_MISS_CHAR OR
4759             p_charges_detail_rec.pricing_attribute27             <> FND_API.G_MISS_CHAR OR
4760             p_charges_detail_rec.pricing_attribute28             <> FND_API.G_MISS_CHAR OR
4761             p_charges_detail_rec.pricing_attribute29             <> FND_API.G_MISS_CHAR OR
4762             p_charges_detail_rec.pricing_attribute30             <> FND_API.G_MISS_CHAR OR
4763             p_charges_detail_rec.pricing_attribute31             <> FND_API.G_MISS_CHAR OR
4764             p_charges_detail_rec.pricing_attribute32             <> FND_API.G_MISS_CHAR OR
4765             p_charges_detail_rec.pricing_attribute33             <> FND_API.G_MISS_CHAR OR
4766             p_charges_detail_rec.pricing_attribute34             <> FND_API.G_MISS_CHAR OR
4767             p_charges_detail_rec.pricing_attribute35             <> FND_API.G_MISS_CHAR OR
4768             p_charges_detail_rec.pricing_attribute36             <> FND_API.G_MISS_CHAR OR
4769             p_charges_detail_rec.pricing_attribute37             <> FND_API.G_MISS_CHAR OR
4770             p_charges_detail_rec.pricing_attribute38             <> FND_API.G_MISS_CHAR OR
4771             p_charges_detail_rec.pricing_attribute39             <> FND_API.G_MISS_CHAR OR
4772             p_charges_detail_rec.pricing_attribute40             <> FND_API.G_MISS_CHAR OR
4773             p_charges_detail_rec.pricing_attribute41             <> FND_API.G_MISS_CHAR OR
4774             p_charges_detail_rec.pricing_attribute42             <> FND_API.G_MISS_CHAR OR
4775             p_charges_detail_rec.pricing_attribute43             <> FND_API.G_MISS_CHAR OR
4776             p_charges_detail_rec.pricing_attribute44             <> FND_API.G_MISS_CHAR OR
4777             p_charges_detail_rec.pricing_attribute45             <> FND_API.G_MISS_CHAR OR
4778             p_charges_detail_rec.pricing_attribute46             <> FND_API.G_MISS_CHAR OR
4779             p_charges_detail_rec.pricing_attribute47             <> FND_API.G_MISS_CHAR OR
4780             p_charges_detail_rec.pricing_attribute48             <> FND_API.G_MISS_CHAR OR
4781             p_charges_detail_rec.pricing_attribute49             <> FND_API.G_MISS_CHAR OR
4782             p_charges_detail_rec.pricing_attribute50             <> FND_API.G_MISS_CHAR OR
4783             p_charges_detail_rec.pricing_attribute51             <> FND_API.G_MISS_CHAR OR
4784             p_charges_detail_rec.pricing_attribute52             <> FND_API.G_MISS_CHAR OR
4785             p_charges_detail_rec.pricing_attribute53             <> FND_API.G_MISS_CHAR OR
4786             p_charges_detail_rec.pricing_attribute54             <> FND_API.G_MISS_CHAR OR
4787             p_charges_detail_rec.pricing_attribute55             <> FND_API.G_MISS_CHAR OR
4788             p_charges_detail_rec.pricing_attribute56             <> FND_API.G_MISS_CHAR OR
4789             p_charges_detail_rec.pricing_attribute57             <> FND_API.G_MISS_CHAR OR
4790             p_charges_detail_rec.pricing_attribute58             <> FND_API.G_MISS_CHAR OR
4791             p_charges_detail_rec.pricing_attribute59             <> FND_API.G_MISS_CHAR OR
4792             p_charges_detail_rec.pricing_attribute60             <> FND_API.G_MISS_CHAR OR
4793             p_charges_detail_rec.pricing_attribute61             <> FND_API.G_MISS_CHAR OR
4794             p_charges_detail_rec.pricing_attribute62             <> FND_API.G_MISS_CHAR OR
4795             p_charges_detail_rec.pricing_attribute63             <> FND_API.G_MISS_CHAR OR
4796             p_charges_detail_rec.pricing_attribute64             <> FND_API.G_MISS_CHAR OR
4797             p_charges_detail_rec.pricing_attribute65             <> FND_API.G_MISS_CHAR OR
4798             p_charges_detail_rec.pricing_attribute66             <> FND_API.G_MISS_CHAR OR
4799             p_charges_detail_rec.pricing_attribute67             <> FND_API.G_MISS_CHAR OR
4800             p_charges_detail_rec.pricing_attribute68             <> FND_API.G_MISS_CHAR OR
4801             p_charges_detail_rec.pricing_attribute69             <> FND_API.G_MISS_CHAR OR
4802             p_charges_detail_rec.pricing_attribute70             <> FND_API.G_MISS_CHAR OR
4803             p_charges_detail_rec.pricing_attribute71             <> FND_API.G_MISS_CHAR OR
4804             p_charges_detail_rec.pricing_attribute72             <> FND_API.G_MISS_CHAR OR
4805             p_charges_detail_rec.pricing_attribute73             <> FND_API.G_MISS_CHAR OR
4806             p_charges_detail_rec.pricing_attribute74             <> FND_API.G_MISS_CHAR OR
4807             p_charges_detail_rec.pricing_attribute75             <> FND_API.G_MISS_CHAR OR
4808             p_charges_detail_rec.pricing_attribute76             <> FND_API.G_MISS_CHAR OR
4809             p_charges_detail_rec.pricing_attribute77             <> FND_API.G_MISS_CHAR OR
4810             p_charges_detail_rec.pricing_attribute78             <> FND_API.G_MISS_CHAR OR
4811             p_charges_detail_rec.pricing_attribute79             <> FND_API.G_MISS_CHAR OR
4812             p_charges_detail_rec.pricing_attribute80             <> FND_API.G_MISS_CHAR OR
4813             p_charges_detail_rec.pricing_attribute81             <> FND_API.G_MISS_CHAR OR
4814             p_charges_detail_rec.pricing_attribute82             <> FND_API.G_MISS_CHAR OR
4815             p_charges_detail_rec.pricing_attribute83             <> FND_API.G_MISS_CHAR OR
4816             p_charges_detail_rec.pricing_attribute84             <> FND_API.G_MISS_CHAR OR
4817             p_charges_detail_rec.pricing_attribute85             <> FND_API.G_MISS_CHAR OR
4818             p_charges_detail_rec.pricing_attribute86             <> FND_API.G_MISS_CHAR OR
4819             p_charges_detail_rec.pricing_attribute87             <> FND_API.G_MISS_CHAR OR
4820             p_charges_detail_rec.pricing_attribute88             <> FND_API.G_MISS_CHAR OR
4821             p_charges_detail_rec.pricing_attribute89             <> FND_API.G_MISS_CHAR OR
4822             p_charges_detail_rec.pricing_attribute90             <> FND_API.G_MISS_CHAR OR
4823             p_charges_detail_rec.pricing_attribute91             <> FND_API.G_MISS_CHAR OR
4824             p_charges_detail_rec.pricing_attribute92             <> FND_API.G_MISS_CHAR OR
4825             p_charges_detail_rec.pricing_attribute93             <> FND_API.G_MISS_CHAR OR
4826             p_charges_detail_rec.pricing_attribute94             <> FND_API.G_MISS_CHAR OR
4827             p_charges_detail_rec.pricing_attribute95             <> FND_API.G_MISS_CHAR OR
4828             p_charges_detail_rec.pricing_attribute96             <> FND_API.G_MISS_CHAR OR
4829             p_charges_detail_rec.pricing_attribute97             <> FND_API.G_MISS_CHAR OR
4830             p_charges_detail_rec.pricing_attribute98             <> FND_API.G_MISS_CHAR OR
4831             p_charges_detail_rec.pricing_attribute99             <> FND_API.G_MISS_CHAR OR
4832             p_charges_detail_rec.pricing_attribute100            <> FND_API.G_MISS_CHAR )  THEN
4833 
4834          --RAISE FND_API.G_EXC_ERROR;
4835          --null;
4836          FND_MESSAGE.Set_Name('CS', 'CS_CHG_CANNOT_UPDATE_CHRG_LINE');
4837          FND_MSG_PUB.Add;
4838          RAISE FND_API.G_EXC_ERROR;
4839      END IF;
4840 
4841      -- If generated by BCA Engine then cannot update anything except the final amount
4842      -- need to find out from Iwen the exact requirements
4843 
4844    END IF;
4845   END IF;
4846 
4847      --DBMS_OUTPUT.PUT_LINE('Passed the Update Validation for BCA and Order Line');
4848 --======================================
4849 -- For Update Only
4850 -- Check for Item Instance and Rollup Flag
4851 -- from values in Database
4852 --======================================
4853 IF p_validation_mode = 'U' THEN
4854   IF l_db_det_rec.rollup_flag = 'Y' THEN
4855     l_rollup_flag := 'Y';
4856   END IF;
4857 END IF;
4858 
4859 --===========================
4860 --Charge Line Type Validation
4861 --===========================
4862 --DBMS_OUTPUT.PUT_LINE('Charge Line Type Validation ...');
4863 
4864   IF p_validation_mode = 'I' THEN
4865 
4866     IF p_charges_detail_rec.charge_line_type IS NOT NULL THEN
4867 
4868       l_valid_check := IS_CHARGE_LINE_TYPE_VALID(p_charge_line_type => p_charges_detail_rec.charge_line_type,
4869                                    x_msg_data         => l_msg_data,
4870                                    x_msg_count        => l_msg_count,
4871                                    x_return_status    => l_return_status);
4872 
4873       IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
4874         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4875       ELSIF l_return_status = G_RET_STS_ERROR THEN
4876         RAISE FND_API.G_EXC_ERROR;
4877       END IF;
4878 
4879       IF l_valid_check <> 'Y' THEN
4880 
4881         Add_Invalid_Argument_Msg(l_api_name,
4882                                  p_charges_detail_rec.charge_line_type,
4883                                  'charge_line_type');
4884 
4885         RAISE FND_API.G_EXC_ERROR;
4886       ELSE
4887         x_charges_detail_rec.charge_line_type :=  p_charges_detail_rec.charge_line_type;
4888       END IF;
4889 
4890 
4891     ELSE
4892       x_charges_detail_rec.charge_line_type := 'ACTUAL';
4893     END IF;
4894 
4895   ELSIF p_validation_mode = 'U' THEN
4896 
4897     --Resolve Bug # 3078244
4898 
4899     IF p_charges_detail_rec.charge_line_type  <> FND_API.G_MISS_CHAR AND
4900        p_charges_detail_rec.charge_line_type IS NOT NULL THEN
4901 
4902       IF l_db_det_rec.charge_line_type <> 'IN PROGRESS' THEN
4903 
4904         l_valid_check := IS_CHARGE_LINE_TYPE_VALID(p_charge_line_type => p_charges_detail_rec.charge_line_type,
4905                                      x_msg_data         => l_msg_data,
4906                                      x_msg_count        => l_msg_count,
4907                                      x_return_status    => l_return_status);
4908 
4909         IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
4910           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4911         ELSIF l_return_status = G_RET_STS_ERROR THEN
4912           RAISE FND_API.G_EXC_ERROR;
4913         END IF;
4914 
4915         IF l_valid_check <> 'Y' THEN
4916 
4917           Add_Invalid_Argument_Msg(l_api_name,
4918                                    p_charges_detail_rec.charge_line_type,
4919                                    'charge_line_type');
4920 
4921           RAISE FND_API.G_EXC_ERROR;
4922         ELSE
4923           x_charges_detail_rec.charge_line_type :=  p_charges_detail_rec.charge_line_type;
4924         END IF;
4925 
4926       ELSE
4927        -- give an error message
4928        FND_MESSAGE.SET_NAME('CS', 'CS_CHG_CANNOT_UPDATE_INPROG');
4929        FND_MESSAGE.SET_TOKEN('API_NAME', p_api_name);
4930        FND_MSG_PUB.ADD;
4931        RAISE FND_API.G_EXC_ERROR;
4932       END IF;
4933    ELSE
4934     --get it from the db record
4935     x_charges_detail_rec.charge_line_type := l_db_det_rec.charge_line_type;
4936 
4937     IF x_charges_detail_rec.charge_line_type = 'IN PROGRESS' THEN
4938       FND_MESSAGE.SET_NAME('CS', 'CS_CHG_CANNOT_UPDATE_INPROG');
4939       FND_MESSAGE.SET_TOKEN('API_NAME', p_api_name);
4940       FND_MSG_PUB.ADD;
4941       RAISE FND_API.G_EXC_ERROR;
4942     END IF;
4943    END IF;
4944 
4945    --DBMS_OUTPUT.PUT_LINE('passed charge_line_type validation in update');
4946   END IF;
4947 
4948  --=============================
4949  --Line submitted validate
4950  --=============================
4951 
4952  IF p_validation_mode = 'I' THEN
4953 
4954    IF  x_charges_detail_rec.charge_line_type IN ('ESTIMATE', 'IN_PROGRESS') THEN
4955      x_charges_detail_rec.line_submitted_flag := NULL;
4956    ELSE
4957      IF x_charges_detail_rec.charge_line_type = 'ACTUAL' THEN
4958       x_charges_detail_rec.line_submitted_flag := 'N';
4959      END IF;
4960    END IF;
4961  ELSIF p_validation_mode = 'U' THEN
4962    --Fixed Bug # 3353497
4963    IF x_charges_detail_rec.order_line_id IS NULL AND
4964       x_charges_detail_rec.charge_line_type = 'ACTUAL' THEN
4965       x_charges_detail_rec.line_submitted_flag := 'N';
4966    ELSE
4967       --in all other situations  l_line_submitted_flag := NULL;
4968       x_charges_detail_rec.line_submitted_flag := NULL;
4969    END IF;
4970  END IF;
4971 
4972 
4973 
4974  --==============================
4975  --Business Process ID Validation
4976  --==============================
4977   --DBMS_OUTPUT.PUT_LINE('Business Process ID Validation ...');
4978 
4979   IF p_validation_mode = 'I' THEN
4980 
4981     IF p_charges_detail_rec.business_process_id IS NOT NULL THEN
4982 
4983       l_valid_check := IS_BUSINESS_PROCESS_ID_VALID(
4984                                       p_business_process_id => p_charges_detail_rec.business_process_id,
4985                                       x_msg_data            => l_msg_data,
4986                                       x_msg_count           => l_msg_count,
4987                                       x_return_status       => l_return_status);
4988 
4989       IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
4990         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4991       ELSIF l_return_status = G_RET_STS_ERROR THEN
4992         RAISE FND_API.G_EXC_ERROR;
4993       END IF;
4994 
4995       IF l_valid_check <> 'Y' THEN
4996 
4997         Add_Invalid_Argument_Msg(l_api_name,
4998                                  to_char(p_charges_detail_rec.business_process_id),
4999                                  'business_process_id');
5000         RAISE FND_API.G_EXC_ERROR;
5001       ELSE
5002         x_charges_detail_rec.business_process_id := p_charges_detail_rec.business_process_id;
5003       END IF;
5004 
5005     ELSE
5006       -- Business Process Id is null
5007       -- Get the Business Process Id from Service Request
5008       -- Check if the profile to get Business Process From SR = 'Y'
5009       l_def_bp_from_sr := fnd_profile.value('CS_CHG_DEFAULT_BP_FROM_SR');
5010 
5011       IF FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level
5012       THEN
5013 	FND_LOG.String
5014 	( FND_LOG.level_procedure , L_LOG_MODULE || ''
5015 	, 'The Value of profile CS_CHG_DEFAULT_BP_FROM_SR :' || l_def_bp_from_sr
5016 	);
5017       END IF;
5018 
5019       IF l_def_bp_from_sr = 'Y' THEN
5020         -- assign the business process id returned from GET_SR_DEFAULTS
5021         -- assign to out record
5022         IF l_business_process_id IS NOT NULL THEN
5023           x_charges_detail_rec.business_process_id := l_business_process_id;
5024         ELSE
5025           -- Raise Error
5026           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_BUSS_PROCESS_ID');
5027           FND_MESSAGE.SET_TOKEN('BUSINESS_PROCESS_ID', l_business_process_id);
5028           FND_MSG_PUB.ADD;
5029           RAISE FND_API.G_EXC_ERROR;
5030         END IF;
5031       ELSE
5032         -- Profile to get Business Process From SR = 'N'
5033         -- Raise error the Business Process ID IS Null and needed
5034         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_BUSS_PROCESS_ID');
5035         FND_MESSAGE.SET_TOKEN('BUSINESS_PROCESS_ID', p_charges_detail_rec.business_process_id);
5036         FND_MSG_PUB.ADD;
5037         RAISE FND_API.G_EXC_ERROR;
5038       END IF;
5039     END IF;
5040 
5041   ELSIF p_validation_mode = 'U' THEN
5042 
5043     -- In this API the Business Process can be updated
5044     -- If the Business process is passed and valid it will be updated
5045     -- else the value from db will be used
5046     --Resolve Bug # 3078244
5047 
5048     --Check to see if the upstream is passed a new business_process_id
5049     --If passed then validate the new business_process_id
5050     --If valid then assign to out parameters
5051     --Check too see if business_process_id is changed
5052     --If business_process_id is not passed assign the one in the database
5053 
5054     IF p_charges_detail_rec.business_process_id <> FND_API.G_MISS_NUM AND
5055        p_charges_detail_rec.business_process_id IS NOT NULL THEN
5056 
5057        l_valid_check := IS_BUSINESS_PROCESS_ID_VALID(
5058                                       p_business_process_id => p_charges_detail_rec.business_process_id,
5059                                       x_msg_data            => l_msg_data,
5060                                       x_msg_count           => l_msg_count,
5061                                       x_return_status       => l_return_status);
5062 
5063       IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
5064         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5065       ELSIF l_return_status = G_RET_STS_ERROR THEN
5066         RAISE FND_API.G_EXC_ERROR;
5067       END IF;
5068 
5069       IF l_valid_check <> 'Y' THEN
5070 
5071         Add_Invalid_Argument_Msg(l_api_name,
5072                                  to_char(p_charges_detail_rec.business_process_id),
5073                                  'business_process_id');
5074         RAISE FND_API.G_EXC_ERROR;
5075       ELSE
5076         x_charges_detail_rec.business_process_id := p_charges_detail_rec.business_process_id;
5077 
5078         IF p_charges_detail_rec.business_process_id <> l_db_det_rec.business_process_id THEN
5079           l_bp_changed := 'Y';
5080         END IF;
5081 
5082       END IF;
5083    ELSE
5084      -- p_charges_detail_rec.business_process_id is not passed
5085      -- use the business_process_id from the db
5086      x_charges_detail_rec.business_process_id := l_db_det_rec.business_process_id;
5087    END IF;
5088 
5089    --DBMS_OUTPUT.PUT_LINE('passed business process validation in update');
5090 
5091  END IF;
5092 
5093  --==============================
5094  --Transaction Type ID Validation
5095  --=============================
5096   --DBMS_OUTPUT.PUT_LINE('Transaction Type ID Validation ...');
5097   --DBMS_OUTPUT.PUT_LINE('p_validation_mode'|| p_validation_mode);
5098 
5099   IF p_validation_mode = 'I' THEN
5100 
5101     IF p_charges_detail_rec.transaction_type_id IS NULL THEN
5102 
5103       Add_Null_Parameter_Msg(l_api_name, 'transaction_type_id');
5104       Add_Invalid_Argument_Msg(l_api_name, to_char(p_charges_detail_rec.inventory_item_id_in), 'transaction_type_id');
5105       RAISE FND_API.G_EXC_ERROR;
5106 
5107     ELSE -- transaction_type_id is not null;
5108 
5109 --Added by bkanimoz on 15-dec-2007
5110  --start
5111 
5112 --check if the 'create_charge_flag' is 'Y' for the transaction type
5113 
5114     get_charge_flag_from_sac(p_api_name               => p_api_name,
5115                              p_txn_type_id            => p_charges_detail_rec.transaction_type_id,
5116 			     x_create_charge_flag     => l_create_charge_flag,
5117 			     x_msg_data               => l_msg_data,
5118 		             x_msg_count              => l_msg_count,
5119                              x_return_status          => l_return_status
5120 			    );
5121 
5122    IF l_create_charge_flag   = 'N' THEN
5123      --DBMS_OUTPUT.PUT_LINE('l_disallow_new_charge is '||l_disallow_new_charge);
5124      --raise error
5125      FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_CHARGE_FLAG');
5126      FND_MSG_PUB.ADD;
5127      RAISE FND_API.G_EXC_ERROR;
5128    END IF;
5129 
5130 -- end
5131 
5132 
5133       --DBMS_OUTPUT.PUT_LINE('Calling VALIDATE_TXN_TYPE');
5134       -- Call Validate Transaction Type Procedure
5135       VALIDATE_TXN_TYPE(P_API_NAME                  => p_api_name,
5136                         P_BUSINESS_PROCESS_ID       => p_charges_detail_rec.business_process_id,
5137                         P_TXN_TYPE_ID               => p_charges_detail_rec.transaction_type_id,
5138                         P_SOURCE_CODE               => x_charges_detail_rec.source_code,
5139                         X_LINE_ORDER_CATEGORY_CODE  => l_line_order_category_code,
5140                         X_NO_CHARGE_FLAG            => l_no_charge_flag ,
5141                         X_INTERFACE_TO_OE_FLAG      => l_interface_to_oe_flag,
5142                         X_UPDATE_IB_FLAG            => l_update_ib_flag,
5143                         X_SRC_REFERENCE_REQD_FLAG   => l_src_reference_reqd_flag,
5144                         X_SRC_RETURN_REQD_FLAG      => l_src_return_reqd_flag,
5145                         X_NON_SRC_REFERENCE_REQD    => l_non_src_reference_reqd_flag ,
5146                         X_NON_SRC_RETURN_REQD       => l_non_src_return_reqd,
5147                         x_MSG_DATA                  => x_msg_data,
5148                         x_MSG_COUNT                 => x_msg_count,
5149                         X_RETURN_STATUS             => l_return_status );
5150 
5151 
5152 
5153       IF l_return_status = FND_API.G_RET_STS_ERROR THEN
5154        RAISE FND_API.G_EXC_ERROR;
5155       ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5156         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5157       ELSE
5158         x_charges_detail_rec.transaction_type_id := p_charges_detail_rec.transaction_type_id;
5159       END IF ;
5160     END IF;
5161 
5162   ELSIF p_validation_mode = 'U' THEN
5163 
5164     --DBMS_OUTPUT.PUT_LINE('l_bp_changed '||l_bp_changed);
5165 
5166      --Resolve Bug # 3078244
5167 
5168     IF l_bp_changed = 'Y' THEN
5169 
5170       --DBMS_OUTPUT.PUT_LINE(' p_charges_detail_rec.transaction_type_id '||p_charges_detail_rec.transaction_type_id);
5171 
5172       --Check to see if the
5173 
5174       IF p_charges_detail_rec.transaction_type_id <> FND_API.G_MISS_NUM AND
5175          p_charges_detail_rec.transaction_type_id IS NOT NULL THEN
5176 
5177         --DBMS_OUTPUT.PUT_LINE('Transaction Type Passed BP Changed');
5178 
5179         VALIDATE_TXN_TYPE(P_API_NAME                  => p_api_name,
5180                           P_BUSINESS_PROCESS_ID       => x_charges_detail_rec.business_process_id,
5181                           P_TXN_TYPE_ID               => p_charges_detail_rec.transaction_type_id,
5182                           P_SOURCE_CODE               => x_charges_detail_rec.source_code,
5183                           X_LINE_ORDER_CATEGORY_CODE  => l_line_order_category_code,
5184                           X_NO_CHARGE_FLAG            => l_no_charge_flag ,
5185                           X_INTERFACE_TO_OE_FLAG      => l_interface_to_oe_flag,
5186                           X_UPDATE_IB_FLAG            => l_update_ib_flag,
5187                           X_SRC_REFERENCE_REQD_FLAG   => l_src_reference_reqd_flag,
5188                           X_SRC_RETURN_REQD_FLAG      => l_src_return_reqd_flag,
5189                           X_NON_SRC_REFERENCE_REQD    => l_non_src_reference_reqd_flag ,
5190                           X_NON_SRC_RETURN_REQD       => l_non_src_return_reqd,
5191                           X_MSG_DATA                  => l_msg_data,
5192                           X_MSG_COUNT                 => l_msg_count,
5193                           X_RETURN_STATUS             => l_return_status );
5194 
5195         IF l_return_status = FND_API.G_RET_STS_ERROR THEN
5196           RAISE FND_API.G_EXC_ERROR;
5197         ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5198           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5199         ELSE
5200           x_charges_detail_rec.transaction_type_id := p_charges_detail_rec.transaction_type_id;
5201           l_transaction_type_changed := 'Y';
5202         END IF ;
5203 
5204       ELSE
5205 
5206         --DBMS_OUTPUT.PUT_LINE('Transaction Type Not Passed BP Changed');
5207         -- p_charges_detail_rec.transaction_type_id is not passed
5208         -- validate the one from database against the business process changed
5209         VALIDATE_TXN_TYPE(P_API_NAME                  => p_api_name,
5210                           P_BUSINESS_PROCESS_ID       => x_charges_detail_rec.business_process_id,
5211                           P_TXN_TYPE_ID               => l_db_det_rec.transaction_type_id,
5212                           P_SOURCE_CODE               => x_charges_detail_rec.source_code,
5213                           X_LINE_ORDER_CATEGORY_CODE  => l_line_order_category_code,
5214                           X_NO_CHARGE_FLAG            => l_no_charge_flag ,
5215                           X_INTERFACE_TO_OE_FLAG      => l_interface_to_oe_flag,
5216                           X_UPDATE_IB_FLAG            => l_update_ib_flag,
5217                           X_SRC_REFERENCE_REQD_FLAG   => l_src_reference_reqd_flag,
5218                           X_SRC_RETURN_REQD_FLAG      => l_src_return_reqd_flag,
5219                           X_NON_SRC_REFERENCE_REQD    => l_non_src_reference_reqd_flag ,
5220                           X_NON_SRC_RETURN_REQD       => l_non_src_return_reqd,
5221                           X_MSG_DATA                  => l_msg_data,
5222                           X_MSG_COUNT                 => l_msg_count,
5223                           X_RETURN_STATUS             => l_return_status );
5224 
5225         IF l_return_status = FND_API.G_RET_STS_ERROR THEN
5226           RAISE FND_API.G_EXC_ERROR;
5227         ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5228           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5229         ELSE
5230           x_charges_detail_rec.transaction_type_id := l_db_det_rec.transaction_type_id;
5231           l_transaction_type_changed := 'N';
5232         END IF ;
5233       END IF;
5234     ELSE
5235       -- l_bp_changed = 'N'
5236       -- p_charges_detail_rec.transaction_type_id is NOT NULL
5237       --DBMS_OUTPUT.PUT_LINE('l_bp_changed = N');
5238 
5239 
5240       IF p_charges_detail_rec.transaction_type_id <> FND_API.G_MISS_NUM AND
5241          p_charges_detail_rec.transaction_type_id IS NOT NULL THEN
5242 
5243         --DBMS_OUTPUT.PUT_LINE('Transaction Type Passed BP  not Changed');
5244         VALIDATE_TXN_TYPE(P_API_NAME                  => p_api_name,
5245                           P_BUSINESS_PROCESS_ID       => x_charges_detail_rec.business_process_id,
5246                           P_TXN_TYPE_ID               => p_charges_detail_rec.transaction_type_id,
5247                           P_SOURCE_CODE               => x_charges_detail_rec.source_code,
5248                           X_LINE_ORDER_CATEGORY_CODE  => l_line_order_category_code,
5249                           X_NO_CHARGE_FLAG            => l_no_charge_flag ,
5250                           X_INTERFACE_TO_OE_FLAG      => l_interface_to_oe_flag,
5251                           X_UPDATE_IB_FLAG            => l_update_ib_flag,
5252                           X_SRC_REFERENCE_REQD_FLAG   => l_src_reference_reqd_flag,
5253                           X_SRC_RETURN_REQD_FLAG      => l_src_return_reqd_flag,
5254                           X_NON_SRC_REFERENCE_REQD    => l_non_src_reference_reqd_flag ,
5255                           X_NON_SRC_RETURN_REQD       => l_non_src_return_reqd,
5256                           X_MSG_DATA                  => l_msg_data,
5257                           X_MSG_COUNT                 => l_msg_count,
5258                           X_RETURN_STATUS             => l_return_status );
5259         IF l_return_status = FND_API.G_RET_STS_ERROR THEN
5260           RAISE FND_API.G_EXC_ERROR;
5261         ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5262           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5263         END IF;
5264 
5265         x_charges_detail_rec.transaction_type_id := p_charges_detail_rec.transaction_type_id;
5266         l_transaction_type_changed := 'Y';
5267 
5268       ELSE
5269 
5270         IF p_charges_detail_rec.transaction_type_id = FND_API.G_MISS_NUM OR
5271            p_charges_detail_rec.transaction_type_id  IS NULL THEN
5272 
5273            --DBMS_OUTPUT.PUT_LINE('Transaction Type Not Passed BP not Changed');
5274            -- transaction type is not passed
5275            -- transaction type has not changed
5276            x_charges_detail_rec.transaction_type_id := l_db_det_rec.transaction_type_id;
5277            l_transaction_type_changed := 'N';
5278 
5279            -- however call validate_txn_type just to get all the values which will be useful
5280            -- while validating instance
5281 
5282            VALIDATE_TXN_TYPE(P_API_NAME               => p_api_name,
5283                           P_BUSINESS_PROCESS_ID       => x_charges_detail_rec.business_process_id,
5284                           P_TXN_TYPE_ID               => x_charges_detail_rec.transaction_type_id,
5285                           P_SOURCE_CODE               => x_charges_detail_rec.source_code,
5286                           X_LINE_ORDER_CATEGORY_CODE  => l_line_order_category_code,
5287                           X_NO_CHARGE_FLAG            => l_no_charge_flag ,
5288                           X_INTERFACE_TO_OE_FLAG      => l_interface_to_oe_flag,
5289                           X_UPDATE_IB_FLAG            => l_update_ib_flag,
5290                           X_SRC_REFERENCE_REQD_FLAG   => l_src_reference_reqd_flag,
5291                           X_SRC_RETURN_REQD_FLAG      => l_src_return_reqd_flag,
5292                           X_NON_SRC_REFERENCE_REQD    => l_non_src_reference_reqd_flag ,
5293                           X_NON_SRC_RETURN_REQD       => l_non_src_return_reqd,
5294                           X_MSG_DATA                  => l_msg_data,
5295                           X_MSG_COUNT                 => l_msg_count,
5296                           X_RETURN_STATUS             => l_return_status );
5297            IF l_return_status = FND_API.G_RET_STS_ERROR THEN
5298              RAISE FND_API.G_EXC_ERROR;
5299            ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
5300             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5301            END IF;
5302 
5303         END IF;
5304       END IF;
5305     END IF;
5306     --DBMS_OUTPUT.PUT_LINE('passed transaction_type id validation in update ');
5307     --DBMS_OUTPUT.PUT_LINE('l_line_order_category_code = '||l_line_order_category_code);
5308     --DBMS_OUTPUT.PUT_LINE('l_no_charge_flag = '||l_no_charge_flag);
5309     --DBMS_OUTPUT.PUT_LINE('l_update_ib_flag = '||l_update_ib_flag);
5310     --DBMS_OUTPUT.PUT_LINE('l_src_reference_reqd_flag = '||l_src_reference_reqd_flag);
5311     --DBMS_OUTPUT.PUT_LINE('l_src_return_reqd_flag = '||l_src_return_reqd_flag);
5312     --DBMS_OUTPUT.PUT_LINE('l_non_src_reference_reqd_flag = '||l_non_src_reference_reqd_flag);
5313     --DBMS_OUTPUT.PUT_LINE('l_non_src_return_reqd = '||l_non_src_return_reqd);
5314     --DBMS_OUTPUT.PUT_LINE('l_return_status '||l_return_status );
5315   END IF;
5316 
5317 --====================================
5318 -- Line Order Category Code Validation
5319 --====================================
5320   --DBMS_OUTPUT.PUT_LINE('Line Order Category Code Validation ...');
5321 
5322   l_line_order_category_code  :=  NVL(l_line_order_category_code, p_charges_detail_rec.line_category_code);
5323 
5324   IF p_validation_mode = 'I' THEN
5325     IF p_charges_detail_rec.line_category_code IS NOT NULL THEN
5326 
5327       IF p_charges_detail_rec.line_category_code <> l_line_order_category_code THEN
5328         --raise error
5329         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_LN_ORD_CATEGORY');
5330         FND_MESSAGE.SET_TOKEN('LINE_ORDER_CATEGORY', p_charges_detail_rec.line_category_code);
5331         FND_MSG_PUB.ADD;
5332         RAISE FND_API.G_EXC_ERROR;
5333       ELSE
5334         -- the p_charges_detail_rec.line_category_code
5335         -- matches l_line_order_category_code
5336         -- assign to out record
5337         x_charges_detail_rec.line_category_code := p_charges_detail_rec.line_category_code;
5338       END IF;
5339 
5340     ELSE
5341       -- p_charges_detail_rec.line_category_code IS NULL
5342       -- assign the l_line_order_category_code to out record
5343       x_charges_detail_rec.line_category_code := l_line_order_category_code;
5344 
5345     END IF;
5346 
5347   ELSIF p_validation_mode = 'U' THEN
5348 
5349     -- Resolve Bug # 3078244
5350     -- line_order_category can change due to changed transaction type
5351 
5352     IF l_transaction_type_changed = 'Y' THEN
5353       IF p_charges_detail_rec.line_category_code <> FND_API.G_MISS_CHAR AND
5354          p_charges_detail_rec.line_category_code IS NOT NULL THEN
5355         IF p_charges_detail_rec.line_category_code <> l_line_order_category_code THEN
5356           --raise error
5357           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_LN_ORD_CATEGORY');
5358           FND_MESSAGE.SET_TOKEN('LINE_ORDER_CATEGORY', p_charges_detail_rec.line_category_code);
5359           FND_MSG_PUB.ADD;
5360           RAISE FND_API.G_EXC_ERROR;
5361         ELSE
5362           -- the p_charges_detail_rec.line_category_code
5363           -- matches l_line_order_category_code
5364           -- assign to out record
5365           x_charges_detail_rec.line_category_code := p_charges_detail_rec.line_category_code;
5366         END IF;
5367       ELSE
5368         -- p_charges_detail_rec.line_category_code is not passed
5369         -- assign the l_line_order_category_code to out record
5370         x_charges_detail_rec.line_category_code := l_line_order_category_code;
5371       END IF;
5372     ELSE
5373       -- l_transaction_type_changed := 'N'
5374       IF p_charges_detail_rec.line_category_code <> FND_API.G_MISS_CHAR AND
5375          p_charges_detail_rec.line_category_code IS NOT NULL THEN
5376         IF p_charges_detail_rec.line_category_code <> l_db_det_rec.line_category_code THEN
5377           --raise error
5378           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_LN_ORD_CATEGORY');
5379           FND_MESSAGE.SET_TOKEN('LINE_ORDER_CATEGORY', p_charges_detail_rec.line_category_code);
5380           FND_MSG_PUB.ADD;
5381           RAISE FND_API.G_EXC_ERROR;
5382         ELSE
5383           -- the p_charges_detail_rec.line_category_code
5384           -- matches l_db_det_rec.line_category_code
5385           -- assign to out record
5386           x_charges_detail_rec.line_category_code := p_charges_detail_rec.line_category_code;
5387         END IF;
5388       ELSE
5389         -- p_charges_detail_rec.line_category_code IS not passed
5390         -- assign the l_line_order_category_code to out record
5391         x_charges_detail_rec.line_category_code := l_db_det_rec.line_category_code;
5392       END IF;
5393     END IF;
5394 
5395     --DBMS_OUTPUT.PUT_LINE('passed line order category code validation');
5396 
5397   END IF;
5398 
5399 --===================================
5400 --Intreface To OE Flag Validation
5401 --===================================
5402   IF p_validation_mode = 'I' THEN
5403 
5404     -- If the interface_to_oe_flag is passed then use the interface_oe_flag passed by
5405     -- upstream application.
5406     -- If not passed then default this from the Transaction Type Setup
5407 
5408     -- Added for Bug # 5135284
5409     IF p_charges_detail_rec.interface_to_oe_flag IS NOT NULL AND
5410        p_charges_detail_rec.interface_to_oe_flag IN ('Y', 'N') THEN
5411        x_charges_detail_rec.interface_to_oe_flag := p_charges_detail_rec.interface_to_oe_flag;
5412     ELSE
5413       -- p_charges_detail_rec.interface_to_oe_flag is null
5414       -- default it to l_interface_to_oe_flag
5415       x_charges_detail_rec.interface_to_oe_flag := l_interface_to_oe_flag;
5416     END IF;
5417 
5418   ELSIF p_validation_mode = 'U' THEN
5419 
5420 
5421     -- Added for Bug # 5135284
5422      IF l_transaction_type_changed = 'Y' THEN
5423        IF p_charges_detail_rec.interface_to_oe_flag <> FND_API.G_MISS_CHAR AND
5424           p_charges_detail_rec.interface_to_oe_flag IS NOT NULL THEN
5425 
5426           IF p_charges_detail_rec.interface_to_oe_flag IN ('Y', 'N') THEN
5427             x_charges_detail_rec.interface_to_oe_flag := p_charges_detail_rec.interface_to_oe_flag;
5428           ELSE
5429             x_charges_detail_rec.interface_to_oe_flag := l_interface_to_oe_flag;
5430           END IF;
5431 
5432        ELSIF p_charges_detail_rec.interface_to_oe_flag IS NULL THEN
5433           x_charges_detail_rec.interface_to_oe_flag := 'N';
5434        ELSE
5435           x_charges_detail_rec.interface_to_oe_flag := l_interface_to_oe_flag;
5436        END IF;
5437 
5438      ELSE
5439         -- l_transaction_type_changed = 'N'
5440         IF p_charges_detail_rec.interface_to_oe_flag <> FND_API.G_MISS_CHAR AND
5441            p_charges_detail_rec.interface_to_oe_flag IS NOT NULL THEN
5442 
5443             IF p_charges_detail_rec.interface_to_oe_flag IN ('Y', 'N') THEN
5444               x_charges_detail_rec.interface_to_oe_flag := p_charges_detail_rec.interface_to_oe_flag;
5445             ELSE
5446               x_charges_detail_rec.interface_to_oe_flag := l_db_det_rec.interface_to_oe_flag;
5447             END IF;
5448 
5449         ELSIF p_charges_detail_rec.interface_to_oe_flag IS NULL THEN
5450            x_charges_detail_rec.interface_to_oe_flag := 'N';
5451         ELSE
5452            x_charges_detail_rec.interface_to_oe_flag := l_db_det_rec.interface_to_oe_flag;
5453         END IF;
5454 
5455      END IF;
5456 
5457      --DBMS_OUTPUT.PUT_LINE('passed interface_oe_flag validation');
5458   END IF;
5459 
5460 --====================================
5461 -- No Charge Flag Validation
5462 --====================================
5463   IF p_validation_mode = 'I' THEN
5464 
5465     -- If the no_charge_flag is passed then use the no_charge_flag passed by
5466     -- upstream application.
5467     -- If not passed then default this from the Transaction Type Setup
5468     -- Added for Bug # 5135284
5469     IF p_charges_detail_rec.no_charge_flag IS NOT NULL AND
5470        p_charges_detail_rec.no_charge_flag IN ('Y', 'N') THEN
5471       x_charges_detail_rec.no_charge_flag := p_charges_detail_rec.no_charge_flag;
5472     ELSE
5473       -- p_charges_detail_rec.no_charge_flag is null
5474       -- default it to l_no_charge_flag
5475       x_charges_detail_rec.no_charge_flag := l_no_charge_flag;
5476     END IF;
5477 
5478   ELSIF p_validation_mode = 'U' THEN
5479 
5480      -- Resolve Bug # 3078244
5481      -- If Transaction Type is changed and then
5482      -- if no_charge_flag is passed then use the no_charge_flag passed by
5483      -- upstream application
5484      -- if not passed then use the one from the database
5485 
5486      IF l_transaction_type_changed = 'Y' THEN
5487        IF p_charges_detail_rec.no_charge_flag <> FND_API.G_MISS_CHAR AND
5488           p_charges_detail_rec.no_charge_flag IS NOT NULL THEN
5489           IF p_charges_detail_rec.no_charge_flag IN ('Y', 'N') THEN
5490             x_charges_detail_rec.no_charge_flag := p_charges_detail_rec.no_charge_flag;
5491           ELSE
5492             x_charges_detail_rec.no_charge_flag := l_no_charge_flag;
5493           END IF;
5494        ELSIF p_charges_detail_rec.no_charge_flag IS NULL THEN
5495           x_charges_detail_rec.no_charge_flag := 'N';
5496        ELSE
5497           x_charges_detail_rec.no_charge_flag := l_no_charge_flag;
5498        END IF;
5499 
5500      ELSE
5501         -- l_transaction_type_changed = 'N'
5502         IF p_charges_detail_rec.no_charge_flag <> FND_API.G_MISS_CHAR AND
5503            p_charges_detail_rec.no_charge_flag IS NOT NULL THEN
5504            IF p_charges_detail_rec.no_charge_flag IN ('Y', 'N') THEN
5505             x_charges_detail_rec.no_charge_flag := p_charges_detail_rec.no_charge_flag;
5506           ELSE
5507             x_charges_detail_rec.no_charge_flag := l_db_det_rec.no_charge_flag;
5508           END IF;
5509         ELSIF p_charges_detail_rec.no_charge_flag IS NULL THEN
5510           x_charges_detail_rec.no_charge_flag := 'N';
5511         ELSE
5512            x_charges_detail_rec.no_charge_flag := l_db_det_rec.no_charge_flag;
5513         END IF;
5514 
5515      END IF;
5516 
5517      --DBMS_OUTPUT.PUT_LINE('passed no charge flag validation');
5518   END IF;
5519 
5520  --======================
5521  --Item Validation
5522  --======================
5523   --DBMS_OUTPUT.PUT_LINE('Item Validation ...');
5524 
5525   IF p_validation_mode = 'I' THEN
5526 
5527     IF p_charges_detail_rec.inventory_item_id_in IS NULL THEN
5528       Add_Null_Parameter_Msg(l_api_name,
5529                              'inventory_item_id') ;
5530 
5531       Add_Invalid_Argument_Msg(l_api_name,
5532                                to_char(p_charges_detail_rec.inventory_item_id_in),
5533                                'inventory_item_id');
5534       RAISE FND_API.G_EXC_ERROR ;
5535 
5536     ELSE
5537       -- Inventory_Item_ID is not null, call Validate Item
5538 
5539       --DBMS_OUTPUT.PUT_LINE('Calling VALIDATE_ITEM. p_charges_detail_rec.inventory_item_id_in='||p_charges_detail_rec.inventory_item_id_in);
5540 
5541       VALIDATE_ITEM(P_API_NAME            => p_api_name,
5542                     P_INV_ID              => p_charges_detail_rec.inventory_item_id_in,
5543                     P_UPDATE_IB_FLAG      => l_update_ib_flag,
5544                     X_COMMS_TRACKABLE_FLAG=> l_comms_trackable_flag,
5545                     X_SERIAL_CONTROL_FLAG => l_serial_control_flag,
5546                     X_REV_CONTROL_FLAG    => l_rev_control_flag,
5547                     X_MSG_DATA            => l_msg_data,
5548                     X_MSG_COUNT           => l_msg_count,
5549                     X_RETURN_STATUS       => l_return_status);
5550 
5551       --DBMS_OUTPUT.PUT_LINE('Back from VALIDATE_ITEM '||l_return_status);
5552 
5553       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5554         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_VALIDATE_ITEM_ERROR');
5555         FND_MESSAGE.SET_TOKEN('INV_ID', p_charges_detail_rec.inventory_item_id_in);
5556         FND_MSG_PUB.ADD;
5557         RAISE FND_API.G_EXC_ERROR;
5558       ELSE
5559         --assign to out record
5560         x_charges_detail_rec.inventory_item_id_in := p_charges_detail_rec.inventory_item_id_in;
5561       END IF;
5562 
5563     END IF;
5564 
5565   ELSIF p_validation_mode = 'U' THEN
5566 
5567     --DBMS_OUTPUT.PUT_LINE( 'In update for item val');
5568     --DBMS_OUTPUT.PUT_LINE( 'p_charges_detail_rec.inventory_item_id_in '||p_charges_detail_rec.inventory_item_id_in);
5569 
5570     -- Resolve Bug # 3078244
5571     IF p_charges_detail_rec.inventory_item_id_in <> FND_API.G_MISS_NUM AND
5572        p_charges_detail_rec.inventory_item_id_in IS NOT NULL THEN
5573 
5574       IF l_db_det_rec.customer_product_id IS NOT NULL AND
5575         p_charges_detail_rec.inventory_item_id_in <> l_db_det_rec.inventory_item_id AND
5576         p_charges_detail_rec.customer_product_id IS NULL AND
5577         l_src_reference_reqd_flag = 'Y' AND
5578         l_src_return_reqd_flag = 'Y' AND
5579         l_update_ib_flag = 'Y' AND
5580         l_line_order_category_code = 'RETURN' THEN
5581 
5582         --DBMS_OUTPUT.PUT_LINE('Cannot change item');
5583 
5584         Cant_Update_Detail_Param_Msg(l_api_name_full,
5585                                      'INVENTORY_ITEM_ID',
5586                                      to_char(p_charges_DETAIL_rec.inventory_item_id_in));
5587 
5588         RAISE FND_API.G_EXC_ERROR ;
5589 
5590 
5591       ELSE
5592 
5593         --DBMS_OUTPUT.PUT_LINE('p_charges_detail_rec.inventory_item_id_in not null');
5594         -- Validate Item
5595         VALIDATE_ITEM(P_API_NAME                  => p_api_name,
5596                       P_INV_ID                    => p_charges_detail_rec.inventory_item_id_in,
5597                       P_UPDATE_IB_FLAG            => l_update_ib_flag,
5598                       X_COMMS_TRACKABLE_FLAG      => l_comms_trackable_flag,
5599                       X_SERIAL_CONTROL_FLAG       => l_serial_control_flag,
5600                       X_REV_CONTROL_FLAG          => l_rev_control_flag,
5601                       X_MSG_DATA                  => l_msg_data,
5602                       X_MSG_COUNT                 => l_msg_count,
5603                       X_RETURN_STATUS             => l_return_status);
5604 
5605         --DBMS_OUTPUT.PUT_LINE('l_return_status = '||l_return_status);
5606 
5607         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5608           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_VALIDATE_ITEM_ERROR');
5609           FND_MESSAGE.SET_TOKEN('INV_ID', p_charges_detail_rec.inventory_item_id_in);
5610           FND_MSG_PUB.ADD;
5611           RAISE FND_API.G_EXC_ERROR;
5612         END IF;
5613 
5614         --assign to out record
5615         x_charges_detail_rec.inventory_item_id_in := p_charges_detail_rec.inventory_item_id_in;
5616 
5617         --Condition added to fix Bug # 3358531
5618         --the flags will only be set to Y if they do not match the database
5619         IF x_charges_detail_rec.inventory_item_id_in <> l_db_det_rec.inventory_item_id THEN
5620           -- Item is changed so recalculate the price
5621           l_calc_sp := 'Y' ;
5622           l_item_changed := 'Y';
5623         END IF;
5624 
5625         --DBMS_OUTPUT.PUT_LINE('Item Valid');
5626 
5627       END IF ;
5628 
5629     ELSE
5630       --p_charges_detail_rec.inventory_item_id_in is not passed
5631       --assign to out record
5632       IF p_charges_detail_rec.inventory_item_id_in = FND_API.G_MISS_NUM OR
5633          p_charges_detail_rec.inventory_item_id_in IS NULL THEN
5634 
5635          x_charges_detail_rec.inventory_item_id_in := l_db_det_rec.inventory_item_id;
5636 
5637          --again need to validate the item as all flags are not stored in DB
5638          VALIDATE_ITEM(P_API_NAME                 => p_api_name,
5639                       P_INV_ID                    => x_charges_detail_rec.inventory_item_id_in,
5640                       P_UPDATE_IB_FLAG            => l_update_ib_flag,
5641                       X_COMMS_TRACKABLE_FLAG      => l_comms_trackable_flag,
5642                       X_SERIAL_CONTROL_FLAG       => l_serial_control_flag,
5643                       X_REV_CONTROL_FLAG          => l_rev_control_flag,
5644                       X_MSG_DATA                  => l_msg_data,
5645                       X_MSG_COUNT                 => l_msg_count,
5646                       X_RETURN_STATUS             => l_return_status);
5647 
5648          --DBMS_OUTPUT.PUT_LINE('item from db');
5649       END IF;
5650 
5651     END IF;
5652 
5653     --DBMS_OUTPUT.PUT_LINE('Passed Item Validation');
5654     --DBMS_OUTPUT.PUT_LINE('Item is = '||x_charges_detail_rec.inventory_item_id_in);
5655   END IF;
5656 
5657 
5658 
5659  --=========================
5660  --Item Revision Validation
5661  --=========================
5662   --DBMS_OUTPUT.PUT_LINE('Item Revision Validation ...');
5663   IF p_validation_mode = 'I' THEN
5664     IF l_rev_control_flag = 'Y' THEN
5665       IF p_charges_detail_rec.item_revision IS NOT NULL AND
5666          p_charges_detail_rec.item_revision <> FND_API.G_MISS_CHAR THEN
5667            -- Added for fix:5125858
5668             IF IS_ITEM_REVISION_VALID(
5669                  p_inventory_item_id => p_charges_detail_rec.inventory_item_id_in,
5670                  p_item_revision    => p_charges_detail_rec.item_revision,
5671                  x_msg_data         => l_msg_data,
5672                  x_msg_count        => l_msg_count,
5673                  x_return_status    => l_return_status) = 'N' THEN
5674 
5675                  Add_Invalid_Argument_Msg(l_api_name,
5676                                           TO_CHAR(p_charges_detail_rec.item_revision),
5677                                           'item_revision');
5678                   RAISE FND_API.G_EXC_ERROR;
5679              ELSE
5680                   x_charges_detail_rec.item_revision := p_charges_detail_rec.item_revision;
5681 
5682             END IF;
5683       ELSE
5684         --item is revision controlled but item revsion is null
5685         --raise error
5686         --FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_ITEM_REVISION');
5687         --FND_MESSAGE.SET_TOKEN('INVENTORY_ITEM_ID', p_charges_detail_rec.inventory_item_id_in, TRUE);
5688         --FND_MESSAGE.SET_TOKEN('ITEM_REVISION', p_charges_detail_rec.item_revision, TRUE);
5689         --FND_MSG_PUB.ADD;
5690         --RAISE FND_API.G_EXC_ERROR;
5691         x_charges_detail_rec.item_revision := NULL;
5692       END IF;
5693     ELSE
5694       -- l_rev_control_flag = 'N'
5695       x_charges_detail_rec.item_revision := NULL;
5696     END IF;
5697 
5698   ELSIF p_validation_mode = 'U' THEN
5699 
5700     -- Resolve Bug # 3078244
5701 
5702     IF l_item_changed = 'Y' THEN
5703       IF l_rev_control_flag = 'Y' THEN
5704         IF p_charges_detail_rec.item_revision <> FND_API.G_MISS_CHAR AND
5705            p_charges_detail_rec.item_revision IS NOT NULL THEN
5706 
5707            -- Added for fix:5125858
5708             IF IS_ITEM_REVISION_VALID(
5709                  p_inventory_item_id => p_charges_detail_rec.inventory_item_id_in,
5710                  p_item_revision    => p_charges_detail_rec.item_revision,
5711                  x_msg_data         => l_msg_data,
5712                  x_msg_count        => l_msg_count,
5713                  x_return_status    => l_return_status) = 'N' THEN
5714 
5715                  Add_Invalid_Argument_Msg(l_api_name,
5716                                           TO_CHAR(p_charges_detail_rec.item_revision),
5717                                           'item_revision');
5718                   RAISE FND_API.G_EXC_ERROR;
5719              ELSE
5720                   x_charges_detail_rec.item_revision := p_charges_detail_rec.item_revision;
5721 
5722             END IF;
5723 
5724         ELSE
5725           --item is revision controlled but item revsion is null, raise error
5726           --FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_ITEM_REVISION');
5727           --FND_MESSAGE.SET_TOKEN('INVENTORY_ITEM_ID', p_charges_detail_rec.inventory_item_id_in, TRUE);
5728           --FND_MESSAGE.SET_TOKEN('ITEM_REVISION', p_charges_detail_rec.item_revision, TRUE);
5729           --FND_MSG_PUB.ADD;
5730           --RAISE FND_API.G_EXC_ERROR;
5731           x_charges_detail_rec.item_revision := NULL;
5732         END IF;
5733       ELSE
5734         --l_rev_control_flag = 'N' THEN ignore the item revision
5735         x_charges_detail_rec.item_revision := NULL;
5736       END IF;
5737     ELSE
5738       --l_item_changed = 'N'
5739       IF l_db_det_rec.item_revision IS NOT NULL THEN
5740         l_rev_control_flag := 'Y' ;
5741       ELSE
5742         l_rev_control_flag := 'N' ;
5743       END IF;
5744 
5745       IF l_rev_control_flag = 'Y' THEN
5746         IF p_charges_detail_rec.item_revision <> FND_API.G_MISS_CHAR AND
5747            p_charges_detail_rec.item_revision IS NOT NULL THEN
5748            --
5749            -- Added for fix:5125858
5750             IF IS_ITEM_REVISION_VALID(
5751                  p_inventory_item_id => p_charges_detail_rec.inventory_item_id_in,
5752                  p_item_revision    => p_charges_detail_rec.item_revision,
5753                  x_msg_data         => l_msg_data,
5754                  x_msg_count        => l_msg_count,
5755                  x_return_status    => l_return_status) = 'N' THEN
5756 
5757                  Add_Invalid_Argument_Msg(l_api_name,
5758                                           TO_CHAR(p_charges_detail_rec.item_revision),
5759                                           'item_revision');
5760                   RAISE FND_API.G_EXC_ERROR;
5761              ELSE
5762                   x_charges_detail_rec.item_revision := p_charges_detail_rec.item_revision;
5763 
5764             END IF;
5765            --
5766            -- Added for fix:5125858
5767         ELSE
5768            --get the revision from the database
5769            x_charges_detail_rec.item_revision := l_db_det_rec.item_revision;
5770         END IF;
5771       ELSE
5772         --l_rev_control_flag = 'N' THEN ignore the item revision
5773         x_charges_detail_rec.item_revision := NULL;
5774       END IF;
5775 
5776     END IF;
5777 
5778     --DBMS_OUTPUT.PUT_LINE('Item Revision '||x_charges_detail_rec.item_revision);
5779 
5780 
5781   END IF;
5782 
5783  --=========================
5784  --Line Number Validation
5785  --=========================
5786   --DBMS_OUTPUT.PUT_LINE('Line Number Validation ...');
5787   -- Added for fix:5125385
5788   IF p_validation_mode = 'I' THEN
5789      IF p_charges_detail_rec.line_number IS NOT NULL AND
5790         p_charges_detail_rec.line_number <> FND_API.G_MISS_NUM THEN
5791            -- If the line number already exists or <= 0, then raise an error message
5792             IF IS_LINE_NUMBER_VALID(
5793                  p_line_number => p_charges_detail_rec.line_number,
5794                  p_incident_id => p_charges_detail_rec.incident_id,
5795                  x_msg_data         => l_msg_data,
5796                  x_msg_count        => l_msg_count,
5797                  x_return_status    => l_return_status) = 'Y' THEN
5798 
5799                  Add_Invalid_Argument_Msg(l_api_name,
5800                                           TO_CHAR(p_charges_detail_rec.line_number),
5801                                           'line_number');
5802                   RAISE FND_API.G_EXC_ERROR;
5803              ELSE
5804                   x_charges_detail_rec.line_number := p_charges_detail_rec.line_number;
5805 
5806             END IF;
5807 
5808       END IF;
5809 
5810   ELSIF p_validation_mode = 'U' THEN
5811     -- no validation is performed for update mode
5812     null;
5813 
5814  END IF;
5815  --======================
5816  --UOM Validation
5817  --======================
5818   --DBMS_OUTPUT.PUT_LINE('UOM Validation ...  p_charges_detail_rec.unit_of_measure_code='||p_charges_detail_rec.unit_of_measure_code);
5819   IF p_validation_mode = 'I' THEN
5820 
5821     IF p_charges_detail_rec.unit_of_measure_code IS NOT NULL THEN
5822 
5823 
5824        l_valid_check := IS_UOM_VALID(
5825                         p_inv_id        => p_charges_detail_rec.inventory_item_id_in,
5826                         p_uom_code      => p_charges_detail_rec.unit_of_measure_code,
5827                         x_msg_data      => l_msg_data,
5828                         x_msg_count     => l_msg_count,
5829                         x_return_status => l_return_status);
5830 
5831         IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
5832           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5833         ELSIF l_return_status = G_RET_STS_ERROR THEN
5834           RAISE FND_API.G_EXC_ERROR;
5835         END IF;
5836 
5837       IF l_valid_check <> 'Y' THEN
5838         Add_Invalid_Argument_Msg(l_api_name,
5839                                  p_charges_detail_rec.unit_of_measure_code,
5840                                  'Unit_of_Measure_Code');
5841         RAISE FND_API.G_EXC_ERROR;
5842 
5843       ELSE
5844         --assign to out record
5845         x_charges_detail_rec.unit_of_measure_code := p_charges_detail_rec.unit_of_measure_code;
5846       END IF;
5847 
5848     ELSE
5849       -- p_charges_detail_rec.unit_of_measure_code IS NULL, call get primary UOM Proc
5850 
5851       --DBMS_OUTPUT.PUT_LINE('Calling GET_PRIMARY_UOM');
5852       GET_PRIMARY_UOM(P_INV_ID        =>    p_charges_detail_rec.inventory_item_id_in,
5853                       X_PRIMARY_UOM   =>    l_primary_uom,
5854                       X_MSG_DATA      =>    l_msg_data ,
5855                       X_MSG_COUNT     =>    l_msg_count,
5856                       X_RETURN_STATUS =>    l_return_status);
5857 
5858       --DBMS_OUTPUT.PUT_LINE('Back from GET_PRIMARY_UOM status='||l_return_status || '   l_primary_uom '||l_primary_uom);
5859 
5860       --IF l_return_status <> 'S' THEN
5861       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5862         --raise error
5863         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_PRIMARY_UOM_ERROR');
5864         FND_MESSAGE.SET_TOKEN('INV_ID', p_charges_detail_rec.inventory_item_id_in);
5865         FND_MSG_PUB.ADD;
5866         RAISE FND_API.G_EXC_ERROR;
5867       END IF;
5868 
5869       --assign to out record
5870       x_charges_detail_rec.unit_of_measure_code := l_primary_uom;
5871 
5872     END IF;
5873 
5874   ELSIF p_validation_mode = 'U' THEN
5875 
5876   -- Resolve Bug # 3078244
5877 
5878   IF l_item_changed = 'Y' THEN
5879    IF p_charges_detail_rec.unit_of_measure_code <> FND_API.G_MISS_CHAR AND
5880       p_charges_detail_rec.unit_of_measure_code IS NOT NULL THEN
5881 
5882         l_valid_check := IS_UOM_VALID(
5883                         p_inv_id        => p_charges_detail_rec.inventory_item_id_in,
5884                         p_uom_code      => p_charges_detail_rec.unit_of_measure_code,
5885                         x_msg_data      => l_msg_data,
5886                         x_msg_count     => l_msg_count,
5887                         x_return_status => l_return_status);
5888 
5889         IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
5890           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5891         ELSIF l_return_status = G_RET_STS_ERROR THEN
5892           RAISE FND_API.G_EXC_ERROR;
5893         END IF;
5894 
5895       IF l_valid_check <> 'Y' THEN
5896           Add_Invalid_Argument_Msg(l_api_name,
5897                                  p_charges_detail_rec.unit_of_measure_code,
5898                                  'Unit_of_Measure_Code');
5899         RAISE FND_API.G_EXC_ERROR;
5900 
5901       ELSE
5902         --assign to out record
5903         x_charges_detail_rec.unit_of_measure_code := p_charges_detail_rec.unit_of_measure_code;
5904 
5905          --Condition added to fix Bug # 3358531
5906         IF x_charges_detail_rec.unit_of_measure_code <> l_db_det_rec.unit_of_measure_code THEN
5907           --Unit Of Measure is changed need to re-calculate the list price
5908           l_calc_sp := 'Y';
5909         END IF;
5910 
5911       END IF;
5912 
5913 
5914     ELSE
5915         -- p_charges_detail_rec.unit_of_measure_code is not passed
5916         -- get primary UOM Proc
5917         GET_PRIMARY_UOM(P_INV_ID        =>    p_charges_detail_rec.inventory_item_id_in,
5918                         X_PRIMARY_UOM   =>    l_primary_uom,
5919                         X_MSG_DATA      =>    l_msg_data,
5920                         X_MSG_COUNT     =>    l_msg_count,
5921                         X_RETURN_STATUS =>    l_return_status);
5922 
5923         --IF l_return_status <> 'S' THEN
5924         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
5925           --raise error
5926           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_PRIMARY_UOM_ERROR');
5927           FND_MESSAGE.SET_TOKEN('INV_ID', p_charges_detail_rec.inventory_item_id_in);
5928           FND_MSG_PUB.ADD;
5929           RAISE FND_API.G_EXC_ERROR;
5930         END IF;
5931 
5932         --assign to out record
5933         x_charges_detail_rec.unit_of_measure_code := l_primary_uom;
5934 
5935         --Condition added to fix Bug # 3358531
5936         IF x_charges_detail_rec.unit_of_measure_code <> l_db_det_rec.unit_of_measure_code THEN
5937           --Unit Of Measure is changed need to re-calculate the list price
5938           l_calc_sp := 'Y';
5939         END IF;
5940 
5941       END IF;
5942 
5943     ELSE
5944 
5945       -- l_item_changed = 'N';
5946       IF p_charges_detail_rec.unit_of_measure_code <> FND_API.G_MISS_CHAR AND
5947          p_charges_detail_rec.unit_of_measure_code IS NOT NULL THEN
5948 
5949         l_valid_check := IS_UOM_VALID(
5950                         p_inv_id        => p_charges_detail_rec.inventory_item_id_in,
5951                         p_uom_code      => p_charges_detail_rec.unit_of_measure_code,
5952                         x_msg_data      => l_msg_data,
5953                         x_msg_count     => l_msg_count,
5954                         x_return_status => l_return_status);
5955 
5956         IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
5957           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5958         ELSIF l_return_status = G_RET_STS_ERROR THEN
5959           RAISE FND_API.G_EXC_ERROR;
5960         END IF;
5961 
5962       IF l_valid_check <> 'Y' THEN
5963         Add_Invalid_Argument_Msg(l_api_name,
5964                                  p_charges_detail_rec.unit_of_measure_code,
5965                                  'Unit_of_Measure_Code');
5966         RAISE FND_API.G_EXC_ERROR;
5967       ELSE
5968         --assign to out record
5969         x_charges_detail_rec.unit_of_measure_code := p_charges_detail_rec.unit_of_measure_code;
5970 
5971         --Condition added to fix Bug # 3358531
5972         IF x_charges_detail_rec.unit_of_measure_code <> l_db_det_rec.unit_of_measure_code THEN
5973           --Unit Of Measure is changed need to re-calculate the list price
5974           l_calc_sp := 'Y';
5975         END IF;
5976       END IF;
5977     ELSE
5978         -- p_charges_rec.unit_of_measure_code is not passed or null
5979         -- assign db record to out record
5980         x_charges_detail_rec.unit_of_measure_code := l_db_det_rec.unit_of_measure_code;
5981     END IF;
5982 
5983   END IF;
5984 
5985   END IF;
5986   --DBMS_OUTPUT.PUT_LINE('UOM Validation completed...  x_charges_detail_rec.unit_of_measure_code='||x_charges_detail_rec.unit_of_measure_code);
5987 
5988 
5989  --==========================================
5990  --Billing Flag Validation    Note: billing flag means billing category
5991  --==========================================
5992   --DBMS_OUTPUT.PUT_LINE('Billing Flag Validation ...');
5993   IF p_validation_mode = 'I' THEN
5994 
5995     --DBMS_OUTPUT.PUT_LINE('Calling GET_BILLING_FLAG. p_charges_detail_rec.inventory_item_id_in=' || p_charges_detail_rec.inventory_item_id_in);
5996     --DBMS_OUTPUT.PUT_LINE('p_charges_detail_rec.transaction_type_id=' || p_charges_detail_rec.transaction_type_id);
5997 
5998     GET_BILLING_FLAG(
5999                      P_API_NAME           => p_api_name,
6000                      P_INV_ID             => p_charges_detail_rec.inventory_item_id_in,
6001                      P_TXN_TYPE_ID        => p_charges_detail_rec.transaction_type_id,
6002                      X_BILLING_FLAG       => l_billing_flag,
6003                      X_MSG_DATA           => l_msg_data,
6004                      X_MSG_COUNT          => l_msg_count,
6005                      X_RETURN_STATUS      => l_return_status);
6006 
6007     --DBMS_OUTPUT.PUT_LINE('Back from GET_BILLING_FLAG. Status='||l_return_status||'  l_billing_flag='||l_billing_flag);
6008 
6009     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6010       RAISE FND_API.G_EXC_ERROR;
6011     END IF;
6012 
6013     --DBMS_OUTPUT.PUT_LINE('p_charges_detail_rec.billing_flag = ' || p_charges_detail_rec.billing_flag);
6014     --DBMS_OUTPUT.PUT_LINE('l_billing_flag = ' || l_billing_flag);
6015 
6016     IF p_charges_detail_rec.billing_flag IS NOT NULL THEN
6017       --DBMS_OUTPUT.PUT_LINE('P_Billing_Flag is not null');
6018       IF p_charges_detail_rec.billing_flag = l_billing_flag THEN
6019         x_charges_detail_rec.billing_flag := p_charges_detail_rec.billing_flag;
6020       ELSE
6021         -- Billing Flag does not match, raise Error
6022         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_BILLING_FLAG');
6023         FND_MESSAGE.SET_TOKEN('BILLING_FLAG', p_charges_detail_rec.billing_flag);
6024         FND_MSG_PUB.ADD;
6025         RAISE FND_API.G_EXC_ERROR;
6026       END IF;
6027     ELSE
6028       -- p_charges_detail_rec.billing_flag is null
6029       -- assign l_billing_flag to out record
6030       --DBMS_OUTPUT.PUT_LINE('P_Billing_Flag is not null');
6031       x_charges_detail_rec.billing_flag := l_billing_flag;
6032     END IF;
6033 
6034     --DBMS_OUTPUT.PUT_LINE('Billing Flag is '||x_charges_detail_rec.billing_flag);
6035 
6036   ELSIF p_validation_mode = 'U' THEN
6037 
6038     IF l_item_changed = 'Y' OR
6039        l_transaction_type_changed = 'Y' THEN
6040        --get the new billing flag
6041       GET_BILLING_FLAG(
6042                        P_API_NAME           => p_api_name,
6043                        P_INV_ID             => x_charges_detail_rec.inventory_item_id_in,
6044                        P_TXN_TYPE_ID        => x_charges_detail_rec.transaction_type_id,
6045                        X_BILLING_FLAG       => l_billing_flag,
6046                        X_MSG_DATA           => l_msg_data,
6047                        X_MSG_COUNT          => l_msg_count,
6048                        X_RETURN_STATUS      => l_return_status);
6049 
6050       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6051         RAISE FND_API.G_EXC_ERROR ;
6052       END IF;
6053 
6054       IF p_charges_detail_rec.billing_flag <> FND_API.G_MISS_CHAR AND
6055          p_charges_detail_rec.billing_flag IS NOT NULL THEN
6056         IF p_charges_detail_rec.billing_flag = l_billing_flag THEN
6057           x_charges_detail_rec.billing_flag := p_charges_detail_rec.billing_flag;
6058         ELSE
6059           -- Billing Flag does not match
6060           -- Raise Error
6061           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_BILLING_FLAG');
6062           FND_MESSAGE.SET_TOKEN('BILLING_FLAG', p_charges_detail_rec.billing_flag);
6063           FND_MSG_PUB.ADD;
6064           RAISE FND_API.G_EXC_ERROR;
6065         END IF;
6066 
6067       ELSE
6068         -- p_charges_detail_rec.billing_flag is is not passed or is null
6069         -- assign l_billing_flag to out record
6070         x_charges_detail_rec.billing_flag := l_billing_flag;
6071       END IF;
6072 
6073     ELSE
6074       --niether item nor transaction type changed
6075       --assign attribute from db_record
6076       --x_charges_detail_rec.billing_flag := l_db_det_rec.billing_flag;  -- no such column
6077 
6078       GET_BILLING_FLAG(
6079                        P_API_NAME           => p_api_name,
6080                        P_INV_ID             => x_charges_detail_rec.inventory_item_id_in,
6081                        P_TXN_TYPE_ID        => x_charges_detail_rec.transaction_type_id,
6082                        X_BILLING_FLAG       => l_billing_flag,
6083                        X_MSG_DATA           => l_msg_data,
6084                        X_MSG_COUNT          => l_msg_count,
6085                        X_RETURN_STATUS      => l_return_status);
6086 
6087       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6088         RAISE FND_API.G_EXC_ERROR ;
6089       END IF;
6090 
6091       x_charges_detail_rec.billing_flag := l_billing_flag;
6092     END IF;
6093 
6094     --DBMS_OUTPUT.PUT_LINE('Completes Billing Flag Validation ...');
6095 
6096   END IF;
6097 
6098  --=======================================
6099  --Transaction Billing Type ID Validation
6100  --=======================================
6101   --DBMS_OUTPUT.PUT_LINE('Transaction Billing Type ID Validation ...');
6102   IF p_validation_mode = 'I' THEN
6103 
6104     --DBMS_OUTPUT.PUT_LINE('Calling GET_TXN_BILLING_TYPE');
6105     GET_TXN_BILLING_TYPE(P_API_NAME            => p_api_name,
6106                          P_INV_ID              => p_charges_detail_rec.inventory_item_id_in,
6107                          P_TXN_TYPE_ID         => p_charges_detail_rec.transaction_type_id,
6108                          X_TXN_BILLING_TYPE_ID => l_txn_billing_type_id,
6109                          X_MSG_DATA            => l_msg_data,
6110                          X_MSG_COUNT           => l_msg_count,
6111                          X_RETURN_STATUS       => l_return_status);
6112     --DBMS_OUTPUT.PUT_LINE('Back from GET_TXN_BILLING_TYPE '||l_return_status);
6113 
6114     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6115 
6116       RAISE FND_API.G_EXC_ERROR ;
6117 
6118     ELSE
6119 
6120       IF p_charges_detail_rec.txn_billing_type_id IS NOT NULL THEN
6121 
6122         IF p_charges_detail_rec.txn_billing_type_id <> l_txn_billing_type_id THEN
6123           --RAISE ERROR
6124           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_TXN_BILLING_TYP');
6125           FND_MESSAGE.SET_TOKEN('TXN_BILLING_TYPE_ID', p_charges_detail_rec.txn_billing_type_id);
6126           FND_MSG_PUB.ADD;
6127           RAISE FND_API.G_EXC_ERROR;
6128         ELSE --
6129           --the ids match
6130           --assign to the out record
6131           x_charges_detail_rec.txn_billing_type_id := p_charges_detail_rec.txn_billing_type_id ;
6132         END IF;
6133 
6134       ELSE
6135         -- p_charges_detail_rec.txn_billing_type_id is null
6136         -- assign l_txn_billing_type_id to out record
6137         x_charges_detail_rec.txn_billing_type_id := l_txn_billing_type_id;
6138       END IF;
6139 
6140     END IF;
6141 
6142   ELSIF p_validation_mode = 'U' THEN
6143 
6144     IF l_item_changed = 'Y' OR
6145        l_transaction_type_changed = 'Y' THEN
6146 
6147       --need to get the txn billing type for changed parameters
6148 
6149       GET_TXN_BILLING_TYPE(P_API_NAME            => p_api_name,
6150                            P_INV_ID              => x_charges_detail_rec.inventory_item_id_in,
6151                            P_TXN_TYPE_ID         => x_charges_detail_rec.transaction_type_id,
6152                            X_TXN_BILLING_TYPE_ID => l_txn_billing_type_id,
6153                            X_MSG_DATA            => l_msg_data,
6154                            X_MSG_COUNT           => l_msg_count,
6155                            X_RETURN_STATUS       => l_return_status);
6156 
6157       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6158         RAISE FND_API.G_EXC_ERROR ;
6159       END IF;
6160 
6161       IF p_charges_detail_rec.txn_billing_type_id  <> FND_API.G_MISS_NUM AND
6162          p_charges_detail_rec.txn_billing_type_id IS NOT NULL THEN
6163         IF p_charges_detail_rec.txn_billing_type_id <> l_txn_billing_type_id THEN
6164           --RAISE ERROR
6165           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_TXN_BILLING_TYP');
6166           FND_MESSAGE.SET_TOKEN('TXN_BILLING_TYPE_ID', p_charges_detail_rec.txn_billing_type_id);
6167           FND_MSG_PUB.ADD;
6168           RAISE FND_API.G_EXC_ERROR;
6169         ELSE --
6170           --the ids match
6171           --assign to the out record
6172           x_charges_detail_rec.txn_billing_type_id := p_charges_detail_rec.txn_billing_type_id ;
6173         END IF;
6174 
6175       ELSE
6176 
6177         -- p_charges_detail_rec.txn_billing_type_id is not passed
6178         -- assign l_txn_billing_type_id to out record
6179         x_charges_detail_rec.txn_billing_type_id := l_txn_billing_type_id;
6180 
6181       END IF;
6182 
6183     ELSE
6184 
6185       -- niether the item nor the transaction type is changed
6186       -- assign the billing type from db
6187       x_charges_detail_rec.txn_billing_type_id := l_db_det_rec.txn_billing_type_id;
6188 
6189     END IF;
6190 
6191     --DBMS_OUTPUT.PUT_LINE('Completed the txn billing type id');
6192 
6193   END IF;
6194 
6195 
6196  --=======================================
6197  --Line Type ID
6198  --=======================================
6199   --DBMS_OUTPUT.PUT_LINE('Line Type ID Validation ...');
6200   IF p_validation_mode = 'I' THEN
6201 
6202     --DBMS_OUTPUT.PUT_LINE('Calling get_line_type ...');
6203     --DBMS_OUTPUT.PUT_LINE('p_charges_detail_rec.transaction_type_id = ' || p_charges_detail_rec.transaction_type_id);
6204     --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.transaction_type_id = ' || x_charges_detail_rec.transaction_type_id);
6205     --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.txn_billing_type_id = ' || x_charges_detail_rec.txn_billing_type_id);
6206         --Fixed Bug # 3325667 added p_org_id to procedure get_line_type
6207         Get_Line_Type(
6208           p_api_name       => p_api_name,
6209           p_txn_billing_type_id => x_charges_detail_rec.txn_billing_type_id,
6210           p_org_id              => x_charges_detail_rec.org_id,
6211           x_line_type_id  => l_line_type_id,
6212           x_return_status => l_return_status,
6213           x_msg_count => l_msg_count,
6214           x_msg_data => l_msg_data);
6215 
6216     --DBMS_OUTPUT.PUT_LINE('Back from Calling get_line_type. status = '||l_return_status);
6217     --DBMS_OUTPUT.PUT_LINE('msg_data = '||l_msg_data);
6218 
6219     IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6220 
6221       RAISE FND_API.G_EXC_ERROR ;
6222 
6223     ELSE
6224 
6225       --DBMS_OUTPUT.PUT_LINE('p_charges_detail_rec.line_type_id = '||p_charges_detail_rec.line_type_id);
6226       --DBMS_OUTPUT.PUT_LINE('l_line_type_id = '||l_line_type_id);
6227       --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.txn_billing_type_id = '||x_charges_detail_rec.txn_billing_type_id);
6228 
6229       IF p_charges_detail_rec.line_type_id IS NOT NULL THEN
6230 
6231         IF p_charges_detail_rec.line_type_id <> l_line_type_id THEN
6232           --RAISE ERROR
6233           --DBMS_OUTPUT.PUT_LINE('here is the error');
6234           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_LINE_TYPE');
6235           FND_MESSAGE.SET_TOKEN('LINE_TYPE_ID', p_charges_detail_rec.line_type_id);
6236           FND_MESSAGE.SET_TOKEN('TXN_LINE_TYPE_ID', l_line_type_id);
6237           FND_MESSAGE.SET_TOKEN('TXN_BILLING_TYPE_ID', x_charges_detail_rec.txn_billing_type_id);
6238           FND_MSG_PUB.ADD;
6239           RAISE FND_API.G_EXC_ERROR;
6240         ELSE --
6241           --the ids match
6242           --assign to the out record
6243           x_charges_detail_rec.line_type_id := p_charges_detail_rec.line_type_id;
6244         END IF;
6245 
6246       ELSE
6247         -- p_charges_detail_rec.line_type_id is null
6248         -- assign l_line_type_id to out record
6249         x_charges_detail_rec.line_type_id := l_line_type_id;
6250       END IF;
6251 
6252     END IF;
6253 
6254   ELSIF p_validation_mode = 'U' THEN
6255 
6256     IF l_item_changed = 'Y' OR
6257        l_transaction_type_changed = 'Y' THEN
6258 
6259       --need to get the line type id for changed parameters
6260       --Fixed Bug # 3325667 added p_org_id to procedure get_line_type
6261 
6262       Get_Line_Type(p_api_name            => p_api_name,
6263                     p_txn_billing_type_id => x_charges_detail_rec.txn_billing_type_id,
6264                     p_org_id              => x_charges_detail_rec.org_id,
6265                     x_line_type_id        => l_line_type_id,
6266                     x_return_status       => l_return_status,
6267                     x_msg_count           => l_msg_count,
6268                     x_msg_data            => l_msg_data);
6269 
6270       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
6271         RAISE FND_API.G_EXC_ERROR ;
6272       END IF;
6273 
6274       IF p_charges_detail_rec.line_type_id <> FND_API.G_MISS_NUM AND
6275          p_charges_detail_rec.line_type_id IS NOT NULL THEN
6276         IF p_charges_detail_rec.line_type_id <> l_line_type_id THEN
6277           --RAISE ERROR
6278           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_LINE_TYPE');
6279           FND_MESSAGE.SET_TOKEN('LINE_TYPE_ID', p_charges_detail_rec.line_type_id);
6280           FND_MESSAGE.SET_TOKEN('TXN_LINE_TYPE_ID', l_line_type_id);
6281           FND_MESSAGE.SET_TOKEN('TXN_BILLING_TYPE_ID', x_charges_detail_rec.txn_billing_type_id);
6282           FND_MSG_PUB.ADD;
6283           RAISE FND_API.G_EXC_ERROR;
6284         ELSE --
6285           --the ids match
6286           --assign to the out record
6287           x_charges_detail_rec.line_type_id := p_charges_detail_rec.line_type_id;
6288         END IF;
6289 
6290       ELSE
6291 
6292         -- p_charges_detail_rec.line_type_id is null
6293         -- assign l_line_type_id to out record
6294         x_charges_detail_rec.line_type_id := l_line_type_id;
6295 
6296       END IF;
6297 
6298     ELSE
6299 
6300       -- niether the item nor the transaction type is changed
6301       -- assign the line_type_id from db
6302       x_charges_detail_rec.line_type_id := l_db_det_rec.line_type_id;
6303 
6304     END IF;
6305 
6306     --DBMS_OUTPUT.PUT_LINE('Completed Line Type Id Validation successfully ...');
6307 
6308   END IF;
6309 
6310 
6311 --=====================================
6312 --TCA Validation
6313 --=====================================
6314 --DBMS_OUTPUT.PUT_LINE('TCA Validation ...');
6315 
6316 IF p_validation_mode = 'I' THEN
6317 
6318   -- Bill to Valdation
6319   --
6320   --DBMS_OUTPUT.PUT_LINE('In the the TCA Validation');
6321 
6322   IF p_charges_detail_rec.bill_to_party_id IS NOT NULL THEN
6323 
6324     IF IS_PARTY_VALID(p_party_id      => p_charges_detail_rec.bill_to_party_id,
6325                       x_msg_data         => l_msg_data,
6326                       x_msg_count        => l_msg_count,
6327                       x_return_status    => l_return_status) = 'N' THEN
6328 
6329       Add_Invalid_Argument_Msg(l_api_name,
6330                                to_char(p_charges_detail_rec.bill_to_party_id),
6331                                'Bill_to_Party_Id');
6332       RAISE FND_API.G_EXC_ERROR;
6333 
6334     ELSE
6335       --assign to out record
6336       x_charges_detail_rec.bill_to_party_id := p_charges_detail_rec.bill_to_party_id;
6337 
6338       IF p_charges_detail_rec.bill_to_account_id IS NOT NULL THEN
6339 
6340 
6341          IF IS_ACCOUNT_VALID(p_party_id      => p_charges_detail_rec.bill_to_party_id,
6342                              p_account_id    => p_charges_detail_rec.bill_to_account_id,
6343                              x_msg_data      => l_msg_data,
6344                              x_msg_count     => l_msg_count,
6345                              x_return_status => l_return_status) = 'U' THEN
6346            --raise unexpected error
6347            Raise FND_API.G_EXC_UNEXPECTED_ERROR;
6348            null;
6349          ELSIF IS_ACCOUNT_VALID(p_party_id      => p_charges_detail_rec.bill_to_party_id,
6350                                 p_account_id    => p_charges_detail_rec.bill_to_account_id,
6351                                 x_msg_data      => l_msg_data,
6352                                 x_msg_count     => l_msg_count,
6353                                 x_return_status => l_return_status) = 'N' THEN
6354 
6355            Add_Invalid_Argument_Msg(l_api_name,
6356                                  to_char(p_charges_detail_rec.bill_to_account_id),
6357                                  'Bill_to_Account_Id');
6358            RAISE FND_API.G_EXC_ERROR;
6359            null;
6360          ELSE
6361            -- assign to out record
6362            x_charges_detail_rec.bill_to_account_id := p_charges_detail_rec.bill_to_account_id;
6363          END IF;
6364       ELSE
6365         -- bill_to_account IS NULL
6366         -- assign NULL to out record
6367         x_charges_detail_rec.bill_to_account_id := NULL;
6368       END IF;
6369       IF  p_charges_detail_rec.bill_to_contact_id IS NOT NULL THEN
6370 
6371 
6372         IF IS_CONTACT_VALID(p_party_id      => p_charges_detail_rec.bill_to_party_id,
6373                             p_contact_id    => p_charges_detail_rec.bill_to_contact_id,
6374                             x_msg_data      => l_msg_data,
6375                             x_msg_count     => l_msg_count,
6376                             x_return_status => l_return_status) = 'U' THEN
6377           --raise unexpected error
6378           Raise FND_API.G_EXC_UNEXPECTED_ERROR;
6379           null;
6380 
6381         ELSIF IS_CONTACT_VALID(p_party_id      => p_charges_detail_rec.bill_to_party_id,
6382                                p_contact_id    => p_charges_detail_rec.bill_to_contact_id,
6383                                x_msg_data      => l_msg_data,
6384                                x_msg_count     => l_msg_count,
6385                                x_return_status => l_return_status) = 'N' THEN
6386 
6387           Add_Invalid_Argument_Msg(l_api_name,
6388                                  to_char(p_charges_detail_rec.bill_to_contact_id),
6389                                  'Bill_to_Contact_Id');
6390           RAISE FND_API.G_EXC_ERROR;
6391           null;
6392         ELSE
6393           -- assign to out record
6394           x_charges_detail_rec.bill_to_contact_id := p_charges_detail_rec.bill_to_contact_id;
6395         END IF;
6396       ELSE
6397         -- bill_to_contact IS NULL
6398         -- assign NULL to out record
6399         x_charges_detail_rec.bill_to_contact_id := NULL;
6400       END IF;
6401 
6402       IF p_charges_detail_rec.invoice_to_org_id IS NOT NULL THEN
6403 
6404 
6405         IF IS_PARTY_SITE_VALID( p_party_site_id => p_charges_detail_rec.invoice_to_org_id,
6406                                 p_party_id      => p_charges_detail_rec.bill_to_party_id,
6407                                 p_val_mode      => 'BILL_TO',
6408                                 x_msg_data      => l_msg_data,
6409                                 x_msg_count     => l_msg_count,
6410                                 x_return_status => l_return_status) = 'U' THEN
6411           --raise unexpected error
6412           Raise FND_API.G_EXC_UNEXPECTED_ERROR;
6413           null;
6414         ELSIF IS_PARTY_SITE_VALID( p_party_site_id => p_charges_detail_rec.invoice_to_org_id,
6415                                 p_party_id         => p_charges_detail_rec.bill_to_party_id,
6416                                 p_val_mode         => 'BILL_TO',
6417                                 x_msg_data         => l_msg_data,
6418                                 x_msg_count        => l_msg_count,
6419                                 x_return_status    => l_return_status) = 'N' THEN
6420           Add_Invalid_Argument_Msg(l_api_name,
6421                                  to_char(p_charges_detail_rec.invoice_to_org_id),
6422                                  'Invoice_to_org_Id');
6423           RAISE FND_API.G_EXC_ERROR;
6424           null;
6425         ELSE
6426           --assign to out record
6427           x_charges_detail_rec.invoice_to_org_id := p_charges_detail_rec.invoice_to_org_id;
6428         END IF;
6429 
6430       ELSE
6431         --invoice_to_org_id IS NULL
6432         --assign NULL to out record
6433         x_charges_detail_rec.invoice_to_org_id := NULL;
6434       END IF;
6435     END IF;
6436 
6437   ELSE
6438     -- p_charges_detail_rec.bill_to_party_id IS NULL
6439     -- default TCA information from SR
6440 
6441     --DBMS_OUTPUT.PUT_LINE('p_charges_detail_rec.bill_to_party_id IS NULL............');
6442     --DBMS_OUTPUT.PUT_LINE('l_bill_to_party_id'||l_bill_to_party_id);
6443 
6444     IF l_bill_to_party_id <> -999 THEN
6445 
6446       IF IS_PARTY_VALID(p_party_id         => l_bill_to_party_id,
6447                         x_msg_data         => l_msg_data,
6448                         x_msg_count        => l_msg_count,
6449                         x_return_status    => l_return_status) = 'N' THEN
6450 
6451         Add_Invalid_Argument_Msg(l_api_name,
6452                                  to_char(l_bill_to_party_id),
6453                                  'Bill_to_Party_Id');
6454         RAISE FND_API.G_EXC_ERROR;
6455         null;
6456       ELSE
6457 
6458         --DBMS_OUTPUT.PUT_LINE('l_bill_to_party_id assigned ...' || l_bill_to_party_id);
6459 
6460         --assign to out record
6461         x_charges_detail_rec.bill_to_party_id := l_bill_to_party_id;
6462 
6463         IF l_bill_to_account_id <> -999 THEN
6464           IF IS_ACCOUNT_VALID(p_party_id      => l_bill_to_party_id,
6465                               p_account_id    => l_bill_to_account_id,
6466                               x_msg_data      => l_msg_data,
6467                               x_msg_count     => l_msg_count,
6468                               x_return_status => l_return_status) = 'U' THEN
6469             --raise unexpected error
6470             Raise FND_API.G_EXC_UNEXPECTED_ERROR;
6471             null;
6472 
6473           ELSIF IS_ACCOUNT_VALID(p_party_id      => l_bill_to_party_id,
6474                               p_account_id    => l_bill_to_account_id,
6475                               x_msg_data      => l_msg_data,
6476                               x_msg_count     => l_msg_count,
6477                               x_return_status => l_return_status) = 'N' THEN
6478 
6479              Add_Invalid_Argument_Msg(l_api_name,
6480                                  to_char(l_bill_to_account_id),
6481                                  'Bill_to_Account_Id');
6482              RAISE FND_API.G_EXC_ERROR;
6483              null;
6484            ELSE
6485              --DBMS_OUTPUT.PUT_LINE(' l_bill_to_account_id assigned ....'||l_bill_to_account_id);
6486 
6487              -- assign to out record
6488              x_charges_detail_rec.bill_to_account_id := l_bill_to_account_id;
6489            END IF;
6490         ELSE
6491           --l_bill_to_account is -999
6492           --assign NULL to out record
6493           --DBMS_OUTPUT.PUT_LINE(' l_bill_to_account_id assigned is null ');
6494           x_charges_detail_rec.bill_to_account_id := NULL;
6495 
6496         END IF;
6497 
6498         IF  l_bill_to_contact_id <> -999 THEN
6499           IF IS_CONTACT_VALID(p_party_id      => l_bill_to_party_id,
6500                               p_contact_id    => l_bill_to_contact_id,
6501                               x_msg_data      => l_msg_data,
6502                               x_msg_count     => l_msg_count,
6503                               x_return_status => l_return_status) = 'U' THEN
6504             --raise unexpected error
6505             Raise FND_API.G_EXC_UNEXPECTED_ERROR;
6506             null;
6507 
6508           ELSIF IS_CONTACT_VALID(p_party_id   => l_bill_to_party_id,
6509                               p_contact_id    => l_bill_to_contact_id,
6510                               x_msg_data      => l_msg_data,
6511                               x_msg_count     => l_msg_count,
6512                               x_return_status => l_return_status) = 'N' THEN
6513 
6514             Add_Invalid_Argument_Msg(l_api_name,
6515                                  to_char(l_bill_to_contact_id),
6516                                  'Bill_to_Contact_Id');
6517             RAISE FND_API.G_EXC_ERROR;
6518             null;
6519           ELSE
6520             -- assign to out record
6521             --DBMS_OUTPUT.PUT_LINE(' l_bill_to_contact_id assigned....'||l_bill_to_contact_id);
6522 
6523             x_charges_detail_rec.bill_to_contact_id := l_bill_to_contact_id;
6524           END IF;
6525         ELSE
6526           --l_bill_to_contact_id IS NULL
6527           --assign NULL to out record
6528           --DBMS_OUTPUT.PUT_LINE(' l_bill_to_contact_id assigned null');
6529           x_charges_detail_rec.bill_to_contact_id := NULL;
6530         END IF;
6531 
6532         IF  l_bill_to_site_id <> -999 THEN
6533           x_charges_detail_rec.invoice_to_org_id := l_bill_to_site_id;
6534         ELSE
6535           --l_bill_to_site_use_id IS NULL
6536           --assign NULL to the out record
6537           --assign the customer_site_id
6538           x_charges_detail_rec.invoice_to_org_id := l_customer_site_id;
6539         END IF;
6540         --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.invoice_to_org_id ...'||x_charges_detail_rec.invoice_to_org_id);
6541 
6542       END IF;
6543     ELSE
6544       --l_bill_to_party_id is -999
6545       --Check If l_customer_id is not null
6546       IF l_customer_id IS NOT NULL THEN
6547 
6548         IF IS_PARTY_VALID(p_party_id      => l_customer_id,
6549                           x_msg_data      => l_msg_data,
6550                           x_msg_count     => l_msg_count,
6551                           x_return_status => l_return_status) = 'N' THEN
6552 
6553           Add_Invalid_Argument_Msg(l_api_name,
6554                                  to_char(l_customer_id),
6555                                  'Bill_to_Party_Id');
6556           RAISE FND_API.G_EXC_ERROR;
6557           null;
6558         ELSE
6559           --assign to out record
6560           x_charges_detail_rec.bill_to_party_id := l_customer_id;
6561           -- Fix For Bug 6356247--Start
6562 	  --x_charges_detail_rec.bill_to_contact_id := l_customer_id;
6563 	  x_charges_detail_rec.bill_to_contact_id := Null;
6564 	  -- Fix For Bug 6356247--End
6565 
6566           IF l_account_id IS NOT NULL THEN
6567 
6568 
6569             IF IS_ACCOUNT_VALID(p_party_id      => l_customer_id,
6570                                 p_account_id    => l_account_id,
6571                                 x_msg_data      => l_msg_data,
6572                                 x_msg_count     => l_msg_count,
6573                                 x_return_status => l_return_status) = 'U' THEN
6574               --raise unexpected error
6575               Raise FND_API.G_EXC_UNEXPECTED_ERROR;
6576               null;
6577 
6578             ELSIF IS_ACCOUNT_VALID(p_party_id      => l_customer_id,
6579                                 p_account_id    => l_account_id,
6580                                 x_msg_data      => l_msg_data,
6581                                 x_msg_count     => l_msg_count,
6582                                 x_return_status => l_return_status) = 'N' THEN
6583 
6584               Add_Invalid_Argument_Msg(l_api_name,
6585                                  to_char(l_account_id),
6586                                  'Bill_to_Account_Id');
6587               RAISE FND_API.G_EXC_ERROR;
6588               null;
6589             ELSE
6590               -- assign to out record
6591               x_charges_detail_rec.bill_to_account_id :=l_account_id;
6592             END IF;
6593           END IF;
6594 
6595           IF l_customer_site_id IS NOT NULL THEN
6596 
6597             IF IS_PARTY_SITE_VALID( p_party_site_id => l_customer_site_id,
6598                                     p_party_id      => l_customer_id,
6599                                     p_val_mode      => 'NONE',
6600                                     x_msg_data      => l_msg_data,
6601                                     x_msg_count     => l_msg_count,
6602                                     x_return_status => l_return_status) = 'U' THEN
6603               --raise unexpected error
6604               Raise FND_API.G_EXC_UNEXPECTED_ERROR;
6605               null;
6606             ELSIF IS_PARTY_SITE_VALID( p_party_site_id => l_customer_site_id,
6607                                     p_party_id      => l_customer_id,
6608                                     p_val_mode      => 'NONE',
6609                                     x_msg_data      => l_msg_data,
6610                                     x_msg_count     => l_msg_count,
6611                                     x_return_status => l_return_status) = 'N' THEN
6612 
6613               Add_Invalid_Argument_Msg(l_api_name,
6614                                  to_char(l_customer_site_id),
6615                                  'Invoice_to_Org_Id');
6616               RAISE FND_API.G_EXC_ERROR;
6617               null;
6618             ELSE
6619               --assign to out record
6620               x_charges_detail_rec.invoice_to_org_id := l_customer_site_id;
6621             END IF;
6622           ELSE
6623             --l_customer_site_id IS NULL
6624             --assign NULL to out record
6625             x_charges_detail_rec.invoice_to_org_id := NULL;
6626           END IF;
6627         END IF;
6628       ELSE
6629         x_charges_detail_rec.bill_to_party_id   := NULL;
6630         x_charges_detail_rec.bill_to_account_id := NULL;
6631         x_charges_detail_rec.bill_to_contact_id := NULL;
6632         x_charges_detail_rec.invoice_to_org_id  := NULL;
6633       END IF;
6634     END IF;
6635   END IF;
6636 
6637   --DBMS_OUTPUT.PUT_LINE('Passed Bill To Validation .....');
6638 
6639   -- Ship To Validation
6640   --
6641   --DBMS_OUTPUT.PUT_LINE(' ship tp party id '||p_charges_detail_rec.ship_to_party_id );
6642 
6643   IF p_charges_detail_rec.ship_to_party_id IS NOT NULL THEN
6644 
6645     IF IS_PARTY_VALID(p_party_id   => p_charges_detail_rec.ship_to_party_id,
6646                       x_msg_data      => l_msg_data,
6647                       x_msg_count     => l_msg_count,
6648                       x_return_status => l_return_status) = 'N' THEN
6649 
6650 
6651        Add_Invalid_Argument_Msg(l_api_name,
6652                                  to_char(p_charges_detail_rec.ship_to_party_id),
6653                                  'Ship_to_Party_Id');
6654 
6655         x_msg_data      :=  l_msg_data;
6656         x_return_status :=  l_return_status;
6657 
6658        RAISE FND_API.G_EXC_ERROR;
6659 
6660     ELSE
6661 
6662       --DBMS_OUTPUT.PUT_LINE('Assigning the ship_to_party_id '||p_charges_detail_rec.ship_to_party_id);
6663 
6664       --assign to out record
6665       x_charges_detail_rec.ship_to_party_id := p_charges_detail_rec.ship_to_party_id;
6666 
6667       IF p_charges_detail_rec.ship_to_account_id IS NOT NULL THEN
6668 
6669          IF IS_ACCOUNT_VALID(p_party_id         => p_charges_detail_rec.ship_to_party_id,
6670                              p_account_id       => p_charges_detail_rec.ship_to_account_id,
6671                              x_msg_data         => l_msg_data,
6672                              x_msg_count        => l_msg_count,
6673                              x_return_status    => l_return_status) = 'U' THEN
6674            --raise unexpected error
6675            Raise FND_API.G_EXC_UNEXPECTED_ERROR;
6676            null;
6677 
6678          ELSIF IS_ACCOUNT_VALID(p_party_id      => p_charges_detail_rec.ship_to_party_id,
6679                              p_account_id       => p_charges_detail_rec.ship_to_account_id,
6680                              x_msg_data         => l_msg_data,
6681                              x_msg_count        => l_msg_count,
6682                              x_return_status    => l_return_status) = 'N' THEN
6683 
6684            Add_Invalid_Argument_Msg(l_api_name,
6685                                  to_char(p_charges_detail_rec.ship_to_account_id),
6686                                  'Ship_to_Account_Id');
6687 
6688            x_msg_data      :=  l_msg_data;
6689            x_return_status :=  l_return_status;
6690 
6691            RAISE FND_API.G_EXC_ERROR;
6692          ELSE
6693            -- assign to out record
6694            x_charges_detail_rec.ship_to_account_id := p_charges_detail_rec.ship_to_account_id;
6695          END IF;
6696       ELSE
6697         -- Ship To Account ID is NULL
6698         -- assign NULL to out record
6699         x_charges_detail_rec.ship_to_account_id := NULL;
6700       END IF;
6701 
6702       IF  p_charges_detail_rec.ship_to_contact_id IS NOT NULL THEN
6703 
6704         IF IS_CONTACT_VALID(p_party_id      => p_charges_detail_rec.ship_to_party_id,
6705                             p_contact_id    => p_charges_detail_rec.ship_to_contact_id,
6706                             x_msg_data      => l_msg_data,
6707                             x_msg_count     => l_msg_count,
6708                             x_return_status => l_return_status) = 'U' THEN
6709           --raise unexpected error
6710           Raise FND_API.G_EXC_UNEXPECTED_ERROR;
6711           null;
6712         ELSIF IS_CONTACT_VALID(p_party_id   => p_charges_detail_rec.ship_to_party_id,
6713                             p_contact_id    => p_charges_detail_rec.ship_to_contact_id,
6714                             x_msg_data      => l_msg_data,
6715                             x_msg_count     => l_msg_count,
6716                             x_return_status => l_return_status) = 'N' THEN
6717 
6718           Add_Invalid_Argument_Msg(l_api_name,
6719                                  to_char(p_charges_detail_rec.ship_to_contact_id),
6720                                  'Ship_to_Contact_Id');
6721           RAISE FND_API.G_EXC_ERROR;
6722 
6723         ELSE
6724           -- assign to out record
6725           x_charges_detail_rec.ship_to_contact_id := p_charges_detail_rec.ship_to_contact_id;
6726         END IF;
6727       ELSE
6728         -- Ship To Contact is NULL
6729         -- assign NULL to out record
6730         x_charges_detail_rec.ship_to_contact_id := NULL;
6731       END IF;
6732 
6733       IF p_charges_detail_rec.ship_to_org_id IS NOT NULL THEN
6734 
6735 
6736         IF IS_PARTY_SITE_VALID( p_party_site_id => p_charges_detail_rec.ship_to_org_id,
6737                                 p_party_id      => p_charges_detail_rec.ship_to_party_id,
6738                                 p_val_mode      => 'SHIP_TO',
6739                                 x_msg_data      => l_msg_data,
6740                                 x_msg_count     => l_msg_count,
6741                                 x_return_status => l_return_status) = 'U' THEN
6742           --raise unexpected error
6743           Raise FND_API.G_EXC_UNEXPECTED_ERROR;
6744           null;
6745         ELSIF IS_PARTY_SITE_VALID( p_party_site_id => p_charges_detail_rec.ship_to_org_id,
6746                                 p_party_id         => p_charges_detail_rec.ship_to_party_id,
6747                                 p_val_mode         => 'SHIP_TO',
6748                                 x_msg_data         => l_msg_data,
6749                                 x_msg_count        => l_msg_count,
6750                                 x_return_status    => l_return_status) = 'N' THEN
6751 
6752           Add_Invalid_Argument_Msg(l_api_name,
6753                                  to_char(p_charges_detail_rec.ship_to_org_id),
6754                                  'Ship_to_org_Id');
6755           RAISE FND_API.G_EXC_ERROR;
6756           null;
6757         ELSE
6758           --assign to out record
6759           x_charges_detail_rec.ship_to_org_id := p_charges_detail_rec.ship_to_org_id;
6760         END IF;
6761 
6762       ELSE
6763         --ship_to_org_id IS NULL
6764         --assign NULL to out record
6765         x_charges_detail_rec.ship_to_org_id := NULL;
6766       END IF;
6767 
6768     END IF;
6769 
6770   ELSE
6771     -- p_charges_detail_rec.ship_to_party_id IS NULL
6772     -- default TCA information from SR
6773 
6774     --DBMS_OUTPUT.PUT_LINE('ship to party id is null');
6775 
6776     IF l_ship_to_party_id <> -999 THEN
6777       IF IS_PARTY_VALID(p_party_id   => l_ship_to_party_id,
6778                         x_msg_data      => l_msg_data,
6779                         x_msg_count     => l_msg_count,
6780                         x_return_status => l_return_status) = 'N' THEN
6781         RAISE FND_API.G_EXC_ERROR;
6782         null;
6783       ELSE
6784         --assign to out record
6785         x_charges_detail_rec.ship_to_party_id := l_ship_to_party_id;
6786 
6787         IF l_ship_to_account_id <> -999 THEN
6788 
6789 
6790           IF IS_ACCOUNT_VALID(p_party_id      => l_ship_to_party_id,
6791                               p_account_id    => l_ship_to_account_id,
6792                               x_msg_data      => l_msg_data,
6793                               x_msg_count     => l_msg_count,
6794                               x_return_status => l_return_status) = 'U' THEN
6795             --raise unexpected error
6796             Raise FND_API.G_EXC_UNEXPECTED_ERROR;
6797             null;
6798 
6799           ELSIF IS_ACCOUNT_VALID(p_party_id   => l_ship_to_party_id,
6800                               p_account_id    => l_ship_to_account_id,
6801                               x_msg_data      => l_msg_data,
6802                               x_msg_count     => l_msg_count,
6803                               x_return_status => l_return_status) = 'N' THEN
6804              Add_Invalid_Argument_Msg(l_api_name,
6805                                  to_char(l_ship_to_account_id),
6806                                  'Ship_to_Account_Id');
6807 
6808              x_msg_data      :=  l_msg_data;
6809              x_return_status :=  l_return_status;
6810 
6811              RAISE FND_API.G_EXC_ERROR;
6812           ELSE
6813              -- assign to out record
6814              x_charges_detail_rec.ship_to_account_id := l_ship_to_account_id;
6815           END IF;
6816         ELSE
6817           -- Ship To Account is -999
6818           -- assign NULL to out record
6819            x_charges_detail_rec.ship_to_account_id := NULL;
6820         END IF;
6821 
6822         IF  l_ship_to_contact_id <> -999 THEN
6823 
6824           IF IS_CONTACT_VALID(p_party_id      => l_ship_to_party_id,
6825                               p_contact_id    => l_ship_to_contact_id,
6826                               x_msg_data      => l_msg_data,
6827                               x_msg_count     => l_msg_count,
6828                               x_return_status => l_return_status) = 'U' THEN
6829             --raise unexpected error
6830             Raise FND_API.G_EXC_UNEXPECTED_ERROR;
6831             null;
6832 
6833           ELSIF IS_CONTACT_VALID(p_party_id   => l_ship_to_party_id,
6834                               p_contact_id    => l_ship_to_contact_id,
6835                               x_msg_data      => l_msg_data,
6836                               x_msg_count     => l_msg_count,
6837                               x_return_status => l_return_status) = 'N' THEN
6838 
6839             Add_Invalid_Argument_Msg(l_api_name,
6840                                  to_char(l_ship_to_contact_id),
6841                                  'Ship_to_Contact_Id');
6842             RAISE FND_API.G_EXC_ERROR;
6843           ELSE
6844             -- assign to out record
6845             x_charges_detail_rec.ship_to_contact_id := l_ship_to_contact_id;
6846           END IF;
6847         ELSE
6848           -- Ship To Contact is -999
6849           -- assign NULL to out record
6850           x_charges_detail_rec.ship_to_contact_id := NULL;
6851         END IF;
6852 
6853         IF  l_ship_to_site_id <> -999 THEN
6854           x_charges_detail_rec.ship_to_org_id := l_ship_to_site_id;
6855         ELSE
6856           --l_ship_to_site_use_id IS NULL
6857           --assign l_customer_site_id
6858           x_charges_detail_rec.ship_to_org_id := l_customer_site_id;
6859         END IF;
6860 
6861       END IF;
6862     ELSE
6863       --l_ship_to_party_id is -999
6864       --Check If l_customer_id is not null
6865       IF l_customer_id IS NOT NULL THEN
6866 
6867         IF IS_PARTY_VALID(p_party_id   => l_customer_id,
6868                           x_msg_data      => l_msg_data,
6869                           x_msg_count     => l_msg_count,
6870                           x_return_status => l_return_status) = 'N' THEN
6871           RAISE FND_API.G_EXC_ERROR;
6872           null;
6873         ELSE
6874           --assign to out record
6875           x_charges_detail_rec.ship_to_party_id := l_customer_id;
6876 	  --Fix for Bug 6356247--Start
6877           --x_charges_detail_rec.ship_to_contact_id := l_customer_id;
6878 	  x_charges_detail_rec.ship_to_contact_id := Null;
6879 	  --Fix for Bug 6356247--End
6880 
6881           IF l_account_id IS NOT NULL THEN
6882 
6883             IF IS_ACCOUNT_VALID(p_party_id      => l_customer_id,
6884                                 p_account_id    => l_account_id,
6885                                 x_msg_data      => l_msg_data,
6886                                 x_msg_count     => l_msg_count,
6887                                 x_return_status => l_return_status) = 'U' THEN
6888               --raise unexpected error
6889               Raise FND_API.G_EXC_UNEXPECTED_ERROR;
6890               null;
6891 
6892             ELSIF IS_ACCOUNT_VALID(p_party_id   => l_customer_id,
6893                                 p_account_id    => l_account_id,
6894                                 x_msg_data      => l_msg_data,
6895                                 x_msg_count     => l_msg_count,
6896                                 x_return_status => l_return_status) = 'N' THEN
6897 
6898                Add_Invalid_Argument_Msg(l_api_name,
6899                                  to_char(l_account_id),
6900                                  'Ship_to_Account_Id');
6901 
6902                x_msg_data      :=  l_msg_data;
6903                x_return_status :=  l_return_status;
6904 
6905                RAISE FND_API.G_EXC_ERROR;
6906             ELSE
6907               -- assign to out record
6908               x_charges_detail_rec.ship_to_account_id := l_account_id;
6909             END IF;
6910           ELSE
6911             -- Account is NULL
6912             -- assign NULL to out record
6913             x_charges_detail_rec.ship_to_account_id := NULL;
6914           END IF;
6915 
6916           IF l_customer_site_id IS NOT NULL THEN
6917 
6918             IF IS_PARTY_SITE_VALID( p_party_site_id => l_customer_site_id,
6919                                     p_party_id      => l_customer_id,
6920                                     p_val_mode      => 'NONE',
6921                                     x_msg_data      => l_msg_data,
6922                                     x_msg_count     => l_msg_count,
6923                                     x_return_status => l_return_status) = 'U' THEN
6924               --raise unexpected error
6925               Raise FND_API.G_EXC_UNEXPECTED_ERROR;
6926               null;
6927 
6928             ELSIF IS_PARTY_SITE_VALID( p_party_site_id => l_customer_site_id,
6929                                     p_party_id      => l_customer_id,
6930                                     p_val_mode      => 'NONE',
6931                                     x_msg_data      => l_msg_data,
6932                                     x_msg_count     => l_msg_count,
6933                                     x_return_status => l_return_status) = 'N' THEN
6934               RAISE FND_API.G_EXC_ERROR;
6935               null;
6936             ELSE
6937               --assign to out record
6938               x_charges_detail_rec.ship_to_org_id := l_customer_site_id;
6939             END IF;
6940           ELSE
6941             --l_customer_site_id IS NULL
6942             --assign NULL to out record
6943             x_charges_detail_rec.ship_to_org_id := NULL;
6944           END IF;
6945 
6946         END IF;
6947       ELSE
6948         x_charges_detail_rec.ship_to_party_id := NULL;
6949         x_charges_detail_rec.ship_to_account_id := NULL;
6950         x_charges_detail_rec.ship_to_contact_id := NULL;
6951         x_charges_detail_rec.ship_to_org_id  := NULL;
6952       END IF;
6953     END IF;
6954   END IF;
6955   --DBMS_OUTPUT.PUT_LINE('Passed Ship To Validation .....');
6956 
6957 ELSIF p_validation_mode = 'U' THEN
6958 
6959   -- Bill to Valdation
6960   --
6961   --DBMS_OUTPUT.PUT_LINE('In the the TCA Update Validation');
6962 
6963   IF p_charges_detail_rec.bill_to_party_id <> FND_API.G_MISS_NUM AND
6964      p_charges_detail_rec.bill_to_party_id IS NOT NULL THEN
6965 
6966     IF IS_PARTY_VALID(p_party_id      => p_charges_detail_rec.bill_to_party_id,
6967                       x_msg_data         => l_msg_data,
6968                       x_msg_count        => l_msg_count,
6969                       x_return_status    => l_return_status) = 'N' THEN
6970 
6971       Add_Invalid_Argument_Msg(l_api_name,
6972                                to_char(p_charges_detail_rec.bill_to_party_id),
6973                                'Bill_to_Party_Id');
6974       RAISE FND_API.G_EXC_ERROR;
6975 
6976     ELSE
6977       --assign to out record
6978       x_charges_detail_rec.bill_to_party_id := p_charges_detail_rec.bill_to_party_id;
6979 
6980       IF p_charges_detail_rec.bill_to_account_id <> FND_API.G_MISS_NUM AND
6981          p_charges_detail_rec.bill_to_account_id IS NOT NULL THEN
6982 
6983          IF IS_ACCOUNT_VALID(p_party_id      => p_charges_detail_rec.bill_to_party_id,
6984                              p_account_id    => p_charges_detail_rec.bill_to_account_id,
6985                              x_msg_data      => l_msg_data,
6986                              x_msg_count     => l_msg_count,
6987                              x_return_status => l_return_status) = 'U' THEN
6988            --raise unexpected error
6989            Raise FND_API.G_EXC_UNEXPECTED_ERROR;
6990            null;
6991          ELSIF IS_ACCOUNT_VALID(p_party_id      => p_charges_detail_rec.bill_to_party_id,
6992                                 p_account_id    => p_charges_detail_rec.bill_to_account_id,
6993                                 x_msg_data      => l_msg_data,
6994                                 x_msg_count     => l_msg_count,
6995                                 x_return_status => l_return_status) = 'N' THEN
6996 
6997            Add_Invalid_Argument_Msg(l_api_name,
6998                                  to_char(p_charges_detail_rec.bill_to_account_id),
6999                                  'Bill_to_Account_Id');
7000            RAISE FND_API.G_EXC_ERROR;
7001            null;
7002          ELSE
7003            -- assign to out record
7004            x_charges_detail_rec.bill_to_account_id := p_charges_detail_rec.bill_to_account_id;
7005          END IF;
7006 
7007 --Bug# 4870037
7008       ELSIF p_charges_detail_rec.bill_to_account_id = FND_API.G_MISS_NUM THEN
7009          x_charges_detail_rec.bill_to_account_id := l_db_det_rec.invoice_to_account_id;
7010       ELSE
7011         -- bill_to_account IS NULL
7012         -- assign NULL to out record
7013         x_charges_detail_rec.bill_to_account_id := NULL;
7014       END IF;
7015       IF  p_charges_detail_rec.bill_to_contact_id <> FND_API.G_MISS_NUM AND
7016           p_charges_detail_rec.bill_to_contact_id IS NOT NULL THEN
7017 
7018 
7019         IF IS_CONTACT_VALID(p_party_id      => p_charges_detail_rec.bill_to_party_id,
7020                             p_contact_id    => p_charges_detail_rec.bill_to_contact_id,
7021                             x_msg_data      => l_msg_data,
7022                             x_msg_count     => l_msg_count,
7023                             x_return_status => l_return_status) = 'U' THEN
7024           --raise unexpected error
7025           Raise FND_API.G_EXC_UNEXPECTED_ERROR;
7026           null;
7027 
7028         ELSIF IS_CONTACT_VALID(p_party_id      => p_charges_detail_rec.bill_to_party_id,
7029                                p_contact_id    => p_charges_detail_rec.bill_to_contact_id,
7030                                x_msg_data      => l_msg_data,
7031                                x_msg_count     => l_msg_count,
7032                                x_return_status => l_return_status) = 'N' THEN
7033 
7034           Add_Invalid_Argument_Msg(l_api_name,
7035                                  to_char(p_charges_detail_rec.bill_to_contact_id),
7036                                  'Bill_to_Contact_Id');
7037           RAISE FND_API.G_EXC_ERROR;
7038           null;
7039         ELSE
7040           -- assign to out record
7041           x_charges_detail_rec.bill_to_contact_id := p_charges_detail_rec.bill_to_contact_id;
7042         END IF;
7043       ELSE
7044         -- bill_to_contact IS NULL
7045         -- assign NULL to out record
7046         x_charges_detail_rec.bill_to_contact_id := NULL;
7047       END IF;
7048 
7049       IF p_charges_detail_rec.invoice_to_org_id <> FND_API.G_MISS_NUM AND
7050          p_charges_detail_rec.invoice_to_org_id IS NOT NULL THEN
7051 
7052 
7053         IF IS_PARTY_SITE_VALID( p_party_site_id => p_charges_detail_rec.invoice_to_org_id,
7054                                 p_party_id      => p_charges_detail_rec.bill_to_party_id,
7055                                 p_val_mode      => 'BILL_TO',
7056                                 x_msg_data      => l_msg_data,
7057                                 x_msg_count     => l_msg_count,
7058                                 x_return_status => l_return_status) = 'U' THEN
7059           --raise unexpected error
7060           Raise FND_API.G_EXC_UNEXPECTED_ERROR;
7061           null;
7062         ELSIF IS_PARTY_SITE_VALID( p_party_site_id => p_charges_detail_rec.invoice_to_org_id,
7063                                 p_party_id         => p_charges_detail_rec.bill_to_party_id,
7064                                 p_val_mode         => 'BILL_TO',
7065                                 x_msg_data         => l_msg_data,
7066                                 x_msg_count        => l_msg_count,
7067                                 x_return_status    => l_return_status) = 'N' THEN
7068           Add_Invalid_Argument_Msg(l_api_name,
7069                                  to_char(p_charges_detail_rec.invoice_to_org_id),
7070                                  'Invoice_to_org_Id');
7071           RAISE FND_API.G_EXC_ERROR;
7072           null;
7073         ELSE
7074           --assign to out record
7075           x_charges_detail_rec.invoice_to_org_id := p_charges_detail_rec.invoice_to_org_id;
7076         END IF;
7077 
7078       ELSE
7079         --invoice_to_org_id IS NULL
7080         --assign NULL to out record
7081         x_charges_detail_rec.invoice_to_org_id := NULL;
7082       END IF;
7083     END IF;
7084 
7085  ELSIF
7086 
7087      p_charges_detail_rec.bill_to_party_id = FND_API.G_MISS_NUM THEN
7088 
7089       -- assign the value from the database
7090       x_charges_detail_rec.bill_to_party_id := l_db_det_rec.bill_to_party_id;
7091 
7092       IF p_charges_detail_rec.bill_to_account_id <> FND_API.G_MISS_NUM AND
7093          p_charges_detail_rec.bill_to_account_id IS NOT NULL THEN
7094 
7095 
7096          IF IS_ACCOUNT_VALID(p_party_id      => x_charges_detail_rec.bill_to_party_id,
7097                              p_account_id    => p_charges_detail_rec.bill_to_account_id,
7098                              x_msg_data      => l_msg_data,
7099                              x_msg_count     => l_msg_count,
7100                              x_return_status => l_return_status) = 'U' THEN
7101            --raise unexpected error
7102            Raise FND_API.G_EXC_UNEXPECTED_ERROR;
7103            null;
7104          ELSIF IS_ACCOUNT_VALID(p_party_id      => x_charges_detail_rec.bill_to_party_id,
7105                                 p_account_id    => p_charges_detail_rec.bill_to_account_id,
7106                                 x_msg_data      => l_msg_data,
7107                                 x_msg_count     => l_msg_count,
7108                                 x_return_status => l_return_status) = 'N' THEN
7109 
7110            Add_Invalid_Argument_Msg(l_api_name,
7111                                  to_char(p_charges_detail_rec.bill_to_account_id),
7112                                  'Bill_to_Account_Id');
7113            RAISE FND_API.G_EXC_ERROR;
7114            null;
7115          ELSE
7116            -- assign to out record
7117            x_charges_detail_rec.bill_to_account_id := p_charges_detail_rec.bill_to_account_id;
7118          END IF;
7119       ELSE
7120         -- bill_to_account is not passed
7121         -- assign the value from the database
7122         x_charges_detail_rec.bill_to_account_id := l_db_det_rec.invoice_to_account_id;
7123       END IF;
7124 
7125       IF  p_charges_detail_rec.bill_to_contact_id <> FND_API.G_MISS_NUM AND
7126           p_charges_detail_rec.bill_to_contact_id IS NOT NULL THEN
7127 
7128 
7129         IF IS_CONTACT_VALID(p_party_id      => x_charges_detail_rec.bill_to_party_id,
7130                             p_contact_id    => p_charges_detail_rec.bill_to_contact_id,
7131                             x_msg_data      => l_msg_data,
7132                             x_msg_count     => l_msg_count,
7133                             x_return_status => l_return_status) = 'U' THEN
7134           --raise unexpected error
7135           Raise FND_API.G_EXC_UNEXPECTED_ERROR;
7136           null;
7137 
7138         ELSIF IS_CONTACT_VALID(p_party_id      => x_charges_detail_rec.bill_to_party_id,
7139                                p_contact_id    => p_charges_detail_rec.bill_to_contact_id,
7140                                x_msg_data      => l_msg_data,
7141                                x_msg_count     => l_msg_count,
7142                                x_return_status => l_return_status) = 'N' THEN
7143 
7144           Add_Invalid_Argument_Msg(l_api_name,
7145                                  to_char(p_charges_detail_rec.bill_to_contact_id),
7146                                  'Bill_to_Contact_Id');
7147           RAISE FND_API.G_EXC_ERROR;
7148           null;
7149         ELSE
7150           -- assign to out record
7151           x_charges_detail_rec.bill_to_contact_id := p_charges_detail_rec.bill_to_contact_id;
7152         END IF;
7153       ELSE
7154         -- bill_to_contact is not passed
7155         -- assign values from the database to out record
7156         x_charges_detail_rec.bill_to_contact_id := l_db_det_rec.bill_to_contact_id;
7157       END IF;
7158 
7159       IF p_charges_detail_rec.invoice_to_org_id <> FND_API.G_MISS_NUM AND
7160          p_charges_detail_rec.invoice_to_org_id IS NOT NULL THEN
7161 
7162 
7163         IF IS_PARTY_SITE_VALID( p_party_site_id => p_charges_detail_rec.invoice_to_org_id,
7164                                 p_party_id      => x_charges_detail_rec.bill_to_party_id,
7165                                 p_val_mode      => 'BILL_TO',
7166                                 x_msg_data      => l_msg_data,
7167                                 x_msg_count     => l_msg_count,
7168                                 x_return_status => l_return_status) = 'U' THEN
7169           --raise unexpected error
7170           Raise FND_API.G_EXC_UNEXPECTED_ERROR;
7171           null;
7172         ELSIF IS_PARTY_SITE_VALID( p_party_site_id => p_charges_detail_rec.invoice_to_org_id,
7173                                 p_party_id         => x_charges_detail_rec.bill_to_party_id,
7174                                 p_val_mode         => 'BILL_TO',
7175                                 x_msg_data         => l_msg_data,
7176                                 x_msg_count        => l_msg_count,
7177                                 x_return_status    => l_return_status) = 'N' THEN
7178           Add_Invalid_Argument_Msg(l_api_name,
7179                                  to_char(p_charges_detail_rec.invoice_to_org_id),
7180                                  'Invoice_to_org_Id');
7181           RAISE FND_API.G_EXC_ERROR;
7182           null;
7183         ELSE
7184           --assign to out record
7185           x_charges_detail_rec.invoice_to_org_id := p_charges_detail_rec.invoice_to_org_id;
7186         END IF;
7187 
7188       ELSE
7189         --invoice_to_org_id is not passed
7190         --assign values from the database to out record
7191         x_charges_detail_rec.invoice_to_org_id :=  l_db_det_rec.invoice_to_org_id;
7192       END IF;
7193 
7194  ELSE
7195 
7196     IF p_charges_detail_rec.bill_to_party_id IS NULL THEN
7197 
7198       --all the values for out record for TCA should be nulled out
7199       x_charges_detail_rec.bill_to_party_id := NULL;
7200       x_charges_detail_rec.bill_to_account_id := NULL;
7201       x_charges_detail_rec.bill_to_contact_id := NULL;
7202       x_charges_detail_rec.invoice_to_org_id := NULL;
7203     END IF;
7204   END IF;
7205 
7206 
7207   IF p_charges_detail_rec.ship_to_party_id <> FND_API.G_MISS_NUM AND
7208      p_charges_detail_rec.ship_to_party_id IS NOT NULL THEN
7209 
7210     IF IS_PARTY_VALID(p_party_id      => p_charges_detail_rec.ship_to_party_id,
7211                       x_msg_data         => l_msg_data,
7212                       x_msg_count        => l_msg_count,
7213                       x_return_status    => l_return_status) = 'N' THEN
7214 
7215       Add_Invalid_Argument_Msg(l_api_name,
7216                                to_char(p_charges_detail_rec.ship_to_party_id),
7217                                'ship_to_party_id');
7218       RAISE FND_API.G_EXC_ERROR;
7219 
7220     ELSE
7221       --assign to out record
7222       x_charges_detail_rec.ship_to_party_id := p_charges_detail_rec.ship_to_party_id;
7223 
7224       IF p_charges_detail_rec.ship_to_account_id <> FND_API.G_MISS_NUM AND
7225          p_charges_detail_rec.ship_to_account_id IS NOT NULL THEN
7226 
7227          IF IS_ACCOUNT_VALID(p_party_id      => p_charges_detail_rec.ship_to_party_id,
7228                              p_account_id    => p_charges_detail_rec.ship_to_account_id,
7229                              x_msg_data      => l_msg_data,
7230                              x_msg_count     => l_msg_count,
7231                              x_return_status => l_return_status) = 'U' THEN
7232            --raise unexpected error
7233            Raise FND_API.G_EXC_UNEXPECTED_ERROR;
7234            null;
7235          ELSIF IS_ACCOUNT_VALID(p_party_id      => p_charges_detail_rec.ship_to_party_id,
7236                                 p_account_id    => p_charges_detail_rec.ship_to_account_id,
7237                                 x_msg_data      => l_msg_data,
7238                                 x_msg_count     => l_msg_count,
7239                                 x_return_status => l_return_status) = 'N' THEN
7240 
7241            Add_Invalid_Argument_Msg(l_api_name,
7242                                  to_char(p_charges_detail_rec.ship_to_account_id),
7243                                  'ship_to_account_id');
7244            RAISE FND_API.G_EXC_ERROR;
7245            null;
7246          ELSE
7247            -- assign to out record
7248            x_charges_detail_rec.ship_to_account_id := p_charges_detail_rec.ship_to_account_id;
7249          END IF;
7250 
7251       --Bug# 4870037
7252       ELSIF p_charges_detail_rec.ship_to_account_id = FND_API.G_MISS_NUM THEN
7253           x_charges_detail_rec.ship_to_account_id := l_db_det_rec.ship_to_account_id;
7254       ELSE
7255         -- ship_to_account IS NULL
7256         -- assign NULL to out record
7257         x_charges_detail_rec.ship_to_account_id := NULL;
7258       END IF;
7259       IF  p_charges_detail_rec.ship_to_contact_id <> FND_API.G_MISS_NUM AND
7260           p_charges_detail_rec.ship_to_contact_id IS NOT NULL THEN
7261 
7262 
7263         IF IS_CONTACT_VALID(p_party_id      => p_charges_detail_rec.ship_to_party_id,
7264                             p_contact_id    => p_charges_detail_rec.ship_to_contact_id,
7265                             x_msg_data      => l_msg_data,
7266                             x_msg_count     => l_msg_count,
7267                             x_return_status => l_return_status) = 'U' THEN
7268           --raise unexpected error
7269           Raise FND_API.G_EXC_UNEXPECTED_ERROR;
7270           null;
7271 
7272         ELSIF IS_CONTACT_VALID(p_party_id      => p_charges_detail_rec.ship_to_party_id,
7273                                p_contact_id    => p_charges_detail_rec.ship_to_contact_id,
7274                                x_msg_data      => l_msg_data,
7275                                x_msg_count     => l_msg_count,
7276                                x_return_status => l_return_status) = 'N' THEN
7277 
7278           Add_Invalid_Argument_Msg(l_api_name,
7279                                  to_char(p_charges_detail_rec.ship_to_contact_id),
7280                                  'ship_to_contact_id');
7281           RAISE FND_API.G_EXC_ERROR;
7282           null;
7283         ELSE
7284           -- assign to out record
7285           x_charges_detail_rec.ship_to_contact_id := p_charges_detail_rec.ship_to_contact_id;
7286         END IF;
7287       ELSE
7288         -- ship_to_contact IS NULL
7289         -- assign NULL to out record
7290         x_charges_detail_rec.ship_to_contact_id := NULL;
7291       END IF;
7292 
7293        -- Fixed Bug # 3325675
7294       IF p_charges_detail_rec.ship_to_org_id <> FND_API.G_MISS_NUM AND
7295          p_charges_detail_rec.ship_to_org_id IS NOT NULL THEN
7296 
7297 
7298         IF IS_PARTY_SITE_VALID( p_party_site_id => p_charges_detail_rec.ship_to_org_id,
7299                                 p_party_id      => p_charges_detail_rec.ship_to_party_id,
7300                                 p_val_mode      => 'SHIP_TO',
7301                                 x_msg_data      => l_msg_data,
7302                                 x_msg_count     => l_msg_count,
7303                                 x_return_status => l_return_status) = 'U' THEN
7304           --raise unexpected error
7305           Raise FND_API.G_EXC_UNEXPECTED_ERROR;
7306           null;
7307         ELSIF IS_PARTY_SITE_VALID( p_party_site_id => p_charges_detail_rec.ship_to_org_id,
7308                                 p_party_id         => p_charges_detail_rec.ship_to_party_id,
7309                                 p_val_mode         => 'SHIP_TO',
7310                                 x_msg_data         => l_msg_data,
7311                                 x_msg_count        => l_msg_count,
7312                                 x_return_status    => l_return_status) = 'N' THEN
7313           Add_Invalid_Argument_Msg(l_api_name,
7314                                  to_char(p_charges_detail_rec.ship_to_org_id),
7315                                  'Ship_to_org_Id');
7316           RAISE FND_API.G_EXC_ERROR;
7317           null;
7318         ELSE
7319           --assign to out record
7320           x_charges_detail_rec.ship_to_org_id := p_charges_detail_rec.ship_to_org_id;
7321         END IF;
7322 
7323       ELSE
7324         --ship_to_org_id IS NULL
7325         --assign NULL to out record
7326         x_charges_detail_rec.ship_to_org_id := NULL;
7327       END IF;
7328     END IF;
7329 
7330  ELSIF
7331 
7332      p_charges_detail_rec.ship_to_party_id = FND_API.G_MISS_NUM THEN
7333 
7334       -- assign the value from the database
7335       x_charges_detail_rec.ship_to_party_id := l_db_det_rec.ship_to_party_id;
7336 
7337       IF p_charges_detail_rec.ship_to_account_id <> FND_API.G_MISS_NUM AND
7338          p_charges_detail_rec.ship_to_account_id IS NOT NULL THEN
7339 
7340 
7341          IF IS_ACCOUNT_VALID(p_party_id      => x_charges_detail_rec.ship_to_party_id,
7342                              p_account_id    => p_charges_detail_rec.ship_to_account_id,
7343                              x_msg_data      => l_msg_data,
7344                              x_msg_count     => l_msg_count,
7345                              x_return_status => l_return_status) = 'U' THEN
7346            --raise unexpected error
7347            Raise FND_API.G_EXC_UNEXPECTED_ERROR;
7348            null;
7349          ELSIF IS_ACCOUNT_VALID(p_party_id      => x_charges_detail_rec.ship_to_party_id,
7350                                 p_account_id    => p_charges_detail_rec.ship_to_account_id,
7351                                 x_msg_data      => l_msg_data,
7352                                 x_msg_count     => l_msg_count,
7353                                 x_return_status => l_return_status) = 'N' THEN
7354 
7355            Add_Invalid_Argument_Msg(l_api_name,
7356                                  to_char(p_charges_detail_rec.ship_to_account_id),
7357                                  'ship_to_account_id');
7358            RAISE FND_API.G_EXC_ERROR;
7359            null;
7360          ELSE
7361            -- assign to out record
7362            x_charges_detail_rec.ship_to_account_id := p_charges_detail_rec.ship_to_account_id;
7363          END IF;
7364       ELSE
7365         -- ship_to_account is not passed
7366         -- assign the value from the database
7367         x_charges_detail_rec.ship_to_account_id := l_db_det_rec.ship_to_account_id;
7368       END IF;
7369 
7370       IF  p_charges_detail_rec.ship_to_contact_id <> FND_API.G_MISS_NUM AND
7371           p_charges_detail_rec.ship_to_contact_id IS NOT NULL THEN
7372 
7373 
7374         IF IS_CONTACT_VALID(p_party_id      => x_charges_detail_rec.ship_to_party_id,
7375                             p_contact_id    => p_charges_detail_rec.ship_to_contact_id,
7376                             x_msg_data      => l_msg_data,
7377                             x_msg_count     => l_msg_count,
7378                             x_return_status => l_return_status) = 'U' THEN
7379           --raise unexpected error
7380           Raise FND_API.G_EXC_UNEXPECTED_ERROR;
7381           null;
7382 
7383         ELSIF IS_CONTACT_VALID(p_party_id      => x_charges_detail_rec.ship_to_party_id,
7384                                p_contact_id    => p_charges_detail_rec.ship_to_contact_id,
7385                                x_msg_data      => l_msg_data,
7386                                x_msg_count     => l_msg_count,
7387                                x_return_status => l_return_status) = 'N' THEN
7388 
7389           Add_Invalid_Argument_Msg(l_api_name,
7390                                  to_char(p_charges_detail_rec.ship_to_contact_id),
7391                                  'ship_to_contact_id');
7392           RAISE FND_API.G_EXC_ERROR;
7393           null;
7394         ELSE
7395           -- assign to out record
7396           x_charges_detail_rec.ship_to_contact_id := p_charges_detail_rec.ship_to_contact_id;
7397         END IF;
7398       ELSE
7399         -- bill_to_contact is not passed
7400         -- assign values from the database to out record
7401         x_charges_detail_rec.ship_to_contact_id := l_db_det_rec.ship_to_contact_id;
7402       END IF;
7403 
7404        -- Fixed Bug # 3325675
7405       IF p_charges_detail_rec.ship_to_org_id <> FND_API.G_MISS_NUM AND
7406          p_charges_detail_rec.ship_to_org_id IS NOT NULL THEN
7407 
7408 
7409         IF IS_PARTY_SITE_VALID( p_party_site_id => p_charges_detail_rec.ship_to_org_id,
7410                                 p_party_id      => x_charges_detail_rec.ship_to_party_id,
7411                                 p_val_mode      => 'SHIP_TO',
7412                                 x_msg_data      => l_msg_data,
7413                                 x_msg_count     => l_msg_count,
7414                                 x_return_status => l_return_status) = 'U' THEN
7415           --raise unexpected error
7416           Raise FND_API.G_EXC_UNEXPECTED_ERROR;
7417           null;
7418         ELSIF IS_PARTY_SITE_VALID( p_party_site_id => p_charges_detail_rec.ship_to_org_id,
7419                                 p_party_id         => x_charges_detail_rec.ship_to_party_id,
7420                                 p_val_mode         => 'SHIP_TO',
7421                                 x_msg_data         => l_msg_data,
7422                                 x_msg_count        => l_msg_count,
7423                                 x_return_status    => l_return_status) = 'N' THEN
7424           Add_Invalid_Argument_Msg(l_api_name,
7425                                  to_char(p_charges_detail_rec.ship_to_org_id),
7426                                  'ship_to_org_id');
7427           RAISE FND_API.G_EXC_ERROR;
7428           null;
7429         ELSE
7430           --assign to out record
7431           x_charges_detail_rec.ship_to_org_id := p_charges_detail_rec.ship_to_org_id;
7432         END IF;
7433 
7434       ELSE
7435         --ship_to_org_id is not passed
7436         --assign values from the database to out record
7437         x_charges_detail_rec.ship_to_org_id := l_db_det_rec.ship_to_org_id;
7438       END IF;
7439 
7440  ELSE
7441 
7442     IF p_charges_detail_rec.ship_to_party_id IS NULL THEN
7443 
7444       --all the values for out record for TCA should be nulled out
7445       x_charges_detail_rec.ship_to_party_id := NULL;
7446       x_charges_detail_rec.ship_to_account_id := NULL;
7447       x_charges_detail_rec.ship_to_contact_id := NULL;
7448       x_charges_detail_rec.ship_to_org_id := NULL;
7449     END IF;
7450   END IF;
7451 END IF;
7452 
7453 
7454 --DBMS_OUTPUT.PUT_LINE('TCA VALID');
7455 --DBMS_OUTPUT.PUT_LINE('Customer ID '||l_customer_id);
7456 
7457 --==================================================
7458 -- Sold to party Validation
7459 --==================================================
7460 --DBMS_OUTPUT.PUT_LINE('Sold To Party Validation ...');
7461 
7462 --DBMS_OUTPUT.PUT_LINE('sold_to_party_id'||p_charges_detail_rec.sold_to_party_id);
7463 --DBMS_OUTPUT.PUT_LINE('customer id '||l_customer_id);
7464 
7465 IF p_validation_mode = 'I' THEN
7466   IF p_charges_detail_rec.sold_to_party_id IS NOT NULL THEN
7467     IF p_charges_detail_rec.sold_to_party_id <> l_customer_id THEN
7468       --raise error
7469       FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_SOLD_TO_PARTY');
7470       FND_MESSAGE.SET_TOKEN('SOLD_TO_PARTY', p_charges_detail_rec.sold_to_party_id);
7471       FND_MESSAGE.SET_TOKEN('INCIDENT_ID', p_charges_detail_rec.incident_id);
7472       FND_MSG_PUB.ADD;
7473       RAISE FND_API.G_EXC_ERROR;
7474     ELSE
7475       --assign the sold to party to the out record
7476       x_charges_detail_rec.sold_to_party_id := l_customer_id;
7477     END IF;
7478   ELSE
7479     --p_charges_detail_rec.sold_to_party_id
7480     IF l_customer_id IS NOT NULL THEN
7481       --assign the l_customer_id to the out rec
7482       x_charges_detail_rec.sold_to_party_id  := l_customer_id;
7483     ELSE
7484       x_charges_detail_rec.sold_to_party_id  := NULL;
7485     END IF;
7486   END IF;
7487 
7488 ElSIF p_validation_mode  = 'U' THEN
7489 
7490   IF p_charges_detail_rec.sold_to_party_id <> FND_API.G_MISS_NUM AND
7491     p_charges_detail_rec.sold_to_party_id IS NOT NULL THEN
7492     IF p_charges_detail_rec.sold_to_party_id <> l_customer_id THEN
7493       --raise error
7494       FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_SOLD_TO_PARTY');
7495       FND_MESSAGE.SET_TOKEN('SOLD_TO_PARTY', p_charges_detail_rec.sold_to_party_id);
7496       FND_MESSAGE.SET_TOKEN('INCIDENT_ID', p_charges_detail_rec.incident_id);
7497       FND_MSG_PUB.ADD;
7498       RAISE FND_API.G_EXC_ERROR;
7499     ELSE
7500       --assign the sold to party to the out record
7501       x_charges_detail_rec.sold_to_party_id := p_charges_detail_rec.sold_to_party_id;
7502     END IF;
7503 
7504   ELSIF p_charges_detail_rec.sold_to_party_id = FND_API.G_MISS_NUM THEN
7505     --assign the database value to the field
7506     --assign the sold to party to the out record
7507     x_charges_detail_rec.sold_to_party_id := l_customer_id ;
7508 
7509   ELSE
7510     IF p_charges_detail_rec.sold_to_party_id IS NULL THEN
7511       IF l_customer_id IS NOT NULL THEN
7512         -- raise error
7513         null;
7514       ELSE
7515         x_charges_detail_rec.sold_to_party_id := NULL;
7516       END IF;
7517     END IF;
7518   END IF;
7519  END IF;
7520 
7521 --DBMS_OUTPUT.PUT_LINE('Sold To Party Validation successful...');
7522 
7523 --============================================
7524 --Valid the Item Instance
7525 --============================================
7526 -- DBMS_OUTPUT.PUT_LINE('Item Instance Validation ...');
7527 IF p_validation_mode = 'I' THEN
7528 
7529    -- DBMS_OUTPUT.PUT_LINE('Update_ib_flag '||l_update_ib_flag);
7530    -- DBMS_OUTPUT.PUT_LINE('src_reference_reqd_flag '||l_src_reference_reqd_flag);
7531    -- DBMS_OUTPUT.PUT_LINE('line_order_category_code '||l_line_order_category_code);
7532    -- DBMS_OUTPUT.PUT_LINE('customer_product_id '||p_charges_detail_rec.customer_product_id);
7533 
7534 
7535    x_charges_detail_rec.customer_product_id := p_charges_detail_rec.customer_product_id;
7536    x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;
7537 
7538     --item instance validation
7539     --fixed Bug # 3362130 - added l_comms_trackable_flag = 'Y' condition
7540     IF(l_src_reference_reqd_flag = 'Y') AND
7541       (l_line_order_category_code = 'RETURN') AND
7542       (l_comms_trackable_flag = 'Y') THEN
7543       IF p_charges_detail_rec.customer_product_id IS NULL THEN
7544 
7545         -- --DBMS_OUTPUT.PUT_LINE('Customer product id null');
7546         --RAISE FND_API.G_EXC_ERROR;
7547         --null;
7548         FND_MESSAGE.Set_Name('CS', 'CS_API_CHG_IB_INSTANCE_MISSING');
7549         FND_MESSAGE.Set_Token('API_NAME', p_api_name);
7550         FND_MSG_PUB.Add;
7551         RAISE FND_API.G_EXC_ERROR;
7552       ELSE
7553         -- Check if instance is of the same inventory_item_id
7554         -- If not of the same inv id the error
7555         -- Call IS_INSTANCE_FOR_INVENTORY
7556 
7557         -- --DBMS_OUTPUT.PUT_LINE('Customer product id is not null');
7558 
7559         l_valid_check := IS_INSTANCE_FOR_INVENTORY(
7560                                      p_instance_id   => p_charges_detail_rec.customer_product_id,
7561                                      p_inv_id        => x_charges_detail_rec.inventory_item_id_in,
7562                                      x_msg_data      => l_msg_data,
7563                                      x_msg_count     => l_msg_count,
7564                                      x_return_status => l_return_status);
7565 
7566           IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
7567             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7568           ELSIF l_return_status = G_RET_STS_ERROR THEN
7569             RAISE FND_API.G_EXC_ERROR;
7570           END IF;
7571 
7572         IF l_valid_check <> 'Y' THEN
7573 
7574             FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_IB_INSTANCE_INV');
7575             FND_MESSAGE.Set_Token('INVENTORY_ITEM_ID', p_charges_detail_rec.inventory_item_id_in);
7576             FND_MESSAGE.Set_Token('INSTANCE_ID', p_charges_detail_rec.customer_product_id);
7577             FND_MSG_PUB.Add;
7578             RAISE FND_API.G_EXC_ERROR;
7579         ELSE
7580 
7581           l_valid_check := IS_INSTANCE_VALID(p_instance_id   => p_charges_detail_rec.customer_product_id,
7582                                p_party_id      => x_charges_detail_rec.sold_to_party_id,
7583                                x_msg_data      => l_msg_data,
7584                                x_msg_count     => l_msg_count,
7585                                x_return_status => l_return_status);
7586 
7587               IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
7588                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7589               ELSIF l_return_status = G_RET_STS_ERROR THEN
7590                 RAISE FND_API.G_EXC_ERROR;
7591               END IF;
7592 
7593 --taklam
7594           IF l_valid_check <> 'Y' THEN
7595              --Check if Service activity has 'change owner flag' set to 'N'
7596              --(See the csi_ib_txn_types table for the flag value)
7597              --'change owner flag'
7598 
7599              OPEN C_SRC_CHANGE_OWNER(p_charges_detail_rec.txn_billing_type_id);
7600              FETCH C_SRC_CHANGE_OWNER INTO l_src_change_owner;
7601              CLOSE C_SRC_CHANGE_OWNER;
7602 
7603              If (l_src_change_owner = 'N') or (l_src_change_owner is null) THEN
7604                --Pass the internal_party_id to the existing "IS_INSTANCE_VALID" method.
7605                --select internal_party_id from csi_install_parameters,
7606                SELECT internal_party_id into l_internal_party_id
7607                FROM csi_install_parameters WHERE rownum = 1;
7608 
7609                l_valid_check := IS_INSTANCE_VALID( p_instance_id   => p_charges_detail_rec.customer_product_id,
7610                                                    p_party_id      => l_internal_party_id,
7611                                                    x_msg_data      => l_msg_data,
7612                                                    x_msg_count     => l_msg_count,
7613                                                    x_return_status => l_return_status);
7614                IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
7615                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7616                ELSIF l_return_status = G_RET_STS_ERROR THEN
7617                  RAISE FND_API.G_EXC_ERROR;
7618                END IF;
7619              End if;
7620           End if;
7621 
7622 
7623           IF l_valid_check <> 'Y' THEN
7624 
7625                FND_MESSAGE.SET_NAME ('CS', 'CS_CHG_INVALID_INSTANCE_RMA_PT');
7626                FND_MSG_PUB.Add;
7627                RAISE FND_API.G_EXC_ERROR;
7628 --taklam
7629           ELSE
7630             --assign the customer product id to out record
7631             x_charges_detail_rec.customer_product_id := p_charges_detail_rec.customer_product_id;
7632             --DBMS_OUTPUT.PUT_LINE('Cust prod id '||x_charges_detail_rec.customer_product_id);
7633           END IF;
7634         END IF;
7635       END IF;
7636 
7637       -- check to see if its a serialized item
7638       -- Added for Bug # 4073602
7639       IF l_serial_control_flag = 'Y' THEN
7640         IF p_charges_detail_rec.serial_number IS NULL THEN
7641           -- no error raised
7642           -- Fix bug#5125934
7643           OPEN c_serial_number(p_charges_detail_rec.customer_product_id);
7644           FETCH c_serial_number
7645           INTO  l_serial_number;
7646           CLOSE c_serial_number;
7647 
7648           -- x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;
7649           x_charges_detail_rec.serial_number := l_serial_number;
7650         ELSE
7651           --validate the serial number
7652           l_valid_check := IS_INSTANCE_SERIAL_VALID( p_instance_id   => x_charges_detail_rec.customer_product_id
7653                                                     ,p_serial_number => p_charges_detail_rec.serial_number
7654                                                     ,x_msg_data      => l_msg_data
7655                                                     ,x_msg_count     => l_msg_count
7656                                                     ,x_return_status => l_return_status);
7657 
7658           IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
7659             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7660           ELSIF l_return_status = G_RET_STS_ERROR THEN
7661             RAISE FND_API.G_EXC_ERROR;
7662           END IF;
7663 
7664           IF l_valid_check <> 'Y' THEN
7665             FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_SERIAL_NUMBER');
7666             FND_MESSAGE.Set_Token('INSTANCE_ID', p_charges_detail_rec.customer_product_id);
7667             FND_MESSAGE.Set_Token('SERIAL_NUMBER', p_charges_detail_rec.serial_number);
7668             FND_MSG_PUB.Add;
7669             RAISE FND_API.G_EXC_ERROR;
7670           ELSE
7671             --assign the customer product id to out record
7672             x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;
7673           END IF;
7674         END IF;
7675 
7676       ELSE
7677         x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;
7678       END IF; -- check to see if its a serialized item
7679 
7680 
7681     --fixed Bug # 3362130 - added l_comms_trackable_flag = 'Y' condition
7682     ELSIF (l_non_src_reference_reqd_flag = 'Y') AND
7683       (l_line_order_category_code = 'ORDER') AND
7684       (l_comms_trackable_flag = 'Y') THEN
7685       IF p_charges_detail_rec.customer_product_id IS NULL THEN
7686         --DBMS_OUTPUT.PUT_LINE('Customer product id null');
7687         --RAISE FND_API.G_EXC_ERROR;
7688         --null;
7689         FND_MESSAGE.Set_Name('CS', 'CS_API_CHG_IB_INSTANCE_MISSING');
7690         FND_MESSAGE.Set_Token('API_NAME', p_api_name);
7691         FND_MSG_PUB.Add;
7692         RAISE FND_API.G_EXC_ERROR;
7693       ELSE
7694 
7695 
7696         l_valid_check := IS_INSTANCE_VALID(p_instance_id   => p_charges_detail_rec.customer_product_id,
7697                                p_party_id      => x_charges_detail_rec.sold_to_party_id,
7698                                x_msg_data      => l_msg_data,
7699                                x_msg_count     => l_msg_count,
7700                                x_return_status => l_return_status);
7701 
7702               IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
7703                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7704               ELSIF l_return_status = G_RET_STS_ERROR THEN
7705                 RAISE FND_API.G_EXC_ERROR;
7706               END IF;
7707         --DBMS_OUTPUT.PUT_LINE('Instance is l_valid_check'||l_valid_check);
7708 
7709         IF l_valid_check <> 'Y' THEN
7710 
7711               FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_IB_INSTANCE_PTY');
7712               FND_MESSAGE.Set_Token('PARTY_ID', x_charges_detail_rec.sold_to_party_id);
7713               FND_MESSAGE.Set_Token('INSTANCE_ID', p_charges_detail_rec.customer_product_id);
7714               FND_MSG_PUB.Add;
7715               RAISE FND_API.G_EXC_ERROR;
7716 
7717         ELSE
7718           --assign to out record
7719           x_charges_detail_rec.customer_product_id := p_charges_detail_rec.customer_product_id;
7720           --DBMS_OUTPUT.PUT_LINE('Cust prod id '||x_charges_detail_rec.customer_product_id);
7721         END IF;
7722       END IF;
7723 
7724       -- check to see if its a serialized item
7725       -- Added for Bug # 4073602
7726       IF l_serial_control_flag = 'Y' THEN
7727         IF p_charges_detail_rec.serial_number IS NULL THEN
7728           -- no error raised
7729           -- Fix bug#5125934
7730           OPEN c_serial_number(p_charges_detail_rec.customer_product_id);
7731           FETCH c_serial_number
7732           INTO  l_serial_number;
7733           CLOSE c_serial_number;
7734 
7735           -- x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;
7736           x_charges_detail_rec.serial_number := l_serial_number;
7737 
7738         ELSE
7739           --validate the serial number
7740           l_valid_check := IS_INSTANCE_SERIAL_VALID( p_instance_id => x_charges_detail_rec.customer_product_id
7741                                                     ,p_serial_number => p_charges_detail_rec.serial_number
7742                                                     ,x_msg_data      => l_msg_data
7743                                                     ,x_msg_count     => l_msg_count
7744                                                     ,x_return_status => l_return_status);
7745 
7746           IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
7747             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7748           ELSIF l_return_status = G_RET_STS_ERROR THEN
7749             RAISE FND_API.G_EXC_ERROR;
7750           END IF;
7751 
7752           IF l_valid_check <> 'Y' THEN
7753             FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_SERIAL_NUMBER');
7754             FND_MESSAGE.Set_Token('INSTANCE_ID', p_charges_detail_rec.customer_product_id);
7755             FND_MESSAGE.Set_Token('SERIAL_NUMBER', p_charges_detail_rec.serial_number);
7756             FND_MSG_PUB.Add;
7757             RAISE FND_API.G_EXC_ERROR;
7758           ELSE
7759             --assign the customer product id to out record
7760             x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;
7761           END IF;
7762         END IF;
7763 
7764       ELSE
7765         x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;
7766       END IF; -- check to see if its a serialized item
7767 
7768     ELSE -- IF1
7769 
7770       --DBMS_OUTPUT.PUT_LINE('In the IF1');
7771       -- Added customer_product_id is not null condition
7772       IF (p_charges_detail_rec.customer_product_id IS NOT NULL AND -- IF2
7773           p_charges_detail_rec.customer_product_id <> FND_API.G_MISS_NUM) THEN
7774         -- Added the FND Messages for Bug# 5141369
7775         IF (l_comms_trackable_flag = 'N') THEN
7776           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_INST_AND_INV');
7777           FND_MESSAGE.Set_Token('INSTANCE_ID', p_charges_detail_rec.customer_product_id);
7778           FND_MESSAGE.Set_Token('INVENTORY_ITEM_ID', p_charges_detail_rec.inventory_item_id_in);
7779           FND_MSG_PUB.Add;
7780           RAISE FND_API.G_EXC_ERROR;
7781         ELSE
7782           -- Check if the Instance Is Valid for all other cases
7783           l_valid_check := IS_INSTANCE_VALID(
7784                 p_instance_id   => p_charges_detail_rec.customer_product_id,
7785                 p_party_id      => x_charges_detail_rec.sold_to_party_id,
7786                 x_msg_data      => l_msg_data,
7787                 x_msg_count     => l_msg_count,
7788                 x_return_status => l_return_status);
7789           IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
7790             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7791           ELSIF l_return_status = G_RET_STS_ERROR THEN
7792             RAISE FND_API.G_EXC_ERROR;
7793           END IF;
7794         END IF;
7795 
7796         --DBMS_OUTPUT.PUT_LINE('l_valid_check'||l_valid_check);
7797 
7798 --taklam
7799         IF l_valid_check <> 'Y' THEN
7800           --Check if Service activity has 'change owner flag' set to 'N'
7801           --(See the csi_ib_txn_types table for the flag value)
7802           --'change owner flag'
7803 
7804           OPEN C_SRC_CHANGE_OWNER(p_charges_detail_rec.txn_billing_type_id);
7805           FETCH C_SRC_CHANGE_OWNER INTO l_src_change_owner;
7806           CLOSE C_SRC_CHANGE_OWNER;
7807 
7808           --DBMS_OUTPUT.PUT_LINE('l_src_change_owner'||l_src_change_owner);
7809 
7810           If (l_src_change_owner = 'N') or (l_src_change_owner is null) THEN
7811             --Pass the internal_party_id to the existing "IS_INSTANCE_VALID" method.
7812             --select internal_party_id from csi_install_parameters,
7813             SELECT internal_party_id into l_internal_party_id
7814             FROM csi_install_parameters WHERE rownum = 1;
7815 
7816             l_valid_check := IS_INSTANCE_VALID( p_instance_id   => p_charges_detail_rec.customer_product_id,
7817                                                 p_party_id      => l_internal_party_id,
7818                                                 x_msg_data      => l_msg_data,
7819                                                 x_msg_count     => l_msg_count,
7820                                                 x_return_status => l_return_status);
7821             IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
7822               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7823             ELSIF l_return_status = G_RET_STS_ERROR THEN
7824               RAISE FND_API.G_EXC_ERROR;
7825             END IF;
7826           End if;
7827         End if;
7828 
7829         --DBMS_OUTPUT.PUT_LINE('l_valid_check'||l_valid_check);
7830 
7831         IF l_valid_check <> 'Y' THEN
7832 
7833             --FND_MESSAGE.SET_NAME ('CS', 'CS_CHG_INVALID_INSTANCE_RMA_PT');
7834             --FND_MSG_PUB.Add;
7835             Add_Invalid_Argument_Msg(l_api_name_full,
7836                              to_char(p_charges_detail_rec.customer_product_id),
7837                              'Customer_Product_Id');
7838             RAISE FND_API.G_EXC_ERROR;
7839 --taklam
7840         ELSE
7841           x_charges_detail_rec.customer_product_id := p_charges_detail_rec.customer_product_id;
7842         END IF;
7843 
7844         -- check to see if its a serialized item
7845         -- Added for Bug # 4073602
7846         IF l_serial_control_flag = 'Y' THEN
7847            --DBMS_OUTPUT.PUT_LINE('l_serial_control_flag'||l_serial_control_flag);
7848           IF p_charges_detail_rec.serial_number IS NULL THEN
7849             -- no error raised
7850             -- Fix bug#5125934
7851             OPEN c_serial_number(p_charges_detail_rec.customer_product_id);
7852             FETCH c_serial_number
7853             INTO  l_serial_number;
7854             CLOSE c_serial_number;
7855 
7856           -- x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;
7857           x_charges_detail_rec.serial_number := l_serial_number;
7858 
7859           ELSE
7860             --validate the serial number
7861             --DBMS_OUTPUT.PUT_LINE('Calling IS_INSTANCE_SERIAL_VALID');
7862             --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.customer_product_id'||x_charges_detail_rec.customer_product_id);
7863             --DBMS_OUTPUT.PUT_LINE('p_charges_detail_rec.serial_number'||p_charges_detail_rec.serial_number);
7864 
7865             l_valid_check := IS_INSTANCE_SERIAL_VALID( p_instance_id => x_charges_detail_rec.customer_product_id
7866                                                     ,p_serial_number => p_charges_detail_rec.serial_number
7867                                                     ,x_msg_data      => l_msg_data
7868                                                     ,x_msg_count     => l_msg_count
7869                                                     ,x_return_status => l_return_status);
7870             IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
7871               RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7872             ELSIF l_return_status = G_RET_STS_ERROR THEN
7873               RAISE FND_API.G_EXC_ERROR;
7874             END IF;
7875 
7876             IF l_valid_check <> 'Y' THEN
7877               FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_SERIAL_NUMBER');
7878               FND_MESSAGE.Set_Token('INSTANCE_ID', p_charges_detail_rec.customer_product_id);
7879               FND_MESSAGE.Set_Token('SERIAL_NUMBER', p_charges_detail_rec.serial_number);
7880               FND_MSG_PUB.Add;
7881               RAISE FND_API.G_EXC_ERROR;
7882             ELSE
7883               --assign the customer product id to out record
7884               x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;
7885             END IF;
7886           END IF;
7887 
7888         ELSE
7889           x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;
7890         END IF; -- check to see if its a serialized item
7891 
7892       END IF; -- IF2
7893     END IF; -- IF1
7894 
7895     --DBMS_OUTPUT.PUT_LINE('Checking  src');
7896 
7897     -- Fix for Bug # 3325686
7898     --fixed Bug # 3362130 - added l_comms_trackable_flag = 'Y' condition
7899     /*** IF l_src_reference_reqd_flag = 'Y' AND
7900        l_src_return_reqd_flag = 'Y' AND
7901        l_line_order_category_code = 'RETURN' AND
7902        l_comms_trackable_flag = 'Y' THEN
7903         IF p_charges_detail_rec.installed_cp_return_by_date IS NULL THEN
7904           --RAISE FND_API.G_EXC_ERROR;
7905           --null;
7906           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INST_CP_RETURN_BY_DATE');
7907           FND_MESSAGE.Set_Token('INST_CP_RTN_BY_DATE', p_charges_detail_rec.installed_cp_return_by_date);
7908           FND_MSG_PUB.Add;
7909           RAISE FND_API.G_EXC_ERROR;
7910         ELSE
7911           --assign to out record
7912           x_charges_detail_rec.installed_cp_return_by_date := p_charges_detail_rec.installed_cp_return_by_date;
7913         END IF;
7914 
7915     ELSE
7916       -- the flag is 'N'
7917       -- ignore the installed_cp_return_by_date
7918       x_charges_detail_rec.installed_cp_return_by_date := NULL;
7919     END IF; ****/
7920 
7921     -- Return_by_date fix. If the flags are not set, then assign
7922     --whatever value comes in and do not set the installed_cp_return_date to NULL
7923     -- Fix for bug#5136691
7924     IF l_src_return_reqd_flag = 'Y' AND
7925        l_line_order_category_code = 'RETURN' AND
7926        l_comms_trackable_flag = 'Y' THEN
7927 
7928         IF p_charges_detail_rec.installed_cp_return_by_date IS NULL THEN
7929           --RAISE FND_API.G_EXC_ERROR;
7930           --null;
7931           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INST_CP_RETURN_BY_DATE');
7932           FND_MESSAGE.Set_Token('INST_CP_RTN_BY_DATE', p_charges_detail_rec.installed_cp_return_by_date);
7933           FND_MSG_PUB.Add;
7934           RAISE FND_API.G_EXC_ERROR;
7935         ELSE
7936           --assign to out record
7937           x_charges_detail_rec.installed_cp_return_by_date := p_charges_detail_rec.installed_cp_return_by_date;
7938         END IF;
7939     ELSE
7940       -- the flag is 'N'
7941       -- ignore installed_cp_return_by_date
7942       x_charges_detail_rec.installed_cp_return_by_date := p_charges_detail_rec.installed_cp_return_by_date;
7943     END IF;
7944 
7945     --DBMS_OUTPUT.PUT_LINE('Done Checking src');
7946     --DBMS_OUTPUT.PUT_LINE('Checking  non src');
7947 
7948     -- Depot Loaner fix - Bug#4586140
7949     -- Commenting out for return_by_date fix
7950     /* Open c_get_depot_txns_details(p_charges_detail_rec.estimate_detail_id);
7951     Fetch c_get_depot_txns_details into l_action_code;
7952     Close c_get_depot_txns_details; */
7953 
7954     -- Fix for Bug # 3325686
7955     --fixed Bug # 3362130 - added l_comms_trackable_flag = 'Y' condition
7956     -- commented out the old code
7957     -- Modified for the return_by_date fix. Bug:5136853
7958     -- If the instance is not null and the non_src retur_reqd flag is 'Y' ,
7959     -- then installed_cp_return_by_date column should have a value.
7960     -- Likewise if the instance is null and the item is trackable and the
7961     -- src_return_reqd field is 'y', the the new_cp_return_by_date should have a value.
7962     -- Otherwise raise appropriate errors. This validation is for 'ORDER'
7963 
7964     /*** non source flag checked for the 'ORDER' ***/
7965     IF l_non_src_return_reqd_flag = 'Y' AND
7966        l_line_order_category_code = 'ORDER' AND
7967        l_comms_trackable_flag = 'Y' AND
7968        p_charges_detail_rec.customer_product_id IS NOT NULL THEN
7969       IF p_charges_detail_rec.installed_cp_return_by_date IS NULL THEN
7970         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INSTALLED_CP_RETURN_BY_DATE');
7971         FND_MESSAGE.Set_Token('INSTALLED_CP_RTN_BY_DATE', p_charges_detail_rec.installed_cp_return_by_date);
7972         FND_MSG_PUB.Add;
7973         RAISE FND_API.G_EXC_ERROR;
7974       ELSE
7975         x_charges_detail_rec.installed_cp_return_by_date := p_charges_detail_rec.installed_cp_return_by_date;
7976       END IF;
7977     ELSE
7978       -- Assign whatever value is passed in the parameter.
7979       x_charges_detail_rec.installed_cp_return_by_date := p_charges_detail_rec.installed_cp_return_by_date;
7980     END IF;
7981 
7982     /*** Source Flag checked for the 'Order' ***/
7983     IF l_src_return_reqd_flag = 'Y' AND
7984        l_line_order_category_code = 'ORDER' AND
7985        l_comms_trackable_flag = 'Y' AND
7986        p_charges_detail_rec.customer_product_id IS NULL THEN
7987       IF p_charges_detail_rec.new_cp_return_by_date IS NULL THEN
7988         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_NEW_CP_RETURN_BY_DATE');
7989         FND_MESSAGE.Set_Token('NEW_CP_RTN_BY_DATE', p_charges_detail_rec.new_cp_return_by_date);
7990         FND_MSG_PUB.Add;
7991         RAISE FND_API.G_EXC_ERROR;
7992       ELSE
7993         x_charges_detail_rec.new_cp_return_by_date := p_charges_detail_rec.new_cp_return_by_date;
7994       END IF;
7995     ELSE
7996       -- Assign whatever value is passed in the parameter.
7997       x_charges_detail_rec.new_cp_return_by_date := p_charges_detail_rec.new_cp_return_by_date;
7998     END IF;
7999 
8000 
8001     /*****
8002     IF l_non_src_reference_reqd_flag = 'Y' AND
8003        l_non_src_return_reqd = 'Y' AND
8004        l_line_order_category_code = 'ORDER' AND
8005        l_comms_trackable_flag = 'Y' THEN
8006       IF p_charges_detail_rec.new_cp_return_by_date IS NULL THEN
8007         --RAISE FND_API.G_EXC_ERROR;
8008         --null;
8009         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_NEW_CP_RETURN_BY_DATE');
8010         FND_MESSAGE.Set_Token('NEW_CP_RTN_BY_DATE', p_charges_detail_rec.new_cp_return_by_date);
8011         FND_MSG_PUB.Add;
8012         RAISE FND_API.G_EXC_ERROR;
8013       ELSE
8014         x_charges_detail_rec.new_cp_return_by_date := p_charges_detail_rec.new_cp_return_by_date;
8015       END IF;
8016 
8017      -- Depot Loaner fix - Bug#4586140
8018     ELSIF ( l_line_order_category_code = 'ORDER' AND
8019             l_comms_trackable_flag = 'Y' AND
8020             l_src_return_reqd_flag = 'Y' AND
8021             l_action_code = 'LOANER') THEN
8022 
8023         x_charges_detail_rec.new_cp_return_by_date := p_charges_detail_rec.new_cp_return_by_date;
8024     ELSE
8025       --the flag is 'N'
8026       --ignore the new_cp_return_by_date
8027       x_charges_detail_rec.new_cp_return_by_date := NULL;
8028     END IF;  *****/
8029 
8030 
8031   --DBMS_OUTPUT.PUT_LINE('Done Checking non src');
8032   --DBMS_OUTPUT.PUT_LINE('Cust_product_id is '||P_CHARGES_DETAIL_REC.customer_product_id);
8033 
8034 
8035 ELSIF p_validation_mode = 'U' THEN
8036 
8037     -- If no customer_product_id is passed
8038 	    IF  p_charges_detail_rec.customer_product_id = FND_API.G_MISS_NUM THEN
8039 	      IF l_db_det_rec.customer_product_id  IS NOT NULL AND
8040 	         l_item_changed = 'Y' AND
8041 	         x_charges_detail_rec.line_category_code = 'RETURN' AND
8042 	         l_src_reference_reqd_flag = 'Y' AND
8043 	         l_comms_trackable_flag = 'Y' THEN
8044 
8045 	         --check if instance is for the same inventory
8046 	          l_valid_check := IS_INSTANCE_FOR_INVENTORY(
8047 	                                     p_instance_id   => p_charges_detail_rec.customer_product_id,
8048 	                                     p_inv_id        => x_charges_detail_rec.inventory_item_id_in,
8049 	                                     x_msg_data      => l_msg_data,
8050 	                                     x_msg_count     => l_msg_count,
8051 	                                     x_return_status => l_return_status);
8052 
8053 	          IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8054 	            RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8055 	          ELSIF l_return_status = G_RET_STS_ERROR THEN
8056 	            RAISE FND_API.G_EXC_ERROR;
8057 	          END IF;
8058 
8059 	        IF l_valid_check <> 'Y' THEN
8060 
8061 	            FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_IB_INSTANCE_INV');
8062 	            FND_MESSAGE.Set_Token('INVENTORY_ITEM_ID', p_charges_detail_rec.inventory_item_id_in);
8063 	            FND_MESSAGE.Set_Token('INSTANCE_ID', p_charges_detail_rec.customer_product_id);
8064 	            FND_MSG_PUB.Add;
8065 	            RAISE FND_API.G_EXC_ERROR;
8066 
8067 	        ELSE
8068 	          l_valid_check := IS_INSTANCE_VALID(p_instance_id   => p_charges_detail_rec.customer_product_id,
8069 	                               p_party_id      => x_charges_detail_rec.sold_to_party_id,
8070 	                               x_msg_data      => l_msg_data,
8071 	                               x_msg_count     => l_msg_count,
8072 	                               x_return_status => l_return_status);
8073 
8074 	              IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8075 	                RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8076 	              ELSIF l_return_status = G_RET_STS_ERROR THEN
8077 	                RAISE FND_API.G_EXC_ERROR;
8078 	              END IF;
8079 
8080 	--taklam
8081 	          IF l_valid_check <> 'Y' THEN
8082 	             --Check if Service activity has 'change owner flag' set to 'N'
8083 	             --(See the csi_ib_txn_types table for the flag value)
8084 	             --'change owner flag'
8085 
8086 	             OPEN C_SRC_CHANGE_OWNER(p_charges_detail_rec.txn_billing_type_id);
8087 	             FETCH C_SRC_CHANGE_OWNER INTO l_src_change_owner;
8088 	             CLOSE C_SRC_CHANGE_OWNER;
8089 
8090 	             If (l_src_change_owner = 'N') or (l_src_change_owner is null) THEN
8091 	               --Pass the internal_party_id to the existing "IS_INSTANCE_VALID" method.
8092 	               --select internal_party_id from csi_install_parameters,
8093 	               SELECT internal_party_id into l_internal_party_id
8094 	               FROM csi_install_parameters;
8095 
8096 	               l_valid_check := IS_INSTANCE_VALID( p_instance_id   => p_charges_detail_rec.customer_product_id,
8097 	                                                   p_party_id      => l_internal_party_id,
8098 	                                                   x_msg_data      => l_msg_data,
8099 	                                                   x_msg_count     => l_msg_count,
8100 	                                                   x_return_status => l_return_status);
8101 	               IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8102 	                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8103 	               ELSIF l_return_status = G_RET_STS_ERROR THEN
8104 	                 RAISE FND_API.G_EXC_ERROR;
8105 	               END IF;
8106 	             End if;
8107 	          End if;
8108 
8109 
8110 	          IF l_valid_check <> 'Y' THEN
8111 
8112 	               FND_MESSAGE.SET_NAME ('CS', 'CS_CHG_INVALID_INSTANCE_RMA_PT');
8113 	               FND_MSG_PUB.Add;
8114 	               RAISE FND_API.G_EXC_ERROR;
8115 	--taklam
8116 	          ELSE
8117 	            --assign the customer product id to out record
8118 	            x_charges_detail_rec.customer_product_id := p_charges_detail_rec.customer_product_id;
8119 	            --DBMS_OUTPUT.PUT_LINE('Cust prod id '||x_charges_detail_rec.customer_product_id);
8120 	          END IF;
8121 	        END IF;
8122 	     ELSE
8123 	      --assign the values from the database
8124 	      x_charges_detail_rec.customer_product_id := l_db_det_rec.customer_product_id;
8125 	    END IF;
8126 
8127     -- check to see if its a serialized item
8128     -- Added for Bug # 4073602
8129     IF l_serial_control_flag = 'Y' THEN
8130         IF p_charges_detail_rec.serial_number IS NULL AND
8131            x_charges_detail_rec.customer_product_id IS NOT NULL THEN
8132           -- no error raised
8133           -- Fix bug#5125934
8134             OPEN c_serial_number(p_charges_detail_rec.customer_product_id);
8135             FETCH c_serial_number
8136             INTO  l_serial_number;
8137             CLOSE c_serial_number;
8138 
8139           -- x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;
8140           x_charges_detail_rec.serial_number := l_serial_number;
8141 
8142         ELSIF p_charges_detail_rec.serial_number = FND_API.G_MISS_CHAR THEN
8143           -- Remove serial_number validation. Fix bug#5176423
8144           --validate the serial number
8145           /* l_valid_check := IS_INSTANCE_SERIAL_VALID( p_instance_id   => x_charges_detail_rec.customer_product_id
8146                                                     ,p_serial_number => l_db_det_rec.serial_number
8147                                                     ,x_msg_data      => l_msg_data
8148                                                     ,x_msg_count     => l_msg_count
8149                                                     ,x_return_status => l_return_status);
8150 
8151           IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8152             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8153           ELSIF l_return_status = G_RET_STS_ERROR THEN
8154             RAISE FND_API.G_EXC_ERROR;
8155           END IF;
8156 
8157           IF l_valid_check <> 'Y' THEN
8158             FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_SERIAL_NUMBER');
8159             FND_MESSAGE.Set_Token('INSTANCE_ID', p_charges_detail_rec.customer_product_id);
8160             FND_MESSAGE.Set_Token('SERIAL_NUMBER', p_charges_detail_rec.serial_number);
8161             FND_MSG_PUB.Add;
8162             RAISE FND_API.G_EXC_ERROR;
8163           ELSE */
8164 
8165             --assign the customer product id to out record
8166             -- x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;
8167             x_charges_detail_rec.serial_number := l_db_det_rec.serial_number;
8168 
8169           -- END IF;
8170         -- Added for bug fix:5259686
8171         ELSIF p_charges_detail_rec.serial_number IS NOT NULL AND
8172               x_charges_detail_rec.customer_product_id IS NOT NULL THEN
8173 
8174           --serial number is neither null nor fnd_api.g_miss
8175           -- value is passed
8176           --validate the serial number
8177           x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;    --5887316
8178           /*
8179           l_valid_check := IS_INSTANCE_SERIAL_VALID( p_instance_id   => x_charges_detail_rec.customer_product_id
8180                                                     ,p_serial_number => p_charges_detail_rec.serial_number
8181                                                     ,x_msg_data      => l_msg_data
8182                                                     ,x_msg_count     => l_msg_count
8183                                                     ,x_return_status => l_return_status);
8184 
8185 
8186           IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8187             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8188           ELSIF l_return_status = G_RET_STS_ERROR THEN
8189             RAISE FND_API.G_EXC_ERROR;
8190           END IF;
8191 
8192           IF l_valid_check <> 'Y' THEN
8193             FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_SERIAL_NUMBER');
8194             FND_MESSAGE.Set_Token('INSTANCE_ID', p_charges_detail_rec.customer_product_id);
8195             FND_MESSAGE.Set_Token('SERIAL_NUMBER', p_charges_detail_rec.serial_number);
8196             FND_MSG_PUB.Add;
8197             RAISE FND_API.G_EXC_ERROR;
8198           ELSE
8199             --assign the serial_number to out record
8200             x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;
8201           END IF;
8202 	  */ --5887316
8203         END IF;
8204       ELSE
8205         --customerproduct  id is null
8206         x_charges_detail_rec.serial_number := l_db_det_rec.serial_number ;
8207       END IF;
8208     END IF;
8209 
8210   -- If null is passed to customer_product_id
8211 
8212     IF p_charges_detail_rec.customer_product_id IS NULL THEN
8213 
8214       --item instance validation
8215       --fixed Bug # 3362130 - added l_comms_trackable_flag = 'Y' condition
8216       IF (l_src_reference_reqd_flag = 'Y') AND
8217          (l_line_order_category_code = 'RETURN') AND
8218          (l_comms_trackable_flag = 'Y') THEN
8219         --DBMS_OUTPUT.PUT_LINE('Customer product id null');
8220 
8221         --RAISE FND_API.G_EXC_ERROR;
8222         --null;
8223         FND_MESSAGE.Set_Name('CS', 'CS_API_CHG_IB_INSTANCE_MISSING');
8224         FND_MESSAGE.Set_Token('API_NAME', p_api_name);
8225         FND_MSG_PUB.Add;
8226         RAISE FND_API.G_EXC_ERROR;
8227 
8228       --fixed Bug # 3362130 - added l_comms_trackable_flag = 'Y' condition
8229       ELSIF (l_non_src_reference_reqd_flag = 'Y') AND
8230         (l_line_order_category_code = 'ORDER') AND
8231         (l_comms_trackable_flag = 'Y') THEN
8232         --DBMS_OUTPUT.PUT_LINE('Customer product id null');
8233         --RAISE FND_API.G_EXC_ERROR;
8234         --null;
8235         FND_MESSAGE.Set_Name('CS', 'CS_API_CHG_IB_INSTANCE_MISSING');
8236         FND_MESSAGE.Set_Token('API_NAME', p_api_name);
8237         FND_MSG_PUB.Add;
8238         RAISE FND_API.G_EXC_ERROR;
8239       ELSE
8240         x_charges_detail_rec.customer_product_id := NULL;
8241       END IF;
8242    END IF;
8243 
8244    -- If new CP is passed
8245    -- Fix for Bug # 3325686
8246    --IF l_db_det_rec.customer_product_id  IS NOT NULL AND
8247 /*cnemalik bug 3913714
8248  IN 11.5.9 customer_product_id is mandatory for certain setups. But in 11.5.10, for the same setups it is optional*/
8249 
8250      IF  p_charges_detail_rec.customer_product_id <> FND_API.G_MISS_NUM AND
8251        p_charges_detail_rec.customer_product_id IS NOT NULL AND
8252        x_charges_detail_rec.line_category_code = 'RETURN' THEN
8253 
8254          -- Added the FND Messages for Bug# 5141369
8255          IF (l_comms_trackable_flag = 'N') THEN
8256           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_INST_AND_INV');
8257           FND_MESSAGE.Set_Token('INSTANCE_ID', p_charges_detail_rec.customer_product_id);
8258           FND_MESSAGE.Set_Token('INVENTORY_ITEM_ID', p_charges_detail_rec.inventory_item_id_in);
8259           FND_MSG_PUB.Add;
8260           RAISE FND_API.G_EXC_ERROR;
8261 
8262          ELSE
8263 
8264           --check if instance is for the same inventory
8265           l_valid_check := IS_INSTANCE_FOR_INVENTORY(
8266                                      p_instance_id   => p_charges_detail_rec.customer_product_id,
8267                                      p_inv_id        => x_charges_detail_rec.inventory_item_id_in,
8268                                      x_msg_data      => l_msg_data,
8269                                      x_msg_count     => l_msg_count,
8270                                      x_return_status => l_return_status);
8271 
8272           IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8273             RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8274           ELSIF l_return_status = G_RET_STS_ERROR THEN
8275             RAISE FND_API.G_EXC_ERROR;
8276           END IF;
8277 
8278           END IF;
8279 
8280         IF l_valid_check <> 'Y' THEN
8281 
8282             FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_IB_INSTANCE_INV');
8283             FND_MESSAGE.Set_Token('INVENTORY_ITEM_ID', p_charges_detail_rec.inventory_item_id_in);
8284             FND_MESSAGE.Set_Token('INSTANCE_ID', p_charges_detail_rec.customer_product_id);
8285             FND_MSG_PUB.Add;
8286             RAISE FND_API.G_EXC_ERROR;
8287 
8288         ELSE
8289           l_valid_check := IS_INSTANCE_VALID(p_instance_id   => p_charges_detail_rec.customer_product_id,
8290                                p_party_id      => x_charges_detail_rec.sold_to_party_id,
8291                                x_msg_data      => l_msg_data,
8292                                x_msg_count     => l_msg_count,
8293                                x_return_status => l_return_status);
8294 
8295               IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8296                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8297               ELSIF l_return_status = G_RET_STS_ERROR THEN
8298                 RAISE FND_API.G_EXC_ERROR;
8299               END IF;
8300 
8301    --taklam
8302              IF l_valid_check <> 'Y' THEN
8303                 --Check if Service activity has 'change owner flag' set to 'N'
8304                 --(See the csi_ib_txn_types table for the flag value)
8305                 --'change owner flag'
8306 
8307                 OPEN C_SRC_CHANGE_OWNER(p_charges_detail_rec.txn_billing_type_id);
8308                 FETCH C_SRC_CHANGE_OWNER INTO l_src_change_owner;
8309                 CLOSE C_SRC_CHANGE_OWNER;
8310 
8311                 If (l_src_change_owner = 'N') or (l_src_change_owner is null) THEN
8312                   --Pass the internal_party_id to the existing "IS_INSTANCE_VALID" method.
8313                   --select internal_party_id from csi_install_parameters,
8314                   SELECT internal_party_id into l_internal_party_id
8315                   FROM csi_install_parameters;
8316 
8317                   l_valid_check := IS_INSTANCE_VALID( p_instance_id   => p_charges_detail_rec.customer_product_id,
8318                                                       p_party_id      => l_internal_party_id,
8319                                                       x_msg_data      => l_msg_data,
8320                                                       x_msg_count     => l_msg_count,
8321                                                       x_return_status => l_return_status);
8322                   IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8323                     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8324                   ELSIF l_return_status = G_RET_STS_ERROR THEN
8325                     RAISE FND_API.G_EXC_ERROR;
8326                   END IF;
8327                 End if;
8328              End if;
8329 
8330 
8331             IF l_valid_check <> 'Y' THEN
8332 
8333                   FND_MESSAGE.SET_NAME ('CS', 'CS_CHG_INVALID_INSTANCE_RMA_PT');
8334                   FND_MSG_PUB.Add;
8335                   RAISE FND_API.G_EXC_ERROR;
8336    --taklam
8337             ELSE
8338               --assign the customer product id to out record
8339               x_charges_detail_rec.customer_product_id := p_charges_detail_rec.customer_product_id;
8340               --DBMS_OUTPUT.PUT_LINE('Cust prod id '||x_charges_detail_rec.customer_product_id);
8341             END IF;
8342 
8343            -- check to see if its a serialized item
8344            -- Added for Bug # 4073602
8345            IF l_serial_control_flag = 'Y' THEN
8346              IF p_charges_detail_rec.serial_number IS NULL THEN
8347                -- no error raised
8348                -- Fix bug#5125934
8349                OPEN c_serial_number(p_charges_detail_rec.customer_product_id);
8350                FETCH c_serial_number
8351                INTO  l_serial_number;
8352                CLOSE c_serial_number;
8353 
8354                -- x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;
8355                -- x_charges_detail_rec.serial_number := l_serial_number;
8356 
8357              ELSIF p_charges_detail_rec.serial_number = FND_API.G_MISS_CHAR THEN
8358 
8359                --validate the serial number
8360                x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number; --5887316
8361 	       /*
8362 	       l_valid_check := IS_INSTANCE_SERIAL_VALID( p_instance_id   => x_charges_detail_rec.customer_product_id
8363                                                     ,p_serial_number => l_db_det_rec.serial_number
8364                                                     ,x_msg_data      => l_msg_data
8365                                                     ,x_msg_count     => l_msg_count
8366                                                     ,x_return_status => l_return_status);
8367 
8368                IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8369                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8370                ELSIF l_return_status = G_RET_STS_ERROR THEN
8371                  RAISE FND_API.G_EXC_ERROR;
8372                END IF;
8373 
8374                IF l_valid_check <> 'Y' THEN
8375                  FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_SERIAL_NUMBER');
8376                  FND_MESSAGE.Set_Token('INSTANCE_ID', p_charges_detail_rec.customer_product_id);
8377                  FND_MESSAGE.Set_Token('SERIAL_NUMBER', p_charges_detail_rec.serial_number);
8378                  FND_MSG_PUB.Add;
8379                  RAISE FND_API.G_EXC_ERROR;
8380                ELSE
8381                  --assign the customer product id to out record
8382                  x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;
8383                END IF;
8384                */--5887316
8385              ELSE
8386 
8387                --serial number is neither null nor fnd_api.g_miss
8388                -- value is passed
8389                --validate the serial number
8390                x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number; --5887316
8391 	       /*
8392 	       l_valid_check := IS_INSTANCE_SERIAL_VALID( p_instance_id   => x_charges_detail_rec.customer_product_id
8393                                                     ,p_serial_number => p_charges_detail_rec.serial_number
8394                                                     ,x_msg_data      => l_msg_data
8395                                                     ,x_msg_count     => l_msg_count
8396                                                     ,x_return_status => l_return_status);
8397                IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8398                  RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8399                ELSIF l_return_status = G_RET_STS_ERROR THEN
8400                  RAISE FND_API.G_EXC_ERROR;
8401                END IF;
8402 
8403                IF l_valid_check <> 'Y' THEN
8404                  FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_SERIAL_NUMBER');
8405                  FND_MESSAGE.Set_Token('INSTANCE_ID', p_charges_detail_rec.customer_product_id);
8406                  FND_MESSAGE.Set_Token('SERIAL_NUMBER', p_charges_detail_rec.serial_number);
8407                  FND_MSG_PUB.Add;
8408                  RAISE FND_API.G_EXC_ERROR;
8409                ELSE
8410                  --assign the customer product id to out record
8411                  x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;
8412                END IF;
8413                */ --5887316
8414 	     END IF;
8415            ELSE
8416              --customerproduct  id is null
8417              x_charges_detail_rec.serial_number := l_db_det_rec.serial_number ;
8418            END IF;
8419         END IF;
8420 
8421 
8422       --Fix for Bug # 3325686
8423       ELSIF
8424          p_charges_detail_rec.customer_product_id <> FND_API.G_MISS_NUM AND
8425          p_charges_detail_rec.customer_product_id IS NOT NULL AND
8426          x_charges_detail_rec.line_category_code = 'ORDER' THEN
8427 
8428           -- Added the FND Messages for Bug# 5141369
8429          IF (l_comms_trackable_flag = 'N') THEN
8430           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_INST_AND_INV');
8431           FND_MESSAGE.Set_Token('INSTANCE_ID', p_charges_detail_rec.customer_product_id);
8432           FND_MESSAGE.Set_Token('INVENTORY_ITEM_ID', p_charges_detail_rec.inventory_item_id_in);
8433           FND_MSG_PUB.Add;
8434           RAISE FND_API.G_EXC_ERROR;
8435          ELSE
8436          --Check if instance is valid for the party
8437          l_valid_check := IS_INSTANCE_VALID(p_instance_id   => p_charges_detail_rec.customer_product_id,
8438                                p_party_id      => x_charges_detail_rec.sold_to_party_id,
8439                                x_msg_data      => l_msg_data,
8440                                x_msg_count     => l_msg_count,
8441                                x_return_status => l_return_status);
8442 
8443               IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8444                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8445               ELSIF l_return_status = G_RET_STS_ERROR THEN
8446                 RAISE FND_API.G_EXC_ERROR;
8447               END IF;
8448          END IF;
8449 
8450           IF l_valid_check <> 'Y' THEN
8451 
8452               FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_IB_INSTANCE_PTY');
8453               FND_MESSAGE.Set_Token('PARTY_ID', x_charges_detail_rec.sold_to_party_id);
8454               FND_MESSAGE.Set_Token('INSTANCE_ID', p_charges_detail_rec.customer_product_id);
8455               FND_MSG_PUB.Add;
8456               RAISE FND_API.G_EXC_ERROR;
8457 
8458           ELSE
8459             --assign the customer product id to out record
8460             x_charges_detail_rec.customer_product_id := p_charges_detail_rec.customer_product_id;
8461             --DBMS_OUTPUT.PUT_LINE('Cust prod id '||x_charges_detail_rec.customer_product_id);
8462           END IF;
8463 
8464           -- check to see if its a serialized item
8465           -- Added for Bug # 4073602
8466           IF l_serial_control_flag = 'Y' THEN
8467             IF p_charges_detail_rec.serial_number IS NULL THEN
8468               -- Fix bug#5125934
8469                OPEN c_serial_number(p_charges_detail_rec.customer_product_id);
8470                FETCH c_serial_number
8471                INTO  l_serial_number;
8472                CLOSE c_serial_number;
8473 
8474                -- x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;
8475                x_charges_detail_rec.serial_number := l_serial_number;
8476 
8477             ELSIF p_charges_detail_rec.serial_number = FND_API.G_MISS_CHAR THEN
8478               --validate the serial number
8479               -- Added for Bug # 5471849
8480 	             IF l_db_det_rec.serial_number IS NOT NULL THEN
8481 	                -- dbms_output.put_line('Serial number test bug:5471849');
8482 	                x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;  --5887316
8483 			/*
8484 			l_valid_check := IS_INSTANCE_SERIAL_VALID( p_instance_id   => x_charges_detail_rec.customer_product_id
8485 	                                                    ,p_serial_number => l_db_det_rec.serial_number
8486 	                                                    ,x_msg_data      => l_msg_data
8487 	                                                    ,x_msg_count     => l_msg_count
8488 	                                                    ,x_return_status => l_return_status);
8489 
8490 	                 IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8491 	                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8492 	                 ELSIF l_return_status = G_RET_STS_ERROR THEN
8493 	                 RAISE FND_API.G_EXC_ERROR;
8494 	                 END IF;
8495 
8496 	                 IF l_valid_check <> 'Y' THEN
8497 	                 FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_SERIAL_NUMBER');
8498 	                 FND_MESSAGE.Set_Token('INSTANCE_ID', p_charges_detail_rec.customer_product_id);
8499 	                 FND_MESSAGE.Set_Token('SERIAL_NUMBER', p_charges_detail_rec.serial_number);
8500 	                 FND_MSG_PUB.Add;
8501 	                 RAISE FND_API.G_EXC_ERROR;
8502 	                 ELSE
8503 	                 --assign the customer product id to out record
8504 	                 x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;
8505 	                 END IF;
8506                         */ --5887316
8507 	              ELSE
8508 	                -- Added for the bug:5471849
8509 	                OPEN c_serial_number(p_charges_detail_rec.customer_product_id);
8510 	                FETCH c_serial_number
8511 	                INTO  l_serial_number;
8512 	                CLOSE c_serial_number;
8513 
8514 	                -- x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;
8515 	                 x_charges_detail_rec.serial_number := l_serial_number;
8516 	              END IF;
8517 
8518            ELSE
8519 
8520               --serial number is neither null nor fnd_api.g_miss
8521               -- value is passed
8522               --validate the serial number
8523               x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number; --5887316
8524 	      /*
8525 	      l_valid_check := IS_INSTANCE_SERIAL_VALID( p_instance_id   => x_charges_detail_rec.customer_product_id
8526                                                     ,p_serial_number => p_charges_detail_rec.serial_number
8527                                                     ,x_msg_data      => l_msg_data
8528                                                     ,x_msg_count     => l_msg_count
8529                                                     ,x_return_status => l_return_status);
8530 
8531               IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8532                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8533               ELSIF l_return_status = G_RET_STS_ERROR THEN
8534                 RAISE FND_API.G_EXC_ERROR;
8535               END IF;
8536 
8537               IF l_valid_check <> 'Y' THEN
8538                 FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_SERIAL_NUMBER');
8539                 FND_MESSAGE.Set_Token('INSTANCE_ID', p_charges_detail_rec.customer_product_id);
8540                 FND_MESSAGE.Set_Token('SERIAL_NUMBER', p_charges_detail_rec.serial_number);
8541                 FND_MSG_PUB.Add;
8542                 RAISE FND_API.G_EXC_ERROR;
8543               ELSE
8544                 --assign the customer product id to out record
8545                 x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;
8546               END IF;
8547               */ --5887316
8548 	    END IF;
8549 	  ELSE
8550             x_charges_detail_rec.serial_number := p_charges_detail_rec.serial_number;
8551           END IF; --serial number check
8552 
8553       ELSE
8554           --customerproduct  id is null
8555           x_charges_detail_rec.serial_number := l_db_det_rec.serial_number ;
8556       END IF;
8557 
8558 
8559     -- Checking for source and RETURN transactions to update installed_cp_return_by_date
8560     -- Fix for Bug # 3325686
8561     --fixed Bug # 3362130 - added l_comms_trackable_flag = 'Y' condition
8562     IF l_src_reference_reqd_flag = 'Y' AND
8563        l_src_return_reqd_flag = 'Y' AND
8564        l_line_order_category_code = 'RETURN' AND
8565        l_comms_trackable_flag = 'Y' THEN
8566        IF p_charges_detail_rec.installed_cp_return_by_date IS NULL THEN
8567          --RAISE FND_API.G_EXC_ERROR;
8568          --null;
8569          FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INST_CP_RETURN_BY_DATE');
8570          FND_MESSAGE.Set_Token('INST_CP_RTN_BY_DATE', p_charges_detail_rec.installed_cp_return_by_date);
8571          FND_MSG_PUB.Add;
8572          RAISE FND_API.G_EXC_ERROR;
8573        ELSIF p_charges_detail_rec.installed_cp_return_by_date <> FND_API.G_MISS_DATE THEN
8574          --assign to out record
8575          x_charges_detail_rec.installed_cp_return_by_date := p_charges_detail_rec.installed_cp_return_by_date;
8576        ELSE
8577          x_charges_detail_rec.installed_cp_return_by_date := l_db_det_rec.installed_cp_return_by_date;
8578        END IF;
8579       --ELSE
8580       -- the flag is 'N'
8581       -- ignore the installed_cp_return_by_date
8582       --x_charges_detail_rec.installed_cp_return_by_date := NULL;
8583     -- if the flags are not set, check for g_miss_date
8584     -- Modified for the return_by_date fix. Bug:5136853
8585     ELSIF p_charges_detail_rec.installed_cp_return_by_date <> FND_API.G_MISS_DATE THEN
8586       --assign to out record
8587       x_charges_detail_rec.installed_cp_return_by_date := p_charges_detail_rec.installed_cp_return_by_date;
8588     ELSE
8589       x_charges_detail_rec.installed_cp_return_by_date := l_db_det_rec.installed_cp_return_by_date;
8590     END IF;
8591 
8592     /***** RETURN BY DATE FIX FOR ORDER TRANSACTIONS *****/
8593     --
8594     -- Modified for the return_by_date fix. Bug:5136853
8595     -- If the instance is not null and the non_src retur_reqd flag is 'Y' ,
8596     -- then installed_cp_return_by_date column should have a value.
8597     -- Likewise if the instance is null and the item is trackable and the
8598     -- src_return_reqd field is 'y', the the new_cp_return_by_date should have a value.
8599     -- Otherwise raise appropriate errors. This validation is for 'ORDER'
8600 
8601     /*** non source flag checked for the 'ORDER' ***/
8602      IF l_non_src_reference_reqd_flag = 'Y' AND
8603         l_non_src_return_reqd_flag = 'Y' AND
8604         l_line_order_category_code = 'ORDER' AND
8605         l_comms_trackable_flag = 'Y' AND
8606         p_charges_detail_rec.customer_product_id IS NOT NULL THEN
8607        IF p_charges_detail_rec.installed_cp_return_by_date IS NULL THEN
8608          FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INSTALLED_CP_RETURN_BY_DATE');
8609          FND_MESSAGE.Set_Token('INSTALLED_CP_RTN_BY_DATE', p_charges_detail_rec.installed_cp_return_by_date);
8610          FND_MSG_PUB.Add;
8611          RAISE FND_API.G_EXC_ERROR;
8612        ELSIF  p_charges_detail_rec.installed_cp_return_by_date  <> FND_API.G_MISS_DATE THEN
8613          x_charges_detail_rec.installed_cp_return_by_date := p_charges_detail_rec.installed_cp_return_by_date;
8614        ELSE
8615          x_charges_detail_rec.installed_cp_return_by_date := l_db_det_rec.installed_cp_return_by_date;
8616        END IF;
8617      -- if the flags are not set, check for g_miss_date
8618      ELSIF p_charges_detail_rec.installed_cp_return_by_date <> FND_API.G_MISS_DATE THEN
8619        -- Assign whatever value is passed in the parameter.
8620        x_charges_detail_rec.installed_cp_return_by_date := p_charges_detail_rec.installed_cp_return_by_date;
8621      ELSE
8622        x_charges_detail_rec.installed_cp_return_by_date := l_db_det_rec.installed_cp_return_by_date;
8623      END IF;
8624 
8625     /*** Source Flag checked for the 'Order' ***/
8626     IF  l_src_reference_reqd_flag = 'Y' AND
8627         l_src_return_reqd_flag = 'Y' AND
8628         l_line_order_category_code = 'ORDER' AND
8629         l_comms_trackable_flag = 'Y' AND
8630         p_charges_detail_rec.customer_product_id IS NULL THEN
8631       IF p_charges_detail_rec.new_cp_return_by_date IS NULL THEN
8632         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_NEW_CP_RETURN_BY_DATE');
8633         FND_MESSAGE.Set_Token('NEW_CP_RTN_BY_DATE', p_charges_detail_rec.new_cp_return_by_date);
8634         FND_MSG_PUB.Add;
8635         RAISE FND_API.G_EXC_ERROR;
8636       ELSIF p_charges_detail_rec.new_cp_return_by_date <> FND_API.G_MISS_DATE THEN
8637         -- Assign whatever value is passed in the parameter.
8638         x_charges_detail_rec.new_cp_return_by_date := p_charges_detail_rec.new_cp_return_by_date;
8639       ELSE
8640         x_charges_detail_rec.new_cp_return_by_date := l_db_det_rec.new_cp_return_by_date;
8641       END IF;
8642     ELSIF p_charges_detail_rec.new_cp_return_by_date <> FND_API.G_MISS_DATE THEN
8643       -- Assign whatever value is passed in the parameter.
8644       x_charges_detail_rec.new_cp_return_by_date := p_charges_detail_rec.new_cp_return_by_date;
8645     ELSE
8646       x_charges_detail_rec.new_cp_return_by_date := l_db_det_rec.new_cp_return_by_date;
8647     END IF;
8648 
8649 
8650     /**** -- Depot Loaner fix - Bug#4586140
8651     Open c_get_depot_txns_details(p_charges_detail_rec.estimate_detail_id);
8652     Fetch c_get_depot_txns_details into l_action_code;
8653     Close c_get_depot_txns_details;
8654 
8655     -- Checking for non-source and ORDER transactions to update new_cp_return_by_date
8656     -- Fix for Bug # 3325686
8657     --fixed Bug # 3362130 - added l_comms_trackable_flag = 'Y' condition
8658     IF l_non_src_reference_reqd_flag = 'Y' AND
8659        l_non_src_return_reqd  = 'Y' AND
8660        l_line_order_category_code = 'ORDER' AND
8661        l_comms_trackable_flag = 'Y' THEN
8662       IF p_charges_detail_rec.new_cp_return_by_date IS NULL THEN
8663         --RAISE FND_API.G_EXC_ERROR;
8664         --null;
8665         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INST_CP_RETURN_BY_DATE');
8666         FND_MESSAGE.Set_Token('INST_CP_RTN_BY_DATE', p_charges_detail_rec.installed_cp_return_by_date);
8667         FND_MSG_PUB.Add;
8668         RAISE FND_API.G_EXC_ERROR;
8669       ELSIF p_charges_detail_rec.new_cp_return_by_date <> FND_API.G_MISS_DATE THEN
8670             --assign to out record
8671             x_charges_detail_rec.new_cp_return_by_date := p_charges_detail_rec.new_cp_return_by_date;
8672       ELSE
8673             x_charges_detail_rec.new_cp_return_by_date := l_db_det_rec.new_cp_return_by_date;
8674       END IF;
8675     -- Depot Loaner fix - Bug#4586140
8676     ELSIF ( l_line_order_category_code = 'ORDER' AND
8677             l_comms_trackable_flag = 'Y' AND
8678             l_src_return_reqd_flag = 'Y' AND
8679             l_action_code = 'LOANER') THEN
8680 
8681         x_charges_detail_rec.new_cp_return_by_date := p_charges_detail_rec.new_cp_return_by_date;
8682     ELSE
8683       -- the flag is 'N'
8684       -- ignore the installed_cp_return_by_date
8685       x_charges_detail_rec.new_cp_return_by_date := NULL;
8686     END IF;  ****/
8687 END IF;
8688 --DBMS_OUTPUT.PUT_LINE('Item Instance Valid');
8689 
8690 --=====================================
8691 -- Return Reason Code Validation
8692 --=====================================
8693 --DBMS_OUTPUT.PUT_LINE('Return Reason Code Validation ...');
8694 IF p_validation_mode = 'I' THEN
8695 
8696   IF l_line_order_category_code = 'RETURN' THEN
8697     IF p_charges_detail_rec.return_reason_code IS NULL THEN
8698       --RAISE FND_API.G_EXC_ERROR;
8699       --null;
8700       FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_RETURN_REASON');
8701       FND_MESSAGE.Set_Token('RETURN_REASON_CODE', p_charges_detail_rec.return_reason_code);
8702       FND_MSG_PUB.Add;
8703       RAISE FND_API.G_EXC_ERROR;
8704     ELSE
8705 
8706       --return reason code is not null
8707       --validate the return reason code
8708 
8709       l_valid_check := IS_RETURN_REASON_VALID(p_return_reason_code => p_charges_detail_rec.return_reason_code,
8710                                 x_msg_data           => l_msg_data,
8711                                 x_msg_count          => l_msg_count,
8712                                 x_return_status      => l_return_status);
8713 
8714       IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8715         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8716       ELSIF l_return_status = G_RET_STS_ERROR THEN
8717         RAISE FND_API.G_EXC_ERROR;
8718       END IF;
8719 
8720       IF l_valid_check <> 'Y' THEN
8721 
8722         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_RETURN_REASON');
8723         FND_MESSAGE.Set_Token('RETURN_REASON_CODE', p_charges_detail_rec.return_reason_code);
8724         FND_MSG_PUB.Add;
8725         RAISE FND_API.G_EXC_ERROR;
8726       ELSE
8727         x_charges_detail_rec.return_reason_code := p_charges_detail_rec.return_reason_code;
8728       END IF;
8729 
8730     END IF;
8731 
8732   ELSE
8733 
8734     IF l_line_order_category_code = 'ORDER' OR l_line_order_category_code IS NULL THEN
8735       IF p_charges_detail_rec.return_reason_code IS NOT NULL THEN
8736         --RAISE FND_API.G_EXC_ERROR;
8737         --null;
8738         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_RETURN_REASON');
8739         FND_MESSAGE.Set_Token('RETURN_REASON_CODE', p_charges_detail_rec.return_reason_code);
8740         FND_MSG_PUB.Add;
8741         RAISE FND_API.G_EXC_ERROR;
8742       END IF;
8743     END IF;
8744     x_charges_detail_rec.return_reason_code := p_charges_detail_rec.return_reason_code;
8745 
8746   END IF;
8747 
8748 ELSIF p_validation_mode = 'U' THEN
8749 
8750   IF l_line_order_category_code = 'RETURN' THEN
8751 
8752     IF p_charges_detail_rec.return_reason_code <> FND_API.G_MISS_CHAR AND
8753        p_charges_detail_rec.return_reason_code IS NOT NULL THEN
8754 
8755       l_valid_check := IS_RETURN_REASON_VALID(p_return_reason_code => p_charges_detail_rec.return_reason_code,
8756                                 x_msg_data           => l_msg_data,
8757                                 x_msg_count          => l_msg_count,
8758                                 x_return_status      => l_return_status);
8759 
8760       IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8761         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8762       ELSIF l_return_status = G_RET_STS_ERROR THEN
8763         RAISE FND_API.G_EXC_ERROR;
8764       END IF;
8765 
8766       IF l_valid_check <> 'Y' THEN
8767 
8768         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_RETURN_REASON');
8769         FND_MESSAGE.Set_Token('RETURN_REASON_CODE', p_charges_detail_rec.return_reason_code);
8770         FND_MSG_PUB.Add;
8771         RAISE FND_API.G_EXC_ERROR;
8772       ELSE
8773         x_charges_detail_rec.return_reason_code := p_charges_detail_rec.return_reason_code;
8774       END IF;
8775 
8776     ELSE
8777       -- If not passed then
8778       -- assign from db record
8779       x_charges_detail_rec.return_reason_code := l_db_det_rec.return_reason_code;
8780     END IF;
8781   END IF;
8782 END IF;
8783 
8784 --DBMS_OUTPUT.PUT_LINE('Return Reason COde Successful ....');
8785 
8786 --========================================
8787 -- Qty Required Validation
8788 --========================================
8789 
8790 --DBMS_OUTPUT.PUT_LINE('Qty Required Validation ...');
8791 
8792 IF p_validation_mode = 'I' THEN
8793 
8794   --DBMS_OUTPUT.PUT_LINE('Insert Mode');
8795 
8796   IF (((l_line_order_category_code = 'RETURN') AND
8797        (p_charges_detail_rec.return_reason_code IS NOT NULL) AND
8798        (p_charges_detail_rec.quantity_required IS NOT NULL))) THEN
8799 
8800        IF sign(p_charges_detail_rec.quantity_required) = -1 THEN
8801          x_charges_detail_rec.quantity_required := p_charges_detail_rec.quantity_required;
8802        ELSE
8803          --assign -ve qty to out record
8804          x_charges_detail_rec.quantity_required := (p_charges_detail_rec.quantity_required * -1);
8805        END IF;
8806   ELSE
8807 
8808     IF p_charges_detail_rec.quantity_required IS NOT NULL THEN
8809       -- Added to fix bug # 5147727
8810       IF sign(p_charges_detail_rec.quantity_required) = -1 THEN
8811         -- need to make this positive as no -ve quantity for orders
8812         x_charges_detail_rec.quantity_required := (p_charges_detail_rec.quantity_required * -1);
8813       ELSE
8814         x_charges_detail_rec.quantity_required := p_charges_detail_rec.quantity_required;
8815       END IF;
8816 
8817     ELSE
8818       --Added to fix bug # 3217757
8819       --debriefed expense line not displaying correct amount
8820       --This is to default 1 for qty if qty is null
8821 
8822       --Added to fix bug # 4205915
8823       IF ((l_line_order_category_code = 'RETURN') AND
8824          (p_charges_detail_rec.return_reason_code IS NOT NULL)) THEN
8825 
8826          x_charges_detail_rec.quantity_required := -1;
8827       ELSE
8828          x_charges_detail_rec.quantity_required := 1;
8829       END IF;
8830     END IF;
8831   END IF;
8832 
8833 ELSIF p_validation_mode = 'U' THEN
8834 
8835   --DBMS_OUTPUT.PUT_LINE('Update Mode');
8836 
8837   --DBMS_OUTPUT.PUT_LINE('p_charges_detail_rec.quantity_required '||p_charges_detail_rec.quantity_required);
8838 
8839   IF p_charges_detail_rec.quantity_required = FND_API.G_MISS_NUM OR
8840      p_charges_detail_rec.quantity_required IS NULL THEN
8841 
8842      --DBMS_OUTPUT.PUT_LINE('Quantity Required not passed');
8843      x_charges_detail_rec.quantity_required  := l_db_det_rec.quantity_required ;
8844      --DBMS_OUTPUT.PUT_LINE('Quantity required is '||x_charges_detail_rec.quantity_required);
8845 
8846   ELSE
8847      /* Bug# 4870051
8848      IF l_db_det_rec.rollup_flag = 'Y'  THEN
8849          Cant_Update_Detail_Param_Msg(l_api_name_full,
8850                                       'QUANTITY_REQUIRED',
8851                                       to_char(p_charges_detail_rec.quantity_required));
8852          RAISE FND_API.G_EXC_ERROR;
8853      ELSE*/
8854          IF (((l_line_order_category_code = 'RETURN') AND
8855               (x_charges_detail_rec.return_reason_code IS NOT NULL) AND
8856               (p_charges_detail_rec.quantity_required IS NOT NULL))) THEN
8857 
8858                IF sign(p_charges_detail_rec.quantity_required) = -1 THEN
8859                  x_charges_detail_rec.quantity_required := p_charges_detail_rec.quantity_required;
8860                ELSE
8861                  --assign -ve qty to out record
8862                  x_charges_detail_rec.quantity_required := (p_charges_detail_rec.quantity_required * -1);
8863                END IF;
8864          ELSE
8865            -- Added below for Bug# 5147727
8866            IF sign(p_charges_detail_rec.quantity_required) = -1 THEN
8867              -- need to make this positive as no -ve quantity for orders
8868              x_charges_detail_rec.quantity_required := (p_charges_detail_rec.quantity_required * -1);
8869            ELSE
8870              x_charges_detail_rec.quantity_required  := p_charges_detail_rec.quantity_required ;
8871            END IF;
8872             --DBMS_OUTPUT.PUT_LINE('Quantity required is '||x_charges_detail_rec.quantity_required);
8873 
8874          END IF;
8875 
8876          --Condition added to fix Bug # 3358531
8877          IF x_charges_detail_rec.quantity_required  <> l_db_det_rec.quantity_required THEN
8878           --quantity required is changed need to re-calculate the list price
8879           l_calc_sp := 'Y';
8880         END IF;
8881       --Bug# 4870051 END IF ;
8882   END IF ;
8883 END IF;
8884 
8885 --DBMS_OUTPUT.PUT_LINE('Qty Required Validation Successful...');
8886 
8887 
8888 --=================================================
8889 --Validate Incoming Price List and Currency Code
8890 --=================================================
8891 --DBMS_OUTPUT.PUT_LINE('Validate Incoming Price List and Currency Code ...');
8892 
8893 IF p_validation_mode IN ( 'I', 'U') THEN
8894 
8895   --DBMS_OUTPUT.PUT_LINE(' Price List '||p_charges_detail_rec.price_list_id);
8896   --DBMS_OUTPUT.PUT_LINE(' Currency_code '||p_charges_detail_rec.currency_code);
8897 
8898   IF p_charges_detail_rec.price_list_id <> FND_API.G_MISS_NUM AND
8899      p_charges_detail_rec.price_list_id IS NOT NULL THEN
8900 
8901     l_valid_check := IS_PRICE_LIST_VALID(p_price_list_id => p_charges_detail_rec.price_list_id,
8902                            x_msg_data      => l_msg_data,
8903                            x_msg_count     => l_msg_count,
8904                            x_return_status => l_return_status);
8905 
8906       IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
8907         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8908       ELSIF l_return_status = G_RET_STS_ERROR THEN
8909         RAISE FND_API.G_EXC_ERROR;
8910       END IF;
8911 
8912     IF l_valid_check <> 'Y' THEN
8913         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_PRICE_LIST');
8914         FND_MESSAGE.Set_Token('PRICE_LIST_ID', p_charges_detail_rec.price_list_id);
8915         FND_MSG_PUB.Add;
8916         RAISE FND_API.G_EXC_ERROR;
8917 
8918     ELSE
8919 
8920       --DBMS_OUTPUT.PUT_LINE('Price List is valid');
8921 
8922       --assign the price_list_id to the out record
8923       x_charges_detail_rec.price_list_id := p_charges_detail_rec.price_list_id;
8924 
8925       -- get currency_code for the price_list_id
8926       GET_CURRENCY_CODE(
8927         p_api_name        => l_api_name,
8928         p_price_list_id   => p_charges_detail_rec.price_list_id,
8929         x_currency_code   => l_currency_code,
8930         x_msg_data        => l_msg_data,
8931         x_msg_count       => l_msg_count,
8932         x_return_status   => l_return_status);
8933 
8934       IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
8935         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
8936         FND_MESSAGE.Set_Token('PRICE_LIST_ID', p_charges_detail_rec.price_list_id);
8937         --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
8938         FND_MSG_PUB.Add;
8939         RAISE FND_API.G_EXC_ERROR;
8940       END IF ;
8941 
8942       --DBMS_OUTPUT.PUT_LINE('Currency_code '||l_currency_code);
8943 
8944       IF (p_charges_detail_rec.currency_code <> FND_API.G_MISS_CHAR AND
8945           p_charges_detail_rec.currency_code IS NOT NULL) AND
8946          (l_currency_code IS NOT NULL) AND
8947          (p_charges_detail_rec.currency_code <> l_currency_code) THEN
8948         --RAISE FND_API.G_EXC_ERROR;
8949         --null;
8950         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_CURRENCY_CODE');
8951         FND_MESSAGE.Set_Token('CURRENCY_CODE', p_charges_detail_rec.currency_code);
8952         FND_MSG_PUB.Add;
8953         RAISE FND_API.G_EXC_ERROR;
8954       ELSIF (p_charges_detail_rec.currency_code IS NULL) AND
8955             (l_currency_code IS NOT NULL) THEN
8956 
8957           x_charges_detail_rec.currency_code := l_currency_code;
8958 
8959       --ELSIF (p_charges_detail_rec.currency_code IS NOT NULL) AND
8960       --        (l_currency_code IS NULL) THEN
8961       ELSE
8962           --assign currency_code to out record
8963           x_charges_detail_rec.currency_code := p_charges_detail_rec.currency_code;
8964       END IF;
8965     END IF;
8966 
8967   END IF;
8968 END IF;
8969 
8970 
8971 --===================================
8972 --Validate Contract Information
8973 --===================================
8974 --DBMS_OUTPUT.PUT_LINE('Validate Contract Information ...');
8975 
8976 
8977 IF l_incident_date is NOT NULL THEN
8978   l_request_date := l_incident_date;
8979   --DBMS_OUTPUT.PUT_LINE('l_request_date : '||l_request_date);
8980 
8981 ELSE
8982   l_request_date := l_creation_date;
8983   --DBMS_OUTPUT.PUT_LINE('l_request_date : '||l_request_date);
8984 END IF;
8985 
8986 IF p_validation_mode = 'I' THEN
8987 
8988   --DBMS_OUTPUT.PUT_LINE('Contract Validation');
8989   --DBMS_OUTPUT.PUT_LINE('p_charges_detail_rec.contract_id = ' || p_charges_detail_rec.contract_id);
8990   --DBMS_OUTPUT.PUT_LINE('p_charges_detail_rec.coverage_id = ' || p_charges_detail_rec.coverage_id);
8991   --DBMS_OUTPUT.PUT_LINE('p_charges_detail_rec.coverage_txn_group_id = ' || p_charges_detail_rec.coverage_txn_group_id);
8992 
8993   -- if rate_type is passed then pass it down to the application
8994   IF p_charges_detail_rec.rate_type_code IS NOT NULL THEN
8995     x_charges_detail_rec.rate_type_code := p_charges_detail_rec.rate_type_code;
8996   ELSE
8997     x_charges_detail_rec.rate_type_code := null;
8998   END IF;
8999 
9000 
9001 
9002   --Changed for R12 - always use the contract_line_id
9003   IF p_charges_detail_rec.contract_line_id IS NOT NULL THEN
9004     --validate the contract_line_id
9005     l_valid_check := IS_CONTRACT_LINE_VALID(
9006                       p_contract_line_id      => p_charges_detail_rec.contract_line_id,
9007                       x_contract_id           => x_charges_detail_rec.contract_id,
9008                       x_msg_data              => l_msg_data,
9009                       x_msg_count             => l_msg_count,
9010                       x_return_status         => l_return_status);
9011 
9012     IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
9013       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9014     ELSIF l_return_status = G_RET_STS_ERROR THEN
9015       RAISE FND_API.G_EXC_ERROR;
9016     END IF;
9017 
9018     IF l_valid_check <> 'Y' THEN
9019 
9020       FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_CONTRACT_LINE');
9021       FND_MESSAGE.Set_Token('CONTRACT_LINE_ID', p_charges_detail_rec.contract_Line_id);
9022       FND_MSG_PUB.Add;
9023       RAISE FND_API.G_EXC_ERROR;
9024     ELSE
9025       --assign this value to the out parameter
9026       x_charges_detail_rec.contract_line_id := p_charges_detail_rec.contract_line_id;
9027     END IF;
9028   ELSIF p_charges_detail_rec.coverage_id IS NOT NULL THEN
9029     --need to derive the coverage_line_id using the coverage_id
9030 
9031       x_charges_detail_rec.contract_line_id  := GET_CONTRACT_LINE_ID(p_charges_detail_rec.coverage_id,
9032                                                                      l_msg_data,
9033                                                                      x_msg_count,
9034                                                                      x_return_status);
9035 
9036          IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
9037           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9038          ELSIF l_return_status = G_RET_STS_ERROR THEN
9039           RAISE FND_API.G_EXC_ERROR;
9040          END IF;
9041 
9042          IF x_charges_detail_rec.contract_line_id = 0 THEN
9043             Add_Invalid_Argument_Msg(l_api_name,
9044                                  l_contract_line_id,
9045                                  'Contract Line ID');
9046 
9047             RAISE FND_API.G_EXC_ERROR;
9048          END IF;
9049    ELSE
9050        --Fixed Bug # 5022118  Added condition for Depot Repair Task lines
9051        IF l_contract_service_id IS NOT NULL AND
9052           p_charges_detail_rec.original_source_code <> 'DR' AND
9053           p_charges_detail_rec.source_code <> 'SD' THEN
9054          --assign this to the x_charges_detail_rec.contract_line_id
9055          x_charges_detail_rec.contract_line_id := l_contract_service_id;
9056        ELSE
9057          x_charges_detail_rec.contract_line_id := null;
9058        END IF;
9059    END IF;
9060 
9061 
9062 
9063   -- Initialize contract values.
9064   x_charges_detail_rec.contract_id := null;
9065   x_charges_detail_rec.coverage_id := null;
9066   x_charges_detail_rec.coverage_txn_group_id := null;
9067 
9068   IF (p_charges_detail_rec.contract_id IS NOT NULL) THEN
9069      --(p_charges_detail_rec.coverage_id IS NOT NULL) AND
9070      --(p_charges_detail_rec.coverage_txn_group_id IS NOT NULL) THEN
9071 
9072     --Validate Contract
9073 
9074     l_valid_check := IS_CONTRACT_VALID(
9075                          p_contract_id           =>  p_charges_detail_rec.contract_id,
9076                          x_msg_data              =>  l_msg_data,
9077                          x_msg_count             =>  l_msg_count,
9078                          x_return_status         =>  l_return_status);
9079 
9080       IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
9081         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9082       ELSIF l_return_status = G_RET_STS_ERROR THEN
9083         RAISE FND_API.G_EXC_ERROR;
9084       END IF;
9085 
9086       IF l_valid_check <> 'Y' THEN
9087 
9088         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_CONTRACT');
9089         FND_MESSAGE.Set_Token('CONTRACT_ID', p_charges_detail_rec.contract_id);
9090         --FND_MESSAGE.Set_Token('COVERAGE_ID', p_charges_detail_rec.coverage_id, TRUE);
9091         --FND_MESSAGE.Set_Token('BUSINESS_PROCESS_ID', p_charges_detail_rec.business_process_id, TRUE);
9092         FND_MSG_PUB.Add;
9093         RAISE FND_API.G_EXC_ERROR;
9094 
9095       ELSE
9096 
9097       --Contract is valid, assign to out record
9098       x_charges_detail_rec.contract_id := p_charges_detail_rec.contract_id;
9099 
9100       -- get price list for the contract
9101       GET_CONTRACT_PRICE_LIST(
9102           p_api_name              => l_api_name,
9103           p_business_process_id   => x_charges_detail_rec.business_process_id,
9104           p_request_date          => l_request_date,
9105           p_contract_line_id      => x_charges_detail_rec.contract_line_id,
9106           x_price_list_id         => l_price_list_id,
9107           x_currency_code         => l_currency_code,
9108           x_msg_data              => l_msg_data,
9109           x_msg_count             => l_msg_count,
9110           x_return_status         => l_return_status);
9111 
9112       IF p_charges_detail_rec.price_list_id IS NOT NULL AND
9113          l_price_list_id IS NOT NULL AND
9114          p_charges_detail_rec.price_list_id <> l_price_list_id THEN
9115 
9116          --Fixed To resolve Bug # 3557490
9117          --do nothing
9118          --since the price list is already derived there is no need to validate again
9119          --use the price list sent by the upstream application
9120          x_charges_detail_rec.price_list_id := p_charges_detail_rec.price_list_id;
9121 
9122          -- get currency_code for the price_list_id
9123          GET_CURRENCY_CODE(
9124               p_api_name        => l_api_name,
9125               p_price_list_id   => x_charges_detail_rec.price_list_id,
9126               x_currency_code   => l_currency_code,
9127               x_msg_data        => l_msg_data,
9128               x_msg_count       => l_msg_count,
9129               x_return_status   => l_return_status);
9130 
9131          IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9132           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
9133           FND_MESSAGE.Set_Token('PRICE_LIST_ID', p_charges_detail_rec.price_list_id);
9134           --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
9135           FND_MSG_PUB.Add;
9136           RAISE FND_API.G_EXC_ERROR;
9137          END IF ;
9138 
9139          x_charges_detail_rec.currency_code := l_currency_code;
9140 
9141       ELSIF p_charges_detail_rec.price_list_id IS NULL AND
9142             l_price_list_id IS NOT NULL THEN
9143         x_charges_detail_rec.price_list_id := l_price_list_id;
9144         x_charges_detail_rec.currency_code := l_currency_code;
9145 
9146       ELSIF p_charges_detail_rec.price_list_id IS NOT NULL AND
9147             l_price_list_id IS NULL THEN
9148 
9149         x_charges_detail_rec.price_list_id := p_charges_detail_rec.price_list_id;
9150         -- get currency_code for the price_list_id
9151         GET_CURRENCY_CODE(
9152               p_api_name        => l_api_name,
9153               p_price_list_id   => p_charges_detail_rec.price_list_id,
9154               x_currency_code   => l_currency_code,
9155               x_msg_data        => l_msg_data,
9156               x_msg_count       => l_msg_count,
9157               x_return_status   => l_return_status);
9158 
9159         IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9160          FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
9161          FND_MESSAGE.Set_Token('PRICE_LIST_ID', p_charges_detail_rec.price_list_id);
9162          --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
9163          FND_MSG_PUB.Add;
9164          RAISE FND_API.G_EXC_ERROR;
9165         END IF ;
9166 
9167         x_charges_detail_rec.currency_code := l_currency_code;
9168 
9169       ELSIF p_charges_detail_rec.price_list_id IS NULL AND
9170             l_price_list_id IS NULL THEN
9171 
9172         --use the default from the price list
9173         x_charges_detail_rec.price_list_id := to_number(fnd_profile.value('CS_CHARGE_DEFAULT_PRICE_LIST'));
9174 
9175       IF FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level
9176       THEN
9177 	FND_LOG.String
9178 	( FND_LOG.level_procedure , L_LOG_MODULE || ''
9179 	, 'The Value of profile CS_CHARGE_DEFAULT_PRICE_LIST :' || x_charges_detail_rec.price_list_id
9180 	);
9181       END IF;
9182 
9183         -- get currency_code for the price_list_id
9184         GET_CURRENCY_CODE(
9185               p_api_name        => l_api_name,
9186               p_price_list_id   => x_charges_detail_rec.price_list_id,
9187               x_currency_code   => l_currency_code,
9188               x_msg_data        => l_msg_data,
9189               x_msg_count       => l_msg_count,
9190               x_return_status   => l_return_status);
9191 
9192         IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9193           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
9194           FND_MESSAGE.Set_Token('PRICE_LIST_ID', x_charges_detail_rec.price_list_id);
9195           --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
9196           FND_MSG_PUB.Add;
9197           RAISE FND_API.G_EXC_ERROR;
9198         END IF ;
9199         x_charges_detail_rec.currency_code := l_currency_code;
9200 
9201       END IF;
9202     END IF;
9203 
9204 
9205   -- For bugfix 3903911, vkjain.
9206   -- The charge contract is selectively applied for debrief lines.
9207   -- If the debrief lines originate from Depot Repair than RO contract
9208   -- is used. If there is no RO contract then SR contract should not be defaulted.
9209   -- Adding the NOT condition below to address the requirement.
9210   ELSIF l_contract_service_ID IS NOT NULL AND
9211         l_business_process_id IS NOT NULL AND
9212         NOT ( p_charges_detail_rec.original_source_code = 'DR' AND
9213               p_charges_detail_rec.source_code = 'SD') THEN
9214 
9215     -- p_charges_detail_rec.contract_id IS NULL AND
9216     -- p_charges_detail_rec.coverage_id IS NULL AND
9217     -- p_charges_detail_rec.coverage_txn_group_id IS NULL
9218     -- Check to see if there is a contract on SR
9219 
9220     --DBMS_OUTPUT.PUT_LINE('l_contract_id = ' || l_contract_id);
9221     --DBMS_OUTPUT.PUT_LINE('l_contract_service_ID = ' || l_contract_service_ID);
9222     --DBMS_OUTPUT.PUT_LINE('l_business_process_id = ' || l_business_process_id);
9223 
9224     GET_CONTRACT(
9225         p_api_name               => l_api_name,
9226         p_contract_SR_ID         => l_contract_service_id,
9227         p_incident_date          => l_incident_date,
9228         p_creation_date          => l_creation_date,
9229         p_customer_id            => l_customer_id,
9230         p_cust_account_id        => l_account_id,
9231         p_cust_product_id        => l_cust_product_id,
9232         p_system_id              => l_system_id,          -- Fix bug
9233         p_inventory_item_id      => l_inventory_item_id,  -- Fix bug
9234         p_business_process_id    => p_charges_detail_rec.business_process_id,
9235         x_contract_id            => l_contract_id,
9236         x_po_number              => l_po_number,
9237         x_return_status          => l_return_status,
9238         x_msg_count              => l_msg_count,
9239         x_msg_data               => l_msg_data);
9240 
9241         --DBMS_OUTPUT.PUT_LINE('l_contract_id = ' || l_contract_id);
9242 
9243         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
9244           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CONTRACT_API_ERROR');
9245           FND_MESSAGE.SET_TOKEN('BUSINESS_PROCESS_ID', p_charges_detail_rec.business_process_id);
9246           FND_MESSAGE.SET_TOKEN('CONTRACT_SERVICE_LINE_ID', l_contract_service_id);
9247           --FND_MESSAGE.SET_TOKEN('TEXT', l_msg_data);
9248           FND_MSG_PUB.Add;
9249           RAISE FND_API.G_EXC_ERROR;
9250         END IF;
9251 
9252         IF l_contract_id IS NOT NULL THEN
9253 
9254           x_charges_detail_rec.contract_id := l_contract_id;
9255 
9256 
9257           -- get price list for the contract
9258           GET_CONTRACT_PRICE_LIST(
9259             p_api_name              => l_api_name,
9260             p_business_process_id   => l_business_process_id,
9261             p_request_date          => l_request_date,
9262             p_contract_line_id      => l_contract_service_id,
9263             x_price_list_id         => l_price_list_id,
9264             x_currency_code         => l_currency_code,
9265             x_msg_data              => l_msg_data,
9266             x_msg_count             => l_msg_count,
9267             x_return_status         => l_return_status);
9268 
9269           IF p_charges_detail_rec.price_list_id IS NOT NULL AND
9270              l_price_list_id IS NOT NULL AND
9271              p_charges_detail_rec.price_list_id <> l_price_list_id THEN
9272 
9273              --Fixed To resolve Bug # 3557490
9274              --do nothing
9275              --since the price list is already derived there is no need to validate again
9276              --use the price list sent by the upstream application
9277              x_charges_detail_rec.price_list_id := p_charges_detail_rec.price_list_id;
9278 
9279              -- get currency_code for the price_list_id
9280              GET_CURRENCY_CODE(
9281                   p_api_name        => l_api_name,
9282                   p_price_list_id   => x_charges_detail_rec.price_list_id,
9283                   x_currency_code   => l_currency_code,
9284                   x_msg_data        => l_msg_data,
9285                   x_msg_count       => l_msg_count,
9286                   x_return_status   => l_return_status);
9287 
9288              IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9289                FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
9290                FND_MESSAGE.Set_Token('PRICE_LIST_ID', p_charges_detail_rec.price_list_id);
9291                --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
9292                FND_MSG_PUB.Add;
9293                RAISE FND_API.G_EXC_ERROR;
9294              END IF ;
9295 
9296              x_charges_detail_rec.currency_code := l_currency_code;
9297 
9298           ELSIF p_charges_detail_rec.price_list_id IS NULL AND
9299                 l_price_list_id IS NOT NULL THEN
9300             x_charges_detail_rec.price_list_id := l_price_list_id;
9301             x_charges_detail_rec.currency_code := l_currency_code;
9302           ELSIF p_charges_detail_rec.price_list_id IS NOT NULL AND
9303                 l_price_list_id IS NULL THEN
9304             x_charges_detail_rec.price_list_id := p_charges_detail_rec.price_list_id;
9305 
9306             -- get currency_code for the price_list_id
9307             GET_CURRENCY_CODE(
9308                   p_api_name        => l_api_name,
9309                   p_price_list_id   => p_charges_detail_rec.price_list_id,
9310                   x_currency_code   => l_currency_code,
9311                   x_msg_data        => l_msg_data,
9312                   x_msg_count       => l_msg_count,
9313                   x_return_status   => l_return_status);
9314 
9315             IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9316               FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
9317               FND_MESSAGE.Set_Token('PRICE_LIST_ID', p_charges_detail_rec.price_list_id);
9318               --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
9319               FND_MSG_PUB.Add;
9320               RAISE FND_API.G_EXC_ERROR;
9321             END IF ;
9322 
9323             x_charges_detail_rec.currency_code := l_currency_code;
9324 
9325           ELSIF p_charges_detail_rec.price_list_id IS NULL AND
9326                 l_price_list_id IS NULL THEN
9327 
9328             --use the default from the price list
9329             x_charges_detail_rec.price_list_id := to_number(fnd_profile.value('CS_CHARGE_DEFAULT_PRICE_LIST'));
9330 
9331       IF FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level
9332       THEN
9333 	FND_LOG.String
9334 	( FND_LOG.level_procedure , L_LOG_MODULE || ''
9335 	, 'The Value of profile CS_CHARGE_DEFAULT_PRICE_LIST :' || x_charges_detail_rec.price_list_id
9336 	);
9337       END IF;
9338 
9339             -- get currency_code for the price_list_id
9340             GET_CURRENCY_CODE(
9341                   p_api_name        => l_api_name,
9342                   p_price_list_id   => x_charges_detail_rec.price_list_id,
9343                   x_currency_code   => l_currency_code,
9344                   x_msg_data        => l_msg_data,
9345                   x_msg_count       => l_msg_count,
9346                   x_return_status   => l_return_status);
9347 
9348             IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9349               FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
9350               FND_MESSAGE.Set_Token('PRICE_LIST_ID', x_charges_detail_rec.price_list_id);
9351               --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
9352               FND_MSG_PUB.Add;
9353               RAISE FND_API.G_EXC_ERROR;
9354             END IF ;
9355             x_charges_detail_rec.currency_code := l_currency_code;
9356           END IF;
9357 
9358        ELSE
9359           -- consider this as no contract exists
9360           IF p_charges_detail_rec.price_list_id IS NULL THEN
9361             x_charges_detail_rec.price_list_id := to_number(fnd_profile.value('CS_CHARGE_DEFAULT_PRICE_LIST'));
9362 
9363             -- get currency_code for the price_list_id
9364             GET_CURRENCY_CODE(
9365                   p_api_name        => l_api_name,
9366                   p_price_list_id   => x_charges_detail_rec.price_list_id,
9367                   x_currency_code   => l_currency_code,
9368                   x_msg_data        => l_msg_data,
9369                   x_msg_count       => l_msg_count,
9370                   x_return_status   => l_return_status);
9371 
9372             IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9373               --RAISE FND_API.G_EXC_ERROR;
9374               FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
9375               FND_MESSAGE.Set_Token('PRICE_LIST_ID', x_charges_detail_rec.price_list_id);
9376               --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
9377               FND_MSG_PUB.Add;
9378               RAISE FND_API.G_EXC_ERROR;
9379             END IF ;
9380             x_charges_detail_rec.currency_code := l_currency_code;
9381           ELSE
9382 
9383             x_charges_detail_rec.price_list_id := p_charges_detail_rec.price_list_id;
9384 
9385             -- get currency_code for the price_list_id
9386             GET_CURRENCY_CODE(
9387                   p_api_name        => l_api_name,
9388                   p_price_list_id   => x_charges_detail_rec.price_list_id,
9389                   x_currency_code   => l_currency_code,
9390                   x_msg_data        => l_msg_data,
9391                   x_msg_count       => l_msg_count,
9392                   x_return_status   => l_return_status);
9393             IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9394               --RAISE FND_API.G_EXC_ERROR;
9395               FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
9396               FND_MESSAGE.Set_Token('PRICE_LIST_ID', x_charges_detail_rec.price_list_id);
9397               --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
9398               FND_MSG_PUB.Add;
9399               RAISE FND_API.G_EXC_ERROR;
9400             END IF ;
9401             x_charges_detail_rec.currency_code := l_currency_code;
9402           END IF;
9403         END IF;
9404 
9405 
9406   ELSE
9407     --no contract exists
9408     IF p_charges_detail_rec.price_list_id IS NULL THEN
9409        x_charges_detail_rec.price_list_id := to_number(fnd_profile.value('CS_CHARGE_DEFAULT_PRICE_LIST'));
9410 
9411       -- get currency_code for the price_list_id
9412       GET_CURRENCY_CODE(
9413             p_api_name        => l_api_name,
9414             p_price_list_id   => x_charges_detail_rec.price_list_id,
9415             x_currency_code   => l_currency_code,
9416             x_msg_data        => l_msg_data,
9417             x_msg_count       => l_msg_count,
9418             x_return_status   => l_return_status);
9419 
9420       IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9421         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
9422         FND_MESSAGE.Set_Token('PRICE_LIST_ID', x_charges_detail_rec.price_list_id);
9423         --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
9424         FND_MSG_PUB.Add;
9425         RAISE FND_API.G_EXC_ERROR;
9426       END IF ;
9427       x_charges_detail_rec.currency_code := l_currency_code;
9428 
9429     ELSE
9430       x_charges_detail_rec.price_list_id := p_charges_detail_rec.price_list_id;
9431 
9432       -- get currency_code for the price_list_id
9433       GET_CURRENCY_CODE(
9434             p_api_name        => l_api_name,
9435             p_price_list_id   => x_charges_detail_rec.price_list_id,
9436             x_currency_code   => l_currency_code,
9437             x_msg_data        => l_msg_data,
9438             x_msg_count       => l_msg_count,
9439             x_return_status   => l_return_status);
9440       IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9441         --RAISE FND_API.G_EXC_ERROR;
9442         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
9443         FND_MESSAGE.Set_Token('PRICE_LIST_ID', x_charges_detail_rec.price_list_id);
9444         --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
9445         FND_MSG_PUB.Add;
9446         RAISE FND_API.G_EXC_ERROR;
9447       END IF ;
9448       x_charges_detail_rec.currency_code := l_currency_code;
9449     END IF;
9450   END IF;
9451 
9452 ELSIF p_validation_mode = 'U' THEN
9453 
9454  --DBMS_OUTPUT.PUT_LINE('Contract Validation for update');
9455  --DBMS_OUTPUT.PUT_LINE('p_charges_detail_rec.contract_id = ' || p_charges_detail_rec.contract_id);
9456  --DBMS_OUTPUT.PUT_LINE('p_charges_detail_rec.coverage_id = ' || p_charges_detail_rec.coverage_id);
9457  --DBMS_OUTPUT.PUT_LINE('p_charges_detail_rec.coverage_txn_group_id = ' || p_charges_detail_rec.coverage_txn_group_id);
9458 
9459   -- if rate_type is passed then pass it down to the application
9460   IF p_charges_detail_rec.rate_type_code IS NOT NULL AND
9461      p_charges_detail_rec.rate_type_code <> FND_API.G_MISS_CHAR THEN
9462      -- value is passed
9463     x_charges_detail_rec.rate_type_code := p_charges_detail_rec.rate_type_code;
9464   ELSE
9465     IF p_charges_detail_rec.rate_type_code IS NULL THEN
9466       --nullify the rate_type_code on the charge line
9467       x_charges_detail_rec.rate_type_code := null;
9468     ELSE
9469       --take the one from the database;
9470       x_charges_detail_rec.rate_type_code := l_db_det_rec.rate_type_code;
9471     END IF;
9472 
9473   END IF;
9474 
9475 
9476 
9477   --Changed for R12 - always use the contract_line_id
9478   IF p_charges_detail_rec.contract_line_id IS NOT NULL AND
9479      p_charges_detail_rec.contract_line_id <> FND_API.G_MISS_NUM THEN
9480     --validate the contract_line_id
9481     l_valid_check := IS_CONTRACT_LINE_VALID(
9482                       p_contract_line_id      => p_charges_detail_rec.contract_line_id,
9483                       x_contract_id           => x_charges_detail_rec.contract_id,
9484                       x_msg_data              => l_msg_data,
9485                       x_msg_count             => l_msg_count,
9486                       x_return_status         => l_return_status);
9487 
9488     IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
9489       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9490     ELSIF l_return_status = G_RET_STS_ERROR THEN
9491       RAISE FND_API.G_EXC_ERROR;
9492     END IF;
9493 
9494     IF l_valid_check <> 'Y' THEN
9495 
9496       FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_CONTRACT');
9497       FND_MESSAGE.Set_Token('CONTRACT_ID', p_charges_detail_rec.contract_id);
9498       FND_MSG_PUB.Add;
9499       RAISE FND_API.G_EXC_ERROR;
9500     ELSE
9501       --assign this value to the out parameter
9502       x_charges_detail_rec.contract_line_id := p_charges_detail_rec.contract_line_id;
9503     END IF;
9504   ELSIF p_charges_detail_rec.coverage_id IS NOT NULL AND
9505         p_charges_detail_rec.coverage_id <> FND_API.G_MISS_NUM THEN
9506 
9507     --need to derive the coverage_line_id using the new coverage_id
9508 
9509       x_charges_detail_rec.contract_line_id  := GET_CONTRACT_LINE_ID(p_charges_detail_rec.coverage_id,
9510                                                                      l_msg_data,
9511                                                                      x_msg_count,
9512                                                                      x_return_status);
9513 
9514          IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
9515           RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9516          ELSIF l_return_status = G_RET_STS_ERROR THEN
9517           RAISE FND_API.G_EXC_ERROR;
9518          END IF;
9519 
9520          IF x_charges_detail_rec.contract_line_id = 0 THEN
9521             Add_Invalid_Argument_Msg(l_api_name,
9522                                  l_contract_line_id,
9523                                  'Contract Line ID');
9524 
9525             RAISE FND_API.G_EXC_ERROR;
9526          END IF;
9527    ELSE
9528        IF p_charges_detail_rec.contract_line_id IS NULL THEN
9529          --nullify the contract line id on the charge line
9530          x_charges_detail_rec.contract_line_id := null;
9531        ELSE
9532          --take the one from the database;
9533          x_charges_detail_rec.contract_line_id := l_db_det_rec.contract_line_id;
9534        END IF;
9535 
9536    END IF;
9537 
9538 
9539    -- Initialize contract values.
9540    --x_charges_detail_rec.contract_id := null;
9541    x_charges_detail_rec.coverage_id := null;
9542    x_charges_detail_rec.coverage_txn_group_id := null;
9543 
9544 
9545 
9546  IF(p_charges_detail_rec.contract_id <> FND_API.G_MISS_NUM) AND
9547    (p_charges_detail_rec.contract_id IS NOT NULL) THEN
9548 
9549    -- Fixed Bug # 4126979
9550 
9551     --Validate Contract
9552     l_valid_check := IS_CONTRACT_VALID(
9553                          p_contract_id           =>  p_charges_detail_rec.contract_id,
9554                          x_msg_data              =>  l_msg_data,
9555                          x_msg_count             =>  l_msg_count,
9556                          x_return_status         =>  l_return_status);
9557 
9558       IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
9559         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9560       ELSIF l_return_status = G_RET_STS_ERROR THEN
9561         RAISE FND_API.G_EXC_ERROR;
9562       END IF;
9563 
9564       IF l_valid_check <> 'Y' THEN
9565 
9566         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_CONTRACT');
9567         FND_MESSAGE.Set_Token('CONTRACT_ID', p_charges_detail_rec.contract_id);
9568         FND_MSG_PUB.Add;
9569         RAISE FND_API.G_EXC_ERROR;
9570 
9571       ELSE
9572 
9573       --Contract is valid, assign to out record
9574       x_charges_detail_rec.contract_id := p_charges_detail_rec.contract_id;
9575       -- get price list for the contract
9576       GET_CONTRACT_PRICE_LIST(
9577           p_api_name              => l_api_name,
9578           p_business_process_id   => x_charges_detail_rec.business_process_id,
9579           p_request_date          => l_request_date,
9580           p_contract_line_id      => x_charges_detail_rec.contract_line_id,
9581           x_price_list_id         => l_price_list_id,
9582           x_currency_code         => l_currency_code,
9583           x_msg_data              => l_msg_data,
9584           x_msg_count             => l_msg_count,
9585           x_return_status         => l_return_status);
9586 
9587       IF p_charges_detail_rec.price_list_id <> FND_API.G_MISS_NUM AND
9588          p_charges_detail_rec.price_list_id IS NOT NULL AND
9589          l_price_list_id IS NOT NULL AND
9590          p_charges_detail_rec.price_list_id <> l_price_list_id THEN
9591 
9592          --Fixed To resolve Bug # 3557490
9593          --do nothing
9594          --since the price list is already derived there is no need to validate again
9595          --use the price list sent by the upstream application
9596          x_charges_detail_rec.price_list_id := p_charges_detail_rec.price_list_id;
9597 
9598          -- get currency_code for the price_list_id
9599          GET_CURRENCY_CODE(
9600               p_api_name        => l_api_name,
9601               p_price_list_id   => x_charges_detail_rec.price_list_id,
9602               x_currency_code   => l_currency_code,
9603               x_msg_data        => l_msg_data,
9604               x_msg_count       => l_msg_count,
9605               x_return_status   => l_return_status);
9606 
9607          IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9608            FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
9609            FND_MESSAGE.Set_Token('PRICE_LIST_ID', p_charges_detail_rec.price_list_id);
9610            --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
9611            FND_MSG_PUB.Add;
9612            RAISE FND_API.G_EXC_ERROR;
9613          END IF ;
9614 
9615          x_charges_detail_rec.currency_code := l_currency_code;
9616 
9617          --Condition added to fix Bug # 3358531
9618         IF x_charges_detail_rec.price_list_id <> l_db_det_rec.price_list_header_id OR
9619            x_charges_detail_rec.currency_code <> l_db_det_rec.currency_code THEN
9620           --price list or currecy code is changed need to re-calculate the list price
9621           l_calc_sp := 'Y';
9622         END IF;
9623 
9624       ELSIF p_charges_detail_rec.price_list_id IS NULL OR
9625             p_charges_detail_rec.price_list_id = FND_API.G_MISS_NUM AND
9626             l_price_list_id IS NOT NULL THEN
9627 
9628         -- update the pricelist in the database with the new one
9629 
9630         x_charges_detail_rec.price_list_id := l_price_list_id;
9631         x_charges_detail_rec.currency_code := l_currency_code;
9632 
9633         --Condition added to fix Bug # 3358531
9634         IF x_charges_detail_rec.price_list_id <> l_db_det_rec.price_list_header_id OR
9635            x_charges_detail_rec.currency_code <> l_db_det_rec.currency_code THEN
9636           --price list or currecy code is changed need to re-calculate the list price
9637           l_calc_sp := 'Y';
9638         END IF;
9639 
9640       ELSIF p_charges_detail_rec.price_list_id <> FND_API.G_MISS_NUM AND
9641             p_charges_detail_rec.price_list_id IS NOT NULL AND
9642             l_price_list_id IS NULL THEN
9643 
9644         x_charges_detail_rec.price_list_id := p_charges_detail_rec.price_list_id;
9645         -- get currency_code for the price_list_id
9646         GET_CURRENCY_CODE(
9647               p_api_name        => l_api_name,
9648               p_price_list_id   => p_charges_detail_rec.price_list_id,
9649               x_currency_code   => l_currency_code,
9650               x_msg_data        => l_msg_data,
9651               x_msg_count       => l_msg_count,
9652               x_return_status   => l_return_status);
9653 
9654         IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9655           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
9656           FND_MESSAGE.Set_Token('PRICE_LIST_ID', p_charges_detail_rec.price_list_id);
9657           --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
9658           FND_MSG_PUB.Add;
9659           RAISE FND_API.G_EXC_ERROR;
9660         END IF ;
9661 
9662         x_charges_detail_rec.currency_code := l_currency_code;
9663 
9664          --Condition added to fix Bug # 3358531
9665          IF x_charges_detail_rec.price_list_id <> l_db_det_rec.price_list_header_id OR
9666             x_charges_detail_rec.currency_code <> l_db_det_rec.currency_code THEN
9667             --price list or currecy code is changed need to re-calculate the list price
9668             l_calc_sp := 'Y';
9669          END IF;
9670 
9671       ELSIF p_charges_detail_rec.price_list_id IS NULL OR
9672             p_charges_detail_rec.price_list_id = FND_API.G_MISS_NUM AND
9673             l_price_list_id IS NULL THEN
9674 
9675         --use the default from the price list
9676         x_charges_detail_rec.price_list_id := to_number(fnd_profile.value('CS_CHARGE_DEFAULT_PRICE_LIST'));
9677 
9678         -- get currency_code for the price_list_id
9679         GET_CURRENCY_CODE(
9680               p_api_name        => l_api_name,
9681               p_price_list_id   => x_charges_detail_rec.price_list_id,
9682               x_currency_code   => l_currency_code,
9683               x_msg_data        => l_msg_data,
9684               x_msg_count       => l_msg_count,
9685               x_return_status   => l_return_status);
9686 
9687         IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9688           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
9689           FND_MESSAGE.Set_Token('PRICE_LIST_ID', x_charges_detail_rec.price_list_id);
9690           --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
9691           FND_MSG_PUB.Add;
9692           RAISE FND_API.G_EXC_ERROR;
9693         END IF ;
9694         x_charges_detail_rec.currency_code := l_currency_code;
9695 
9696         --Condition added to fix Bug # 3358531
9697         IF x_charges_detail_rec.price_list_id <> l_db_det_rec.price_list_header_id OR
9698            x_charges_detail_rec.currency_code <> l_db_det_rec.currency_code THEN
9699           --price list or currecy code is changed need to re-calculate the list price
9700           l_calc_sp := 'Y';
9701         END IF;
9702       END IF;
9703     END IF;
9704 
9705   ELSIF p_charges_detail_rec.contract_id IS NULL  THEN
9706 
9707     --nullify the contract on the charge line
9708     --x_charges_detail_rec.contract_id := null;
9709     --x_charges_detail_rec.coverage_id := null;
9710     --x_charges_detail_rec.coverage_txn_group_id := null;
9711 
9712     -- Check to see if there is a price list passed
9713     IF p_charges_detail_rec.price_list_id <> FND_API.G_MISS_NUM AND
9714        p_charges_detail_rec.price_list_id IS NOT NULL THEN
9715 
9716        --assign these to the out parameters as these have already
9717        --been validated before
9718        x_charges_detail_rec.price_list_id := x_charges_detail_rec.price_list_id;
9719        x_charges_detail_rec.currency_code := x_charges_detail_rec.currency_code;
9720 
9721        --Condition added to fix Bug # 3358531
9722        IF x_charges_detail_rec.price_list_id <> l_db_det_rec.price_list_header_id OR
9723           x_charges_detail_rec.currency_code <> l_db_det_rec.currency_code THEN
9724           --price list or currecy code is changed need to re-calculate the list price
9725           l_calc_sp := 'Y';
9726        END IF;
9727 
9728     ELSIF p_charges_detail_rec.price_list_id = FND_API.G_MISS_NUM THEN
9729 
9730       IF l_db_det_rec.price_list_header_id IS NOT NULL THEN
9731 
9732           x_charges_detail_rec.price_list_id := l_db_det_rec.price_list_header_id;
9733 
9734           GET_CURRENCY_CODE(
9735               p_api_name        => l_api_name,
9736               p_price_list_id   => x_charges_detail_rec.price_list_id,
9737               x_currency_code   => l_currency_code,
9738               x_msg_data        => l_msg_data,
9739               x_msg_count       => l_msg_count,
9740               x_return_status   => l_return_status);
9741 
9742         IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9743           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
9744           FND_MESSAGE.Set_Token('PRICE_LIST_ID', p_charges_detail_rec.price_list_id);
9745           --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
9746           FND_MSG_PUB.Add;
9747           RAISE FND_API.G_EXC_ERROR;
9748         END IF ;
9749 
9750         x_charges_detail_rec.currency_code := l_currency_code;
9751 
9752         --Condition added to fix Bug # 3358531
9753         IF x_charges_detail_rec.currency_code <> l_db_det_rec.currency_code THEN
9754           --currecy code is changed need to re-calculate the list price
9755           l_calc_sp := 'Y';
9756         END IF;
9757 
9758     ELSE
9759 
9760       --get the default on the profile
9761       --use the default from the price list
9762       x_charges_detail_rec.price_list_id := to_number(fnd_profile.value('CS_CHARGE_DEFAULT_PRICE_LIST'));
9763 
9764       -- get currency_code for the price_list_id
9765       GET_CURRENCY_CODE(
9766             p_api_name        => l_api_name,
9767             p_price_list_id   => x_charges_detail_rec.price_list_id,
9768             x_currency_code   => l_currency_code,
9769             x_msg_data        => l_msg_data,
9770             x_msg_count       => l_msg_count,
9771             x_return_status   => l_return_status);
9772 
9773         IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9774           FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
9775           FND_MESSAGE.Set_Token('PRICE_LIST_ID', x_charges_detail_rec.price_list_id);
9776           --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
9777           FND_MSG_PUB.Add;
9778           RAISE FND_API.G_EXC_ERROR;
9779         END IF ;
9780         x_charges_detail_rec.currency_code := l_currency_code;
9781 
9782         --Condition added to fix Bug # 3358531
9783         IF x_charges_detail_rec.price_list_id <> l_db_det_rec.price_list_header_id OR
9784            x_charges_detail_rec.currency_code <> l_db_det_rec.currency_code THEN
9785           --price list or currecy code is changed need to re-calculate the list price
9786           l_calc_sp := 'Y';
9787         END IF;
9788 
9789        END IF;
9790     END IF;
9791 
9792   ELSE
9793    -- no contract information coming in
9794    -- get what is in the database
9795    -- --DBMS_OUTPUT.PUT_LINE('contract coming from database');
9796     IF (x_charges_detail_rec.contract_id IS NULL) THEN
9797       x_charges_detail_rec.contract_id           := l_db_det_rec.contract_id;
9798     END IF;
9799 
9800     --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.contract_id '||x_charges_detail_rec.contract_id);
9801     --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.coverage_id '||x_charges_detail_rec.coverage_id);
9802     --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.coverage_txn_group_id '||x_charges_detail_rec.coverage_txn_group_id);
9803 
9804 
9805     IF x_charges_detail_rec.contract_id IS NOT NULL THEN
9806 
9807        GET_CONTRACT_PRICE_LIST(
9808             p_api_name              => l_api_name,
9809             p_business_process_id   => x_charges_detail_rec.business_process_id,
9810             p_request_date          => l_request_date,
9811             p_contract_line_id      => x_charges_detail_rec.contract_line_id,
9812             x_price_list_id         => l_price_list_id,
9813             x_currency_code         => l_currency_code,
9814             x_msg_data              => l_msg_data,
9815             x_msg_count             => l_msg_count,
9816             x_return_status         => l_return_status);
9817 
9818        IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9819            FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
9820            FND_MESSAGE.Set_Token('PRICE_LIST_ID', x_charges_detail_rec.price_list_id);
9821            --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
9822            FND_MSG_PUB.Add;
9823            RAISE FND_API.G_EXC_ERROR;
9824         END IF ;
9825        --DBMS_OUTPUT.PUT_LINE ('l_price_list_id '||l_price_list_id);
9826        --DBMS_OUTPUT.PUT_LINE (' l_currency_code '||l_currency_code);
9827 
9828        IF p_charges_detail_rec.price_list_id <> FND_API.G_MISS_NUM AND
9829           p_charges_detail_rec.price_list_id IS NOT NULL AND
9830           l_price_list_id IS NOT NULL AND
9831 
9832           p_charges_detail_rec.price_list_id <> l_price_list_id THEN
9833 
9834           --Fixed To resolve Bug # 3557490
9835           --do nothing
9836           --since the price list is already derived there is no need to validate again
9837           --use the price list sent by the upstream application
9838           x_charges_detail_rec.price_list_id := p_charges_detail_rec.price_list_id;
9839 
9840           -- get currency_code for the price_list_id
9841           GET_CURRENCY_CODE(
9842               p_api_name        => l_api_name,
9843               p_price_list_id   => x_charges_detail_rec.price_list_id,
9844               x_currency_code   => l_currency_code,
9845               x_msg_data        => l_msg_data,
9846               x_msg_count       => l_msg_count,
9847               x_return_status   => l_return_status);
9848 
9849           IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9850             FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
9851             FND_MESSAGE.Set_Token('PRICE_LIST_ID', p_charges_detail_rec.price_list_id);
9852             --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
9853             FND_MSG_PUB.Add;
9854             RAISE FND_API.G_EXC_ERROR;
9855           END IF ;
9856 
9857           x_charges_detail_rec.currency_code := l_currency_code;
9858 
9859           --Condition added to fix Bug # 3358531
9860           IF x_charges_detail_rec.price_list_id <> l_db_det_rec.price_list_header_id OR
9861             x_charges_detail_rec.currency_code <> l_db_det_rec.currency_code THEN
9862             --price list or currecy code is changed need to re-calculate the list price
9863             l_calc_sp := 'Y';
9864           END IF;
9865 
9866        ELSIF p_charges_detail_rec.price_list_id = FND_API.G_MISS_NUM THEN
9867 
9868           --DBMS_OUTPUT.PUT_LINE(' price list not passed using from db');
9869 
9870           x_charges_detail_rec.price_list_id := l_db_det_rec.price_list_header_id;
9871           x_charges_detail_rec.currency_code := l_db_det_rec.currency_code;
9872 
9873 
9874           --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.price_list_id'||x_charges_detail_rec.price_list_id);
9875 
9876        ELSIF p_charges_detail_rec.price_list_id IS NULL AND
9877              l_price_list_id IS NOT NULL THEN
9878 
9879           x_charges_detail_rec.price_list_id := l_price_list_id;
9880           x_charges_detail_rec.currency_code := l_currency_code;
9881 
9882           --Condition added to fix Bug # 3358531
9883           IF x_charges_detail_rec.price_list_id <> l_db_det_rec.price_list_header_id OR
9884             x_charges_detail_rec.currency_code <> l_db_det_rec.currency_code THEN
9885             --price list or currecy code is changed need to re-calculate the list price
9886             l_calc_sp := 'Y';
9887           END IF;
9888 
9889        ELSIF p_charges_detail_rec.price_list_id <> FND_API.G_MISS_NUM AND
9890              p_charges_detail_rec.price_list_id IS NOT NULL AND
9891              l_price_list_id IS NULL THEN
9892 
9893            x_charges_detail_rec.price_list_id := p_charges_detail_rec.price_list_id;
9894 
9895             -- get currency_code for the price_list_id
9896             GET_CURRENCY_CODE(
9897                   p_api_name        => l_api_name,
9898                   p_price_list_id   => p_charges_detail_rec.price_list_id,
9899                   x_currency_code   => l_currency_code,
9900                   x_msg_data        => l_msg_data,
9901                   x_msg_count       => l_msg_count,
9902                   x_return_status   => l_return_status);
9903 
9904             IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9905               FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
9906               FND_MESSAGE.Set_Token('PRICE_LIST_ID', p_charges_detail_rec.price_list_id);
9907               --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
9908               FND_MSG_PUB.Add;
9909               RAISE FND_API.G_EXC_ERROR;
9910             END IF ;
9911 
9912             x_charges_detail_rec.currency_code := l_currency_code;
9913 
9914             --Condition added to fix Bug # 3346568
9915             IF x_charges_detail_rec.price_list_id <> l_db_det_rec.price_list_header_id OR
9916               x_charges_detail_rec.currency_code <> l_db_det_rec.currency_code THEN
9917               --price list or currecy code is changed need to re-calculate the list price
9918               l_calc_sp := 'Y';
9919             END IF;
9920 
9921         ELSIF p_charges_detail_rec.price_list_id IS NULL AND
9922                 l_price_list_id IS NULL THEN
9923 
9924             --use the default from the price list
9925             x_charges_detail_rec.price_list_id := to_number(fnd_profile.value('CS_CHARGE_DEFAULT_PRICE_LIST'));
9926 
9927             -- get currency_code for the price_list_id
9928             GET_CURRENCY_CODE(
9929                   p_api_name        => l_api_name,
9930                   p_price_list_id   => x_charges_detail_rec.price_list_id,
9931                   x_currency_code   => l_currency_code,
9932                   x_msg_data        => l_msg_data,
9933                   x_msg_count       => l_msg_count,
9934                   x_return_status   => l_return_status);
9935 
9936             IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9937               FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
9938               FND_MESSAGE.Set_Token('PRICE_LIST_ID', x_charges_detail_rec.price_list_id);
9939               --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
9940               FND_MSG_PUB.Add;
9941               RAISE FND_API.G_EXC_ERROR;
9942             END IF ;
9943             x_charges_detail_rec.currency_code := l_currency_code;
9944 
9945             --Condition added to fix Bug # 3358531
9946             IF x_charges_detail_rec.price_list_id <> l_db_det_rec.price_list_header_id OR
9947               x_charges_detail_rec.currency_code <> l_db_det_rec.currency_code THEN
9948               --price list or currecy code is changed need to re-calculate the list price
9949               l_calc_sp := 'Y';
9950             END IF;
9951        END IF;
9952 
9953     ELSE
9954       --all three are null
9955       --update what is come on the line
9956 
9957       --DBMS_OUTPUT.PUT_LINE(' No Contract Information');
9958 
9959       IF p_charges_detail_rec.price_list_id <> FND_API.G_MISS_NUM AND
9960          p_charges_detail_rec.price_list_id IS NOT NULL THEN
9961 
9962             x_charges_detail_rec.price_list_id := p_charges_detail_rec.price_list_id;
9963 
9964             -- get currency_code for the price_list_id
9965             GET_CURRENCY_CODE(
9966                   p_api_name        => l_api_name,
9967                   p_price_list_id   => p_charges_detail_rec.price_list_id,
9968                   x_currency_code   => l_currency_code,
9969                   x_msg_data        => l_msg_data,
9970                   x_msg_count       => l_msg_count,
9971                   x_return_status   => l_return_status);
9972 
9973             IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
9974               FND_MESSAGE.Set_Token('PRICE_LIST_ID', p_charges_detail_rec.price_list_id);
9975               --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
9976               FND_MSG_PUB.Add;
9977               RAISE FND_API.G_EXC_ERROR;
9978             END IF ;
9979 
9980             x_charges_detail_rec.currency_code := l_currency_code;
9981 
9982             --Condition added to fix Bug # 3358531
9983             IF x_charges_detail_rec.price_list_id <> l_db_det_rec.price_list_header_id OR
9984               x_charges_detail_rec.currency_code <> l_db_det_rec.currency_code THEN
9985               --price list or currecy code is changed need to re-calculate the list price
9986               l_calc_sp := 'Y';
9987             END IF;
9988 
9989         ELSE
9990 
9991 
9992           IF l_db_det_rec.price_list_header_id IS NOT NULL THEN
9993                x_charges_detail_rec.price_list_id := l_db_det_rec.price_list_header_id;
9994                -- get currency_code for the price_list_id
9995                GET_CURRENCY_CODE(
9996                   p_api_name        => l_api_name,
9997                   p_price_list_id   => x_charges_detail_rec.price_list_id,
9998                   x_currency_code   => l_currency_code,
9999                   x_msg_data        => l_msg_data,
10000                   x_msg_count       => l_msg_count,
10001                   x_return_status   => l_return_status);
10002 
10003             IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
10004               FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
10005               FND_MESSAGE.Set_Token('PRICE_LIST_ID', x_charges_detail_rec.price_list_id);
10006               --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
10007               FND_MSG_PUB.Add;
10008               RAISE FND_API.G_EXC_ERROR;
10009             END IF ;
10010             x_charges_detail_rec.currency_code := l_currency_code;
10011 
10012             --Condition added to fix Bug # 3358531
10013             IF x_charges_detail_rec.currency_code <> l_db_det_rec.currency_code THEN
10014               --currecy code is changed need to re-calculate the list price
10015               l_calc_sp := 'Y';
10016             END IF;
10017 
10018           ELSE
10019             --use the default from the price list
10020             x_charges_detail_rec.price_list_id := to_number(fnd_profile.value('CS_CHARGE_DEFAULT_PRICE_LIST'));
10021 
10022             -- get currency_code for the price_list_id
10023             GET_CURRENCY_CODE(
10024                   p_api_name        => l_api_name,
10025                   p_price_list_id   => x_charges_detail_rec.price_list_id,
10026                   x_currency_code   => l_currency_code,
10027                   x_msg_data        => l_msg_data,
10028                   x_msg_count       => l_msg_count,
10029                   x_return_status   => l_return_status);
10030 
10031             IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
10032               FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CURRENCY_CODE_ERROR');
10033               FND_MESSAGE.Set_Token('PRICE_LIST_ID', x_charges_detail_rec.price_list_id);
10034               --FND_MESSAGE.Set_Token('TEXT', l_msg_data, TRUE);
10035               FND_MSG_PUB.Add;
10036               RAISE FND_API.G_EXC_ERROR;
10037             END IF ;
10038             x_charges_detail_rec.currency_code := l_currency_code;
10039 
10040             --Condition added to fix Bug # 3358531
10041             IF x_charges_detail_rec.price_list_id <> l_db_det_rec.price_list_header_id OR
10042                x_charges_detail_rec.currency_code <> l_db_det_rec.currency_code THEN
10043                --price list or currecy code is changed need to re-calculate the list price
10044                l_calc_sp := 'Y';
10045             END IF;
10046          END IF;
10047        END IF;
10048     END IF;
10049   END IF;
10050 END IF;
10051 
10052 --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.price_list_id'||x_charges_detail_rec.price_list_id);
10053 --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.currency_code '||x_charges_detail_rec.currency_code);
10054 --DBMS_OUTPUT.PUT_LINE('contract_id '||x_charges_detail_rec.contract_id);
10055 
10056 
10057 -- ========================================
10058 -- Check currency coversion
10059 -- ========================================
10060 --DBMS_OUTPUT.PUT_LINE('Check currency coversion ...');
10061 
10062 IF p_validation_mode IN ('I', 'U') THEN
10063 
10064   l_conversion_needed_flag := 'N';
10065   x_charges_detail_rec.conversion_rate := null;
10066   x_charges_detail_rec.conversion_type_code := null;
10067   x_charges_detail_rec.conversion_rate_date := null;
10068 
10069   IF p_charges_detail_rec.currency_code <> FND_API.G_MISS_CHAR AND
10070      p_charges_detail_rec.currency_code IS NOT NULL AND
10071      p_charges_detail_rec.currency_code <> x_charges_detail_rec.currency_code THEN
10072 
10073     IF l_billing_flag = 'E' THEN
10074 
10075       -- Contract exists for the Charge Line
10076       -- Convert the currency to the currency derived from Contract
10077 
10078       --DBMS_OUTPUT.PUT_LINE('Conversion Needed');
10079 
10080       l_conversion_needed_flag := 'Y';
10081 
10082       --call get_conversion_rate API
10083       Get_Conversion_Rate(
10084         p_api_name        => p_api_name,
10085         p_from_currency   => p_charges_detail_rec.currency_code,
10086         p_to_currency     => x_charges_detail_rec.currency_code,
10087         x_denominator     => l_denominator,
10088         x_numerator       => l_numerator,
10089         x_rate            => l_rate,
10090         x_return_status   => l_return_status);
10091 
10092         --DBMS_OUTPUT.PUT_LINE('l_rate '||l_rate);
10093 
10094       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
10095         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_CURRENCY_CONVERSION_ERR');
10096         FND_MESSAGE.Set_Token('FROM_CURRENCY', p_charges_detail_rec.currency_code);
10097         FND_MESSAGE.Set_Token('TO_CURRENCY', x_charges_detail_rec.currency_code);
10098         FND_MSG_PUB.Add;
10099         RAISE FND_API.G_EXC_ERROR;
10100       END IF;
10101       --assign values to out record for conversion_rate, conversion_type_code
10102       --conversion_rate_date
10103       x_charges_detail_rec.conversion_rate := l_rate;
10104       x_charges_detail_rec.conversion_type_code := FND_PROFILE.VALUE('CS_CHG_DEFAULT_CONVERSION_TYPE');
10105       x_charges_detail_rec.conversion_rate_date := SYSDATE;
10106 
10107     ELSE
10108 
10109       --this should be an error because what comes in must mastch the derived currency code
10110       --RAISE FND_API.G_EXC_ERROR;
10111       --null;
10112       FND_MESSAGE.SET_NAME('CS', 'CS_CHG_INVALID_CURRENCY_CODE');
10113       FND_MESSAGE.Set_Token('CURRENCY_CODE', p_charges_detail_rec.currency_code);
10114       FND_MSG_PUB.Add;
10115       RAISE FND_API.G_EXC_ERROR;
10116 
10117     END IF;
10118 
10119   END IF;
10120 
10121 END IF;
10122 
10123 --DBMS_OUTPUT.PUT_LINE('l_conversion_flag'||l_conversion_needed_flag);
10124 
10125 
10126 --=========================================
10127 -- Assign Values to Charges Flex fields
10128 -- in the out record
10129 --==========================================
10130 IF p_validation_mode = 'I' THEN
10131   x_charges_detail_rec.context       := p_charges_detail_rec.context ;
10132   x_charges_detail_rec.attribute1    := p_charges_detail_rec.attribute1 ;
10133   x_charges_detail_rec.attribute2    := p_charges_detail_rec.attribute2 ;
10134   x_charges_detail_rec.attribute3    := p_charges_detail_rec.attribute3 ;
10135   x_charges_detail_rec.attribute4    := p_charges_detail_rec.attribute4 ;
10136   x_charges_detail_rec.attribute5    := p_charges_detail_rec.attribute5 ;
10137   x_charges_detail_rec.attribute6    := p_charges_detail_rec.attribute6 ;
10138   x_charges_detail_rec.attribute7    := p_charges_detail_rec.attribute7 ;
10139   x_charges_detail_rec.attribute8    := p_charges_detail_rec.attribute8 ;
10140   x_charges_detail_rec.attribute9    := p_charges_detail_rec.attribute9 ;
10141   x_charges_detail_rec.attribute10   := p_charges_detail_rec.attribute10 ;
10142   x_charges_detail_rec.attribute11   := p_charges_detail_rec.attribute11 ;
10143   x_charges_detail_rec.attribute12   := p_charges_detail_rec.attribute12 ;
10144   x_charges_detail_rec.attribute13   := p_charges_detail_rec.attribute13 ;
10145   x_charges_detail_rec.attribute14   := p_charges_detail_rec.attribute14 ;
10146   x_charges_detail_rec.attribute15   := p_charges_detail_rec.attribute15 ;
10147 
10148 --=========================================
10149 -- Assign values to Pricing Flex fields
10150 -- in out record
10151 --=========================================
10152   x_charges_detail_rec.pricing_context       := p_charges_detail_rec.pricing_context ;
10153   x_charges_detail_rec.pricing_attribute1    := p_charges_detail_rec.pricing_attribute1 ;
10154   x_charges_detail_rec.pricing_attribute2    := p_charges_detail_rec.pricing_attribute2 ;
10155   x_charges_detail_rec.pricing_attribute3    := p_charges_detail_rec.pricing_attribute3 ;
10156   x_charges_detail_rec.pricing_attribute4    := p_charges_detail_rec.pricing_attribute4 ;
10157   x_charges_detail_rec.pricing_attribute5    := p_charges_detail_rec.pricing_attribute5 ;
10158   x_charges_detail_rec.pricing_attribute6    := p_charges_detail_rec.pricing_attribute6 ;
10159   x_charges_detail_rec.pricing_attribute7    := p_charges_detail_rec.pricing_attribute7 ;
10160   x_charges_detail_rec.pricing_attribute8    := p_charges_detail_rec.pricing_attribute8 ;
10161   x_charges_detail_rec.pricing_attribute9    := p_charges_detail_rec.pricing_attribute9 ;
10162   x_charges_detail_rec.pricing_attribute10   := p_charges_detail_rec.pricing_attribute10 ;
10163   x_charges_detail_rec.pricing_attribute11   := p_charges_detail_rec.pricing_attribute11 ;
10164   x_charges_detail_rec.pricing_attribute12   := p_charges_detail_rec.pricing_attribute12 ;
10165   x_charges_detail_rec.pricing_attribute13   := p_charges_detail_rec.pricing_attribute13 ;
10166   x_charges_detail_rec.pricing_attribute14   := p_charges_detail_rec.pricing_attribute14 ;
10167   x_charges_detail_rec.pricing_attribute15   := p_charges_detail_rec.pricing_attribute15 ;
10168   x_charges_detail_rec.pricing_attribute16   := p_charges_detail_rec.pricing_attribute16 ;
10169   x_charges_detail_rec.pricing_attribute17   := p_charges_detail_rec.pricing_attribute17 ;
10170   x_charges_detail_rec.pricing_attribute18   := p_charges_detail_rec.pricing_attribute18 ;
10171   x_charges_detail_rec.pricing_attribute19   := p_charges_detail_rec.pricing_attribute19 ;
10172   x_charges_detail_rec.pricing_attribute20   := p_charges_detail_rec.pricing_attribute20 ;
10173   x_charges_detail_rec.pricing_attribute21   := p_charges_detail_rec.pricing_attribute21 ;
10174   x_charges_detail_rec.pricing_attribute22   := p_charges_detail_rec.pricing_attribute22 ;
10175   x_charges_detail_rec.pricing_attribute23   := p_charges_detail_rec.pricing_attribute23 ;
10176   x_charges_detail_rec.pricing_attribute24   := p_charges_detail_rec.pricing_attribute24 ;
10177   x_charges_detail_rec.pricing_attribute25   := p_charges_detail_rec.pricing_attribute25 ;
10178   x_charges_detail_rec.pricing_attribute26   := p_charges_detail_rec.pricing_attribute26 ;
10179   x_charges_detail_rec.pricing_attribute27   := p_charges_detail_rec.pricing_attribute27 ;
10180   x_charges_detail_rec.pricing_attribute28   := p_charges_detail_rec.pricing_attribute28 ;
10181   x_charges_detail_rec.pricing_attribute29   := p_charges_detail_rec.pricing_attribute29 ;
10182   x_charges_detail_rec.pricing_attribute30   := p_charges_detail_rec.pricing_attribute30 ;
10183   x_charges_detail_rec.pricing_attribute31   := p_charges_detail_rec.pricing_attribute31 ;
10184   x_charges_detail_rec.pricing_attribute32   := p_charges_detail_rec.pricing_attribute32 ;
10185   x_charges_detail_rec.pricing_attribute33   := p_charges_detail_rec.pricing_attribute33 ;
10186   x_charges_detail_rec.pricing_attribute34   := p_charges_detail_rec.pricing_attribute34 ;
10187   x_charges_detail_rec.pricing_attribute35   := p_charges_detail_rec.pricing_attribute35 ;
10188   x_charges_detail_rec.pricing_attribute36   := p_charges_detail_rec.pricing_attribute36 ;
10189   x_charges_detail_rec.pricing_attribute37   := p_charges_detail_rec.pricing_attribute37 ;
10190   x_charges_detail_rec.pricing_attribute38   := p_charges_detail_rec.pricing_attribute38 ;
10191   x_charges_detail_rec.pricing_attribute39   := p_charges_detail_rec.pricing_attribute39 ;
10192   x_charges_detail_rec.pricing_attribute40   := p_charges_detail_rec.pricing_attribute40 ;
10193   x_charges_detail_rec.pricing_attribute41   := p_charges_detail_rec.pricing_attribute41 ;
10194   x_charges_detail_rec.pricing_attribute42   := p_charges_detail_rec.pricing_attribute42 ;
10195   x_charges_detail_rec.pricing_attribute43   := p_charges_detail_rec.pricing_attribute43 ;
10196   x_charges_detail_rec.pricing_attribute44   := p_charges_detail_rec.pricing_attribute44 ;
10197   x_charges_detail_rec.pricing_attribute45   := p_charges_detail_rec.pricing_attribute45 ;
10198   x_charges_detail_rec.pricing_attribute46   := p_charges_detail_rec.pricing_attribute46 ;
10199   x_charges_detail_rec.pricing_attribute47   := p_charges_detail_rec.pricing_attribute47 ;
10200   x_charges_detail_rec.pricing_attribute48   := p_charges_detail_rec.pricing_attribute48 ;
10201   x_charges_detail_rec.pricing_attribute49   := p_charges_detail_rec.pricing_attribute49 ;
10202   x_charges_detail_rec.pricing_attribute50   := p_charges_detail_rec.pricing_attribute50 ;
10203   x_charges_detail_rec.pricing_attribute51   := p_charges_detail_rec.pricing_attribute51 ;
10204   x_charges_detail_rec.pricing_attribute52   := p_charges_detail_rec.pricing_attribute52 ;
10205   x_charges_detail_rec.pricing_attribute53   := p_charges_detail_rec.pricing_attribute53 ;
10206   x_charges_detail_rec.pricing_attribute54   := p_charges_detail_rec.pricing_attribute54 ;
10207   x_charges_detail_rec.pricing_attribute55   := p_charges_detail_rec.pricing_attribute55 ;
10208   x_charges_detail_rec.pricing_attribute56   := p_charges_detail_rec.pricing_attribute56 ;
10209   x_charges_detail_rec.pricing_attribute57   := p_charges_detail_rec.pricing_attribute57 ;
10210   x_charges_detail_rec.pricing_attribute58   := p_charges_detail_rec.pricing_attribute58 ;
10211   x_charges_detail_rec.pricing_attribute59   := p_charges_detail_rec.pricing_attribute59 ;
10212   x_charges_detail_rec.pricing_attribute60   := p_charges_detail_rec.pricing_attribute60 ;
10213   x_charges_detail_rec.pricing_attribute61   := p_charges_detail_rec.pricing_attribute61 ;
10214   x_charges_detail_rec.pricing_attribute62   := p_charges_detail_rec.pricing_attribute62 ;
10215   x_charges_detail_rec.pricing_attribute63   := p_charges_detail_rec.pricing_attribute63 ;
10216   x_charges_detail_rec.pricing_attribute64   := p_charges_detail_rec.pricing_attribute64 ;
10217   x_charges_detail_rec.pricing_attribute65   := p_charges_detail_rec.pricing_attribute65 ;
10218   x_charges_detail_rec.pricing_attribute66   := p_charges_detail_rec.pricing_attribute66 ;
10219   x_charges_detail_rec.pricing_attribute67   := p_charges_detail_rec.pricing_attribute67 ;
10220   x_charges_detail_rec.pricing_attribute68   := p_charges_detail_rec.pricing_attribute68 ;
10221   x_charges_detail_rec.pricing_attribute69   := p_charges_detail_rec.pricing_attribute69 ;
10222   x_charges_detail_rec.pricing_attribute70   := p_charges_detail_rec.pricing_attribute70 ;
10223   x_charges_detail_rec.pricing_attribute71   := p_charges_detail_rec.pricing_attribute71 ;
10224   x_charges_detail_rec.pricing_attribute72   := p_charges_detail_rec.pricing_attribute72 ;
10225   x_charges_detail_rec.pricing_attribute73   := p_charges_detail_rec.pricing_attribute73 ;
10226   x_charges_detail_rec.pricing_attribute74   := p_charges_detail_rec.pricing_attribute74 ;
10227   x_charges_detail_rec.pricing_attribute75   := p_charges_detail_rec.pricing_attribute75 ;
10228   x_charges_detail_rec.pricing_attribute76   := p_charges_detail_rec.pricing_attribute76 ;
10229   x_charges_detail_rec.pricing_attribute77   := p_charges_detail_rec.pricing_attribute77 ;
10230   x_charges_detail_rec.pricing_attribute78   := p_charges_detail_rec.pricing_attribute78 ;
10231   x_charges_detail_rec.pricing_attribute79   := p_charges_detail_rec.pricing_attribute79 ;
10232   x_charges_detail_rec.pricing_attribute80   := p_charges_detail_rec.pricing_attribute80 ;
10233   x_charges_detail_rec.pricing_attribute81   := p_charges_detail_rec.pricing_attribute81 ;
10234   x_charges_detail_rec.pricing_attribute82   := p_charges_detail_rec.pricing_attribute82 ;
10235   x_charges_detail_rec.pricing_attribute83   := p_charges_detail_rec.pricing_attribute83 ;
10236   x_charges_detail_rec.pricing_attribute84   := p_charges_detail_rec.pricing_attribute84 ;
10237   x_charges_detail_rec.pricing_attribute85   := p_charges_detail_rec.pricing_attribute85 ;
10238   x_charges_detail_rec.pricing_attribute86   := p_charges_detail_rec.pricing_attribute86 ;
10239   x_charges_detail_rec.pricing_attribute87   := p_charges_detail_rec.pricing_attribute87 ;
10240   x_charges_detail_rec.pricing_attribute88   := p_charges_detail_rec.pricing_attribute88 ;
10241   x_charges_detail_rec.pricing_attribute89   := p_charges_detail_rec.pricing_attribute89 ;
10242   x_charges_detail_rec.pricing_attribute90   := p_charges_detail_rec.pricing_attribute90 ;
10243   x_charges_detail_rec.pricing_attribute91   := p_charges_detail_rec.pricing_attribute91 ;
10244   x_charges_detail_rec.pricing_attribute92   := p_charges_detail_rec.pricing_attribute92 ;
10245   x_charges_detail_rec.pricing_attribute93   := p_charges_detail_rec.pricing_attribute93 ;
10246   x_charges_detail_rec.pricing_attribute94   := p_charges_detail_rec.pricing_attribute94 ;
10247   x_charges_detail_rec.pricing_attribute95   := p_charges_detail_rec.pricing_attribute95 ;
10248   x_charges_detail_rec.pricing_attribute96   := p_charges_detail_rec.pricing_attribute96 ;
10249   x_charges_detail_rec.pricing_attribute97   := p_charges_detail_rec.pricing_attribute97 ;
10250   x_charges_detail_rec.pricing_attribute98   := p_charges_detail_rec.pricing_attribute98 ;
10251   x_charges_detail_rec.pricing_attribute99   := p_charges_detail_rec.pricing_attribute99 ;
10252   x_charges_detail_rec.pricing_attribute100  := p_charges_detail_rec.pricing_attribute100 ;
10253 
10254 ELSIF p_validation_mode = 'U' THEN
10255 
10256  -- Bug Fix for Bug # 3078247
10257  -- Added code to handle the update of attributes
10258 
10259  --=========================================
10260 -- Assign Values to Charges Flex fields
10261 -- in the out record
10262 --==========================================
10263  IF p_charges_detail_rec.context = FND_API.G_MISS_CHAR THEN
10264 
10265    -- get the values from the database
10266    x_charges_detail_rec.context      := l_db_det_rec.context;
10267    x_charges_detail_rec.attribute1   := l_db_det_rec.attribute1;
10268    x_charges_detail_rec.attribute2   := l_db_det_rec.attribute2;
10269    x_charges_detail_rec.attribute3   := l_db_det_rec.attribute3;
10270    x_charges_detail_rec.attribute4   := l_db_det_rec.attribute4;
10271    x_charges_detail_rec.attribute5   := l_db_det_rec.attribute5;
10272    x_charges_detail_rec.attribute6   := l_db_det_rec.attribute6;
10273    x_charges_detail_rec.attribute7   := l_db_det_rec.attribute7;
10274    x_charges_detail_rec.attribute8   := l_db_det_rec.attribute8;
10275    x_charges_detail_rec.attribute9   := l_db_det_rec.attribute9;
10276    x_charges_detail_rec.attribute10  := l_db_det_rec.attribute10;
10277    x_charges_detail_rec.attribute11  := l_db_det_rec.attribute11;
10278    x_charges_detail_rec.attribute12  := l_db_det_rec.attribute12;
10279    x_charges_detail_rec.attribute13  := l_db_det_rec.attribute13;
10280    x_charges_detail_rec.attribute14  := l_db_det_rec.attribute14;
10281    x_charges_detail_rec.attribute15  := l_db_det_rec.attribute15;
10282 
10283  ELSIF
10284    p_charges_detail_rec.context IS NULL THEN
10285 
10286    -- nullify all values for the descriptive flex
10287    x_charges_detail_rec.context      := null;
10288    x_charges_detail_rec.attribute1   := null;
10289    x_charges_detail_rec.attribute2   := null;
10290    x_charges_detail_rec.attribute3   := null;
10291    x_charges_detail_rec.attribute4   := null;
10292    x_charges_detail_rec.attribute5   := null;
10293    x_charges_detail_rec.attribute6   := null;
10294    x_charges_detail_rec.attribute7   := null;
10295    x_charges_detail_rec.attribute8   := null;
10296    x_charges_detail_rec.attribute9   := null;
10297    x_charges_detail_rec.attribute10  := null;
10298    x_charges_detail_rec.attribute11  := null;
10299    x_charges_detail_rec.attribute12  := null;
10300    x_charges_detail_rec.attribute13  := null;
10301    x_charges_detail_rec.attribute14  := null;
10302    x_charges_detail_rec.attribute15  := null;
10303 
10304   ELSE
10305 
10306     x_charges_detail_rec.context     := p_charges_detail_rec.context ;
10307 
10308     IF p_charges_detail_rec.attribute1 = FND_API.G_MISS_CHAR THEN
10309       x_charges_detail_rec.attribute1  := null;
10310     ELSE
10311       x_charges_detail_rec.attribute1  := p_charges_detail_rec.attribute1;
10312     END IF;
10313 
10314     IF p_charges_detail_rec.attribute2 = FND_API.G_MISS_CHAR THEN
10315       x_charges_detail_rec.attribute2  := null;
10316     ELSE
10317       x_charges_detail_rec.attribute2  := p_charges_detail_rec.attribute2;
10318     END IF;
10319 
10320     IF p_charges_detail_rec.attribute3 = FND_API.G_MISS_CHAR THEN
10321       x_charges_detail_rec.attribute3  := null;
10322     ELSE
10323       x_charges_detail_rec.attribute3  := p_charges_detail_rec.attribute3;
10324     END IF;
10325 
10326     IF p_charges_detail_rec.attribute4 = FND_API.G_MISS_CHAR THEN
10327       x_charges_detail_rec.attribute4  := null;
10328     ELSE
10329       x_charges_detail_rec.attribute4  := p_charges_detail_rec.attribute4;
10330     END IF;
10331 
10332     IF p_charges_detail_rec.attribute5 = FND_API.G_MISS_CHAR THEN
10333       x_charges_detail_rec.attribute5  := null;
10334     ELSE
10335       x_charges_detail_rec.attribute5  := p_charges_detail_rec.attribute5;
10336     END IF;
10337 
10338      IF p_charges_detail_rec.attribute6 = FND_API.G_MISS_CHAR THEN
10339       x_charges_detail_rec.attribute6  := null;
10340     ELSE
10341       x_charges_detail_rec.attribute6  := p_charges_detail_rec.attribute6;
10342     END IF;
10343 
10344     IF p_charges_detail_rec.attribute7 = FND_API.G_MISS_CHAR THEN
10345       x_charges_detail_rec.attribute7  := null;
10346     ELSE
10347       x_charges_detail_rec.attribute7  := p_charges_detail_rec.attribute7;
10348     END IF;
10349 
10350     IF p_charges_detail_rec.attribute8 = FND_API.G_MISS_CHAR THEN
10351       x_charges_detail_rec.attribute8  := null;
10352     ELSE
10353       x_charges_detail_rec.attribute8  := p_charges_detail_rec.attribute8;
10354     END IF;
10355 
10356     IF p_charges_detail_rec.attribute9 = FND_API.G_MISS_CHAR THEN
10357       x_charges_detail_rec.attribute9  := null;
10358     ELSE
10359       x_charges_detail_rec.attribute9  := p_charges_detail_rec.attribute9;
10360     END IF;
10361 
10362     IF p_charges_detail_rec.attribute10 = FND_API.G_MISS_CHAR THEN
10363       x_charges_detail_rec.attribute10  := null;
10364     ELSE
10365       x_charges_detail_rec.attribute10 := p_charges_detail_rec.attribute10;
10366     END IF;
10367 
10368     IF p_charges_detail_rec.attribute11 = FND_API.G_MISS_CHAR THEN
10369       x_charges_detail_rec.attribute11  := null;
10370     ELSE
10371       x_charges_detail_rec.attribute11  := p_charges_detail_rec.attribute11;
10372     END IF;
10373 
10374     IF p_charges_detail_rec.attribute12 = FND_API.G_MISS_CHAR THEN
10375       x_charges_detail_rec.attribute12  := null;
10376     ELSE
10377       x_charges_detail_rec.attribute12  := p_charges_detail_rec.attribute12;
10378     END IF;
10379 
10380     IF p_charges_detail_rec.attribute13 = FND_API.G_MISS_CHAR THEN
10381       x_charges_detail_rec.attribute13  := null;
10382     ELSE
10383       x_charges_detail_rec.attribute13  := p_charges_detail_rec.attribute13;
10384     END IF;
10385 
10386     IF p_charges_detail_rec.attribute14 = FND_API.G_MISS_CHAR THEN
10387       x_charges_detail_rec.attribute14  := null;
10388     ELSE
10389       x_charges_detail_rec.attribute14  := p_charges_detail_rec.attribute14;
10390     END IF;
10391 
10392     IF p_charges_detail_rec.attribute15 = FND_API.G_MISS_CHAR THEN
10393       x_charges_detail_rec.attribute15  := null;
10394     ELSE
10395       x_charges_detail_rec.attribute15  := p_charges_detail_rec.attribute15;
10396     END IF;
10397 
10398  END IF;
10399 
10400  -- Bug Fix for Bug # 3063439
10401  -- Added code to handle the update of pricing attributes
10402 
10403 --=========================================
10404 -- Assign values to Pricing Flex fields
10405 -- in out record
10406 --=========================================
10407   IF p_charges_detail_rec.pricing_context = FND_API.G_MISS_CHAR THEN
10408 
10409     --DBMS_OUTPUT.PUT_LINE('parameter context is FND_API.G_MISS_CHAR ');
10410 
10411     x_charges_detail_rec.pricing_context      := l_db_det_rec.pricing_context ;
10412     x_charges_detail_rec.pricing_attribute1   := l_db_det_rec.pricing_attribute1;
10413     x_charges_detail_rec.pricing_attribute2   := l_db_det_rec.pricing_attribute2;
10414     x_charges_detail_rec.pricing_attribute3   := l_db_det_rec.pricing_attribute3;
10415     x_charges_detail_rec.pricing_attribute4   := l_db_det_rec.pricing_attribute4;
10416     x_charges_detail_rec.pricing_attribute5   := l_db_det_rec.pricing_attribute5;
10417     x_charges_detail_rec.pricing_attribute6   := l_db_det_rec.pricing_attribute6;
10418     x_charges_detail_rec.pricing_attribute7   := l_db_det_rec.pricing_attribute7;
10419     x_charges_detail_rec.pricing_attribute8   := l_db_det_rec.pricing_attribute8;
10420     x_charges_detail_rec.pricing_attribute9   := l_db_det_rec.pricing_attribute9;
10421     x_charges_detail_rec.pricing_attribute10  := l_db_det_rec.pricing_attribute10;
10422     x_charges_detail_rec.pricing_attribute11  := l_db_det_rec.pricing_attribute11;
10423     x_charges_detail_rec.pricing_attribute12  := l_db_det_rec.pricing_attribute12;
10424     x_charges_detail_rec.pricing_attribute13  := l_db_det_rec.pricing_attribute13;
10425     x_charges_detail_rec.pricing_attribute14  := l_db_det_rec.pricing_attribute14;
10426     x_charges_detail_rec.pricing_attribute15  := l_db_det_rec.pricing_attribute15;
10427     x_charges_detail_rec.pricing_attribute16  := l_db_det_rec.pricing_attribute16;
10428     x_charges_detail_rec.pricing_attribute17  := l_db_det_rec.pricing_attribute17;
10429     x_charges_detail_rec.pricing_attribute18  := l_db_det_rec.pricing_attribute18;
10430     x_charges_detail_rec.pricing_attribute19  := l_db_det_rec.pricing_attribute19;
10431     x_charges_detail_rec.pricing_attribute20  := l_db_det_rec.pricing_attribute20;
10432     x_charges_detail_rec.pricing_attribute21  := l_db_det_rec.pricing_attribute21;
10433     x_charges_detail_rec.pricing_attribute22  := l_db_det_rec.pricing_attribute22;
10434     x_charges_detail_rec.pricing_attribute23  := l_db_det_rec.pricing_attribute23;
10435     x_charges_detail_rec.pricing_attribute24  := l_db_det_rec.pricing_attribute24;
10436     x_charges_detail_rec.pricing_attribute25  := l_db_det_rec.pricing_attribute25;
10437     x_charges_detail_rec.pricing_attribute26  := l_db_det_rec.pricing_attribute26;
10438     x_charges_detail_rec.pricing_attribute27  := l_db_det_rec.pricing_attribute27;
10439     x_charges_detail_rec.pricing_attribute28  := l_db_det_rec.pricing_attribute28;
10440     x_charges_detail_rec.pricing_attribute29  := l_db_det_rec.pricing_attribute29;
10441     x_charges_detail_rec.pricing_attribute30  := l_db_det_rec.pricing_attribute30;
10442     x_charges_detail_rec.pricing_attribute31  := l_db_det_rec.pricing_attribute31;
10443     x_charges_detail_rec.pricing_attribute32  := l_db_det_rec.pricing_attribute32;
10444     x_charges_detail_rec.pricing_attribute33  := l_db_det_rec.pricing_attribute33;
10445     x_charges_detail_rec.pricing_attribute34  := l_db_det_rec.pricing_attribute34;
10446     x_charges_detail_rec.pricing_attribute35  := l_db_det_rec.pricing_attribute35;
10447     x_charges_detail_rec.pricing_attribute36  := l_db_det_rec.pricing_attribute36;
10448     x_charges_detail_rec.pricing_attribute37  := l_db_det_rec.pricing_attribute37;
10449     x_charges_detail_rec.pricing_attribute38  := l_db_det_rec.pricing_attribute38;
10450     x_charges_detail_rec.pricing_attribute39  := l_db_det_rec.pricing_attribute39;
10451     x_charges_detail_rec.pricing_attribute40  := l_db_det_rec.pricing_attribute40;
10452     x_charges_detail_rec.pricing_attribute41  := l_db_det_rec.pricing_attribute41;
10453     x_charges_detail_rec.pricing_attribute42  := l_db_det_rec.pricing_attribute42;
10454     x_charges_detail_rec.pricing_attribute43  := l_db_det_rec.pricing_attribute43;
10455     x_charges_detail_rec.pricing_attribute44  := l_db_det_rec.pricing_attribute44;
10456     x_charges_detail_rec.pricing_attribute45  := l_db_det_rec.pricing_attribute45;
10457     x_charges_detail_rec.pricing_attribute46  := l_db_det_rec.pricing_attribute46;
10458     x_charges_detail_rec.pricing_attribute47  := l_db_det_rec.pricing_attribute47;
10459     x_charges_detail_rec.pricing_attribute48  := l_db_det_rec.pricing_attribute48;
10460     x_charges_detail_rec.pricing_attribute49  := l_db_det_rec.pricing_attribute49;
10461     x_charges_detail_rec.pricing_attribute50  := l_db_det_rec.pricing_attribute50;
10462     x_charges_detail_rec.pricing_attribute51  := l_db_det_rec.pricing_attribute51;
10463     x_charges_detail_rec.pricing_attribute52  := l_db_det_rec.pricing_attribute52;
10464     x_charges_detail_rec.pricing_attribute53  := l_db_det_rec.pricing_attribute53;
10465     x_charges_detail_rec.pricing_attribute54  := l_db_det_rec.pricing_attribute54;
10466     x_charges_detail_rec.pricing_attribute55  := l_db_det_rec.pricing_attribute55;
10467     x_charges_detail_rec.pricing_attribute56  := l_db_det_rec.pricing_attribute56;
10468     x_charges_detail_rec.pricing_attribute57  := l_db_det_rec.pricing_attribute57;
10469     x_charges_detail_rec.pricing_attribute58  := l_db_det_rec.pricing_attribute58;
10470     x_charges_detail_rec.pricing_attribute59  := l_db_det_rec.pricing_attribute59;
10471     x_charges_detail_rec.pricing_attribute60  := l_db_det_rec.pricing_attribute60;
10472     x_charges_detail_rec.pricing_attribute61  := l_db_det_rec.pricing_attribute61;
10473     x_charges_detail_rec.pricing_attribute62  := l_db_det_rec.pricing_attribute62;
10474     x_charges_detail_rec.pricing_attribute63  := l_db_det_rec.pricing_attribute63;
10475     x_charges_detail_rec.pricing_attribute64  := l_db_det_rec.pricing_attribute64;
10476     x_charges_detail_rec.pricing_attribute65  := l_db_det_rec.pricing_attribute65;
10477     x_charges_detail_rec.pricing_attribute66  := l_db_det_rec.pricing_attribute66;
10478     x_charges_detail_rec.pricing_attribute67  := l_db_det_rec.pricing_attribute67;
10479     x_charges_detail_rec.pricing_attribute68  := l_db_det_rec.pricing_attribute68;
10480     x_charges_detail_rec.pricing_attribute69  := l_db_det_rec.pricing_attribute69;
10481     x_charges_detail_rec.pricing_attribute70  := l_db_det_rec.pricing_attribute70;
10482     x_charges_detail_rec.pricing_attribute71  := l_db_det_rec.pricing_attribute71;
10483     x_charges_detail_rec.pricing_attribute72  := l_db_det_rec.pricing_attribute72;
10484     x_charges_detail_rec.pricing_attribute73  := l_db_det_rec.pricing_attribute73;
10485     x_charges_detail_rec.pricing_attribute74  := l_db_det_rec.pricing_attribute74;
10486     x_charges_detail_rec.pricing_attribute75  := l_db_det_rec.pricing_attribute75;
10487     x_charges_detail_rec.pricing_attribute76  := l_db_det_rec.pricing_attribute76;
10488     x_charges_detail_rec.pricing_attribute77  := l_db_det_rec.pricing_attribute77;
10489     x_charges_detail_rec.pricing_attribute78  := l_db_det_rec.pricing_attribute78;
10490     x_charges_detail_rec.pricing_attribute79  := l_db_det_rec.pricing_attribute79;
10491     x_charges_detail_rec.pricing_attribute80  := l_db_det_rec.pricing_attribute80;
10492     x_charges_detail_rec.pricing_attribute81  := l_db_det_rec.pricing_attribute81;
10493     x_charges_detail_rec.pricing_attribute82  := l_db_det_rec.pricing_attribute82;
10494     x_charges_detail_rec.pricing_attribute83  := l_db_det_rec.pricing_attribute83;
10495     x_charges_detail_rec.pricing_attribute84  := l_db_det_rec.pricing_attribute84;
10496     x_charges_detail_rec.pricing_attribute85  := l_db_det_rec.pricing_attribute85;
10497     x_charges_detail_rec.pricing_attribute86  := l_db_det_rec.pricing_attribute86;
10498     x_charges_detail_rec.pricing_attribute87  := l_db_det_rec.pricing_attribute87;
10499     x_charges_detail_rec.pricing_attribute88  := l_db_det_rec.pricing_attribute88;
10500     x_charges_detail_rec.pricing_attribute89  := l_db_det_rec.pricing_attribute89;
10501     x_charges_detail_rec.pricing_attribute90  := l_db_det_rec.pricing_attribute90;
10502     x_charges_detail_rec.pricing_attribute91  := l_db_det_rec.pricing_attribute91;
10503     x_charges_detail_rec.pricing_attribute92  := l_db_det_rec.pricing_attribute92;
10504     x_charges_detail_rec.pricing_attribute93  := l_db_det_rec.pricing_attribute93;
10505     x_charges_detail_rec.pricing_attribute94  := l_db_det_rec.pricing_attribute94;
10506     x_charges_detail_rec.pricing_attribute95  := l_db_det_rec.pricing_attribute95;
10507     x_charges_detail_rec.pricing_attribute96  := l_db_det_rec.pricing_attribute96;
10508     x_charges_detail_rec.pricing_attribute97  := l_db_det_rec.pricing_attribute97;
10509     x_charges_detail_rec.pricing_attribute98  := l_db_det_rec.pricing_attribute98;
10510     x_charges_detail_rec.pricing_attribute99  := l_db_det_rec.pricing_attribute99;
10511     x_charges_detail_rec.pricing_attribute100 := l_db_det_rec.pricing_attribute100;
10512 
10513  ELSIF p_charges_detail_rec.pricing_context IS NULL THEN
10514 
10515     --DBMS_OUTPUT.PUT_LINE('parameter context is null ');
10516     x_charges_detail_rec.pricing_context      := null ;
10517     x_charges_detail_rec.pricing_attribute1   := null ;
10518     x_charges_detail_rec.pricing_attribute2   := null ;
10519     x_charges_detail_rec.pricing_attribute3   := null ;
10520     x_charges_detail_rec.pricing_attribute4   := null ;
10521     x_charges_detail_rec.pricing_attribute5   := null ;
10522     x_charges_detail_rec.pricing_attribute6   := null ;
10523     x_charges_detail_rec.pricing_attribute7   := null ;
10524     x_charges_detail_rec.pricing_attribute8   := null ;
10525     x_charges_detail_rec.pricing_attribute9   := null ;
10526     x_charges_detail_rec.pricing_attribute10  := null ;
10527     x_charges_detail_rec.pricing_attribute11  := null ;
10528     x_charges_detail_rec.pricing_attribute12  := null ;
10529     x_charges_detail_rec.pricing_attribute13  := null ;
10530     x_charges_detail_rec.pricing_attribute14  := null ;
10531     x_charges_detail_rec.pricing_attribute15  := null ;
10532     x_charges_detail_rec.pricing_attribute16  := null ;
10533     x_charges_detail_rec.pricing_attribute17  := null ;
10534     x_charges_detail_rec.pricing_attribute18  := null ;
10535     x_charges_detail_rec.pricing_attribute19  := null ;
10536     x_charges_detail_rec.pricing_attribute20  := null ;
10537     x_charges_detail_rec.pricing_attribute21  := null ;
10538     x_charges_detail_rec.pricing_attribute22  := null ;
10539     x_charges_detail_rec.pricing_attribute23  := null ;
10540     x_charges_detail_rec.pricing_attribute24  := null ;
10541     x_charges_detail_rec.pricing_attribute25  := null ;
10542     x_charges_detail_rec.pricing_attribute26  := null ;
10543     x_charges_detail_rec.pricing_attribute27  := null ;
10544     x_charges_detail_rec.pricing_attribute28  := null ;
10545     x_charges_detail_rec.pricing_attribute29  := null ;
10546     x_charges_detail_rec.pricing_attribute30  := null ;
10547     x_charges_detail_rec.pricing_attribute31  := null ;
10548     x_charges_detail_rec.pricing_attribute32  := null ;
10549     x_charges_detail_rec.pricing_attribute33  := null ;
10550     x_charges_detail_rec.pricing_attribute34  := null ;
10551     x_charges_detail_rec.pricing_attribute35  := null ;
10552     x_charges_detail_rec.pricing_attribute36  := null ;
10553     x_charges_detail_rec.pricing_attribute37  := null ;
10554     x_charges_detail_rec.pricing_attribute38  := null ;
10555     x_charges_detail_rec.pricing_attribute39  := null ;
10556     x_charges_detail_rec.pricing_attribute40  := null ;
10557     x_charges_detail_rec.pricing_attribute41  := null ;
10558     x_charges_detail_rec.pricing_attribute42  := null ;
10559     x_charges_detail_rec.pricing_attribute43  := null ;
10560     x_charges_detail_rec.pricing_attribute44  := null ;
10561     x_charges_detail_rec.pricing_attribute45  := null ;
10562     x_charges_detail_rec.pricing_attribute46  := null ;
10563     x_charges_detail_rec.pricing_attribute47  := null ;
10564     x_charges_detail_rec.pricing_attribute48  := null ;
10565     x_charges_detail_rec.pricing_attribute49  := null ;
10566     x_charges_detail_rec.pricing_attribute50  := null ;
10567     x_charges_detail_rec.pricing_attribute51  := null ;
10568     x_charges_detail_rec.pricing_attribute52  := null ;
10569     x_charges_detail_rec.pricing_attribute53  := null ;
10570     x_charges_detail_rec.pricing_attribute54  := null ;
10571     x_charges_detail_rec.pricing_attribute55  := null ;
10572     x_charges_detail_rec.pricing_attribute56  := null ;
10573     x_charges_detail_rec.pricing_attribute57  := null ;
10574     x_charges_detail_rec.pricing_attribute58  := null ;
10575     x_charges_detail_rec.pricing_attribute59  := null ;
10576     x_charges_detail_rec.pricing_attribute59  := null ;
10577     x_charges_detail_rec.pricing_attribute60  := null ;
10578     x_charges_detail_rec.pricing_attribute61  := null ;
10579     x_charges_detail_rec.pricing_attribute62  := null ;
10580     x_charges_detail_rec.pricing_attribute63  := null ;
10581     x_charges_detail_rec.pricing_attribute64  := null ;
10582     x_charges_detail_rec.pricing_attribute65  := null ;
10583     x_charges_detail_rec.pricing_attribute66  := null ;
10584     x_charges_detail_rec.pricing_attribute67  := null ;
10585     x_charges_detail_rec.pricing_attribute68  := null ;
10586     x_charges_detail_rec.pricing_attribute69  := null ;
10587     x_charges_detail_rec.pricing_attribute70  := null ;
10588     x_charges_detail_rec.pricing_attribute71  := null ;
10589     x_charges_detail_rec.pricing_attribute72  := null ;
10590     x_charges_detail_rec.pricing_attribute73  := null ;
10591     x_charges_detail_rec.pricing_attribute74  := null ;
10592     x_charges_detail_rec.pricing_attribute75  := null ;
10593     x_charges_detail_rec.pricing_attribute76  := null ;
10594     x_charges_detail_rec.pricing_attribute77  := null ;
10595     x_charges_detail_rec.pricing_attribute78  := null ;
10596     x_charges_detail_rec.pricing_attribute79  := null ;
10597     x_charges_detail_rec.pricing_attribute80  := null ;
10598     x_charges_detail_rec.pricing_attribute81  := null ;
10599     x_charges_detail_rec.pricing_attribute82  := null ;
10600     x_charges_detail_rec.pricing_attribute83  := null ;
10601     x_charges_detail_rec.pricing_attribute84  := null ;
10602     x_charges_detail_rec.pricing_attribute85  := null ;
10603     x_charges_detail_rec.pricing_attribute86  := null ;
10604     x_charges_detail_rec.pricing_attribute87  := null ;
10605     x_charges_detail_rec.pricing_attribute88  := null ;
10606     x_charges_detail_rec.pricing_attribute89  := null ;
10607     x_charges_detail_rec.pricing_attribute90  := null ;
10608     x_charges_detail_rec.pricing_attribute91  := null ;
10609     x_charges_detail_rec.pricing_attribute92  := null ;
10610     x_charges_detail_rec.pricing_attribute93  := null ;
10611     x_charges_detail_rec.pricing_attribute94  := null ;
10612     x_charges_detail_rec.pricing_attribute95  := null ;
10613     x_charges_detail_rec.pricing_attribute96  := null ;
10614     x_charges_detail_rec.pricing_attribute97  := null ;
10615     x_charges_detail_rec.pricing_attribute98  := null ;
10616     x_charges_detail_rec.pricing_attribute99  := null ;
10617     x_charges_detail_rec.pricing_attribute100 := null ;
10618 
10619   ELSE
10620 
10621     -- the pricing context is not null
10622     -- copy the incoming parameters to the record structure
10623     -- --DBMS_OUTPUT.PUT_LINE('parameter context is not null ');
10624 
10625     x_charges_detail_rec.pricing_context     := p_charges_detail_rec.pricing_context ;
10626 
10627     IF p_charges_detail_rec.pricing_attribute1 = FND_API.G_MISS_CHAR THEN
10628       x_charges_detail_rec.pricing_attribute1  := null;
10629     ELSE
10630       x_charges_detail_rec.pricing_attribute1  := p_charges_detail_rec.pricing_attribute1;
10631     END IF;
10632 
10633     IF p_charges_detail_rec.pricing_attribute2 = FND_API.G_MISS_CHAR THEN
10634       x_charges_detail_rec.pricing_attribute2  := null;
10635     ELSE
10636       x_charges_detail_rec.pricing_attribute2  := p_charges_detail_rec.pricing_attribute2;
10637     END IF;
10638 
10639     IF p_charges_detail_rec.pricing_attribute3 = FND_API.G_MISS_CHAR THEN
10640       x_charges_detail_rec.pricing_attribute3  := null;
10641     ELSE
10642       x_charges_detail_rec.pricing_attribute3  := p_charges_detail_rec.pricing_attribute3;
10643     END IF;
10644 
10645     IF p_charges_detail_rec.pricing_attribute4 = FND_API.G_MISS_CHAR THEN
10646       x_charges_detail_rec.pricing_attribute4  := null;
10647     ELSE
10648       x_charges_detail_rec.pricing_attribute4  := p_charges_detail_rec.pricing_attribute4;
10649     END IF;
10650 
10651     IF p_charges_detail_rec.pricing_attribute5 = FND_API.G_MISS_CHAR THEN
10652       x_charges_detail_rec.pricing_attribute5  := null;
10653     ELSE
10654       x_charges_detail_rec.pricing_attribute5  := p_charges_detail_rec.pricing_attribute5;
10655     END IF;
10656 
10657      IF p_charges_detail_rec.pricing_attribute6 = FND_API.G_MISS_CHAR THEN
10658       x_charges_detail_rec.pricing_attribute6  := null;
10659     ELSE
10660       x_charges_detail_rec.pricing_attribute6  := p_charges_detail_rec.pricing_attribute6;
10661     END IF;
10662 
10663     IF p_charges_detail_rec.pricing_attribute7 = FND_API.G_MISS_CHAR THEN
10664       x_charges_detail_rec.pricing_attribute7  := null;
10665     ELSE
10666       x_charges_detail_rec.pricing_attribute7  := p_charges_detail_rec.pricing_attribute7;
10667     END IF;
10668 
10669     IF p_charges_detail_rec.pricing_attribute8 = FND_API.G_MISS_CHAR THEN
10670       x_charges_detail_rec.pricing_attribute8  := null;
10671     ELSE
10672       x_charges_detail_rec.pricing_attribute8  := p_charges_detail_rec.pricing_attribute8;
10673     END IF;
10674 
10675     IF p_charges_detail_rec.pricing_attribute9 = FND_API.G_MISS_CHAR THEN
10676       x_charges_detail_rec.pricing_attribute9  := null;
10677     ELSE
10678       x_charges_detail_rec.pricing_attribute9  := p_charges_detail_rec.pricing_attribute9;
10679     END IF;
10680 
10681     IF p_charges_detail_rec.pricing_attribute10 = FND_API.G_MISS_CHAR THEN
10682       x_charges_detail_rec.pricing_attribute10  := null;
10683     ELSE
10684       x_charges_detail_rec.pricing_attribute10 := p_charges_detail_rec.pricing_attribute10;
10685     END IF;
10686 
10687     IF p_charges_detail_rec.pricing_attribute11 = FND_API.G_MISS_CHAR THEN
10688       x_charges_detail_rec.pricing_attribute11  := null;
10689     ELSE
10690       x_charges_detail_rec.pricing_attribute11  := p_charges_detail_rec.pricing_attribute11;
10691     END IF;
10692 
10693     IF p_charges_detail_rec.pricing_attribute12 = FND_API.G_MISS_CHAR THEN
10694       x_charges_detail_rec.pricing_attribute12  := null;
10695     ELSE
10696       x_charges_detail_rec.pricing_attribute12  := p_charges_detail_rec.pricing_attribute12;
10697     END IF;
10698 
10699     IF p_charges_detail_rec.pricing_attribute13 = FND_API.G_MISS_CHAR THEN
10700       x_charges_detail_rec.pricing_attribute13  := null;
10701     ELSE
10702       x_charges_detail_rec.pricing_attribute13  := p_charges_detail_rec.pricing_attribute13;
10703     END IF;
10704 
10705     IF p_charges_detail_rec.pricing_attribute14 = FND_API.G_MISS_CHAR THEN
10706       x_charges_detail_rec.pricing_attribute14  := null;
10707     ELSE
10708       x_charges_detail_rec.pricing_attribute14  := p_charges_detail_rec.pricing_attribute14;
10709     END IF;
10710 
10711     IF p_charges_detail_rec.pricing_attribute15 = FND_API.G_MISS_CHAR THEN
10712       x_charges_detail_rec.pricing_attribute15  := null;
10713     ELSE
10714       x_charges_detail_rec.pricing_attribute15  := p_charges_detail_rec.pricing_attribute15;
10715     END IF;
10716 
10717     IF p_charges_detail_rec.pricing_attribute16 = FND_API.G_MISS_CHAR THEN
10718       x_charges_detail_rec.pricing_attribute16  := null;
10719     ELSE
10720       x_charges_detail_rec.pricing_attribute16  := p_charges_detail_rec.pricing_attribute16;
10721     END IF;
10722 
10723     IF p_charges_detail_rec.pricing_attribute17 = FND_API.G_MISS_CHAR THEN
10724       x_charges_detail_rec.pricing_attribute17  := null;
10725     ELSE
10726       x_charges_detail_rec.pricing_attribute17  := p_charges_detail_rec.pricing_attribute17;
10727     END IF;
10728 
10729     IF p_charges_detail_rec.pricing_attribute18 = FND_API.G_MISS_CHAR THEN
10730       x_charges_detail_rec.pricing_attribute18  := null;
10731     ELSE
10732       x_charges_detail_rec.pricing_attribute18  := p_charges_detail_rec.pricing_attribute18;
10733     END IF;
10734 
10735     IF p_charges_detail_rec.pricing_attribute19 = FND_API.G_MISS_CHAR THEN
10736       x_charges_detail_rec.pricing_attribute19  := null;
10737     ELSE
10738       x_charges_detail_rec.pricing_attribute19  := p_charges_detail_rec.pricing_attribute19;
10739     END IF;
10740 
10741     IF p_charges_detail_rec.pricing_attribute20 = FND_API.G_MISS_CHAR THEN
10742       x_charges_detail_rec.pricing_attribute20  := null;
10743     ELSE
10744       x_charges_detail_rec.pricing_attribute20  := p_charges_detail_rec.pricing_attribute20;
10745     END IF;
10746 
10747     IF p_charges_detail_rec.pricing_attribute21 = FND_API.G_MISS_CHAR THEN
10748       x_charges_detail_rec.pricing_attribute21  := null;
10749     ELSE
10750       x_charges_detail_rec.pricing_attribute21  := p_charges_detail_rec.pricing_attribute21;
10751     END IF;
10752 
10753     IF p_charges_detail_rec.pricing_attribute22 = FND_API.G_MISS_CHAR THEN
10754       x_charges_detail_rec.pricing_attribute22  := null;
10755     ELSE
10756       x_charges_detail_rec.pricing_attribute22  := p_charges_detail_rec.pricing_attribute22;
10757     END IF;
10758 
10759 
10760     IF p_charges_detail_rec.pricing_attribute23 = FND_API.G_MISS_CHAR THEN
10761       x_charges_detail_rec.pricing_attribute23  := null;
10762     ELSE
10763       x_charges_detail_rec.pricing_attribute23 := p_charges_detail_rec.pricing_attribute23;
10764     END IF;
10765 
10766     IF p_charges_detail_rec.pricing_attribute24 = FND_API.G_MISS_CHAR THEN
10767       x_charges_detail_rec.pricing_attribute24  := null;
10768     ELSE
10769       x_charges_detail_rec.pricing_attribute24  := p_charges_detail_rec.pricing_attribute24;
10770     END IF;
10771 
10772     IF p_charges_detail_rec.pricing_attribute25 = FND_API.G_MISS_CHAR THEN
10773       x_charges_detail_rec.pricing_attribute25  := null;
10774     ELSE
10775       x_charges_detail_rec.pricing_attribute25  := p_charges_detail_rec.pricing_attribute25;
10776     END IF;
10777 
10778     IF p_charges_detail_rec.pricing_attribute26 = FND_API.G_MISS_CHAR THEN
10779       x_charges_detail_rec.pricing_attribute26  := null;
10780     ELSE
10781       x_charges_detail_rec.pricing_attribute26  := p_charges_detail_rec.pricing_attribute26;
10782     END IF;
10783 
10784      IF p_charges_detail_rec.pricing_attribute27 = FND_API.G_MISS_CHAR THEN
10785       x_charges_detail_rec.pricing_attribute27  := null;
10786     ELSE
10787       x_charges_detail_rec.pricing_attribute27 := p_charges_detail_rec.pricing_attribute27;
10788     END IF;
10789 
10790     IF p_charges_detail_rec.pricing_attribute28 = FND_API.G_MISS_CHAR THEN
10791       x_charges_detail_rec.pricing_attribute28 := null;
10792     ELSE
10793       x_charges_detail_rec.pricing_attribute28  := p_charges_detail_rec.pricing_attribute28;
10794     END IF;
10795 
10796     IF p_charges_detail_rec.pricing_attribute29 = FND_API.G_MISS_CHAR THEN
10797       x_charges_detail_rec.pricing_attribute29  := null;
10798     ELSE
10799       x_charges_detail_rec.pricing_attribute29  := p_charges_detail_rec.pricing_attribute29;
10800     END IF;
10801 
10802      IF p_charges_detail_rec.pricing_attribute30 = FND_API.G_MISS_CHAR THEN
10803       x_charges_detail_rec.pricing_attribute30  := null;
10804     ELSE
10805       x_charges_detail_rec.pricing_attribute30  := p_charges_detail_rec.pricing_attribute30;
10806     END IF;
10807 
10808     IF p_charges_detail_rec.pricing_attribute31 = FND_API.G_MISS_CHAR THEN
10809       x_charges_detail_rec.pricing_attribute31  := null;
10810     ELSE
10811       x_charges_detail_rec.pricing_attribute31  := p_charges_detail_rec.pricing_attribute31;
10812     END IF;
10813 
10814     IF p_charges_detail_rec.pricing_attribute32 = FND_API.G_MISS_CHAR THEN
10815       x_charges_detail_rec.pricing_attribute32  := null;
10816     ELSE
10817       x_charges_detail_rec.pricing_attribute32  := p_charges_detail_rec.pricing_attribute32;
10818     END IF;
10819 
10820     IF p_charges_detail_rec.pricing_attribute33 = FND_API.G_MISS_CHAR THEN
10821       x_charges_detail_rec.pricing_attribute33  := null;
10822     ELSE
10823       x_charges_detail_rec.pricing_attribute33  := p_charges_detail_rec.pricing_attribute33;
10824     END IF;
10825 
10826     IF p_charges_detail_rec.pricing_attribute34 = FND_API.G_MISS_CHAR THEN
10827       x_charges_detail_rec.pricing_attribute34  := null;
10828     ELSE
10829       x_charges_detail_rec.pricing_attribute34  := p_charges_detail_rec.pricing_attribute34;
10830     END IF;
10831 
10832     IF p_charges_detail_rec.pricing_attribute35 = FND_API.G_MISS_CHAR THEN
10833       x_charges_detail_rec.pricing_attribute35  := null;
10834     ELSE
10835       x_charges_detail_rec.pricing_attribute35  := p_charges_detail_rec.pricing_attribute35;
10836     END IF;
10837 
10838     IF p_charges_detail_rec.pricing_attribute36 = FND_API.G_MISS_CHAR THEN
10839       x_charges_detail_rec.pricing_attribute36  := null;
10840     ELSE
10841       x_charges_detail_rec.pricing_attribute36  := p_charges_detail_rec.pricing_attribute36;
10842     END IF;
10843 
10844     IF p_charges_detail_rec.pricing_attribute37 = FND_API.G_MISS_CHAR THEN
10845       x_charges_detail_rec.pricing_attribute37  := null;
10846     ELSE
10847       x_charges_detail_rec.pricing_attribute37  := p_charges_detail_rec.pricing_attribute37;
10848     END IF;
10849 
10850     IF p_charges_detail_rec.pricing_attribute38 = FND_API.G_MISS_CHAR THEN
10851       x_charges_detail_rec.pricing_attribute38  := null;
10852     ELSE
10853       x_charges_detail_rec.pricing_attribute38  := p_charges_detail_rec.pricing_attribute38;
10854     END IF;
10855 
10856     IF p_charges_detail_rec.pricing_attribute39 = FND_API.G_MISS_CHAR THEN
10857       x_charges_detail_rec.pricing_attribute39  := null;
10858     ELSE
10859       x_charges_detail_rec.pricing_attribute39  := p_charges_detail_rec.pricing_attribute39;
10860     END IF;
10861 
10862     IF p_charges_detail_rec.pricing_attribute40 = FND_API.G_MISS_CHAR THEN
10863       x_charges_detail_rec.pricing_attribute40  := null;
10864     ELSE
10865       x_charges_detail_rec.pricing_attribute40  := p_charges_detail_rec.pricing_attribute40;
10866     END IF;
10867 
10868     IF p_charges_detail_rec.pricing_attribute41 = FND_API.G_MISS_CHAR THEN
10869       x_charges_detail_rec.pricing_attribute41  := null;
10870     ELSE
10871       x_charges_detail_rec.pricing_attribute41 := p_charges_detail_rec.pricing_attribute41;
10872     END IF;
10873 
10874      IF p_charges_detail_rec.pricing_attribute42 = FND_API.G_MISS_CHAR THEN
10875       x_charges_detail_rec.pricing_attribute42  := null;
10876     ELSE
10877       x_charges_detail_rec.pricing_attribute42  := p_charges_detail_rec.pricing_attribute42;
10878     END IF;
10879 
10880     IF p_charges_detail_rec.pricing_attribute43 = FND_API.G_MISS_CHAR THEN
10881       x_charges_detail_rec.pricing_attribute43  := null;
10882     ELSE
10883       x_charges_detail_rec.pricing_attribute43  := p_charges_detail_rec.pricing_attribute43;
10884     END IF;
10885 
10886     IF p_charges_detail_rec.pricing_attribute44 = FND_API.G_MISS_CHAR THEN
10887       x_charges_detail_rec.pricing_attribute44  := null;
10888     ELSE
10889       x_charges_detail_rec.pricing_attribute44  := p_charges_detail_rec.pricing_attribute44;
10890     END IF;
10891 
10892      IF p_charges_detail_rec.pricing_attribute45 = FND_API.G_MISS_CHAR THEN
10893       x_charges_detail_rec.pricing_attribute45  := null;
10894     ELSE
10895       x_charges_detail_rec.pricing_attribute45  := p_charges_detail_rec.pricing_attribute45;
10896     END IF;
10897 
10898     IF p_charges_detail_rec.pricing_attribute46 = FND_API.G_MISS_CHAR THEN
10899       x_charges_detail_rec.pricing_attribute46  := null;
10900     ELSE
10901       x_charges_detail_rec.pricing_attribute46  := p_charges_detail_rec.pricing_attribute46;
10902     END IF;
10903 
10904     IF p_charges_detail_rec.pricing_attribute47 = FND_API.G_MISS_CHAR THEN
10905       x_charges_detail_rec.pricing_attribute47  := null;
10906     ELSE
10907       x_charges_detail_rec.pricing_attribute47  := p_charges_detail_rec.pricing_attribute47;
10908     END IF;
10909 
10910     IF p_charges_detail_rec.pricing_attribute48 = FND_API.G_MISS_CHAR THEN
10911       x_charges_detail_rec.pricing_attribute48  := null;
10912     ELSE
10913       x_charges_detail_rec.pricing_attribute48  := p_charges_detail_rec.pricing_attribute48;
10914     END IF;
10915 
10916     IF p_charges_detail_rec.pricing_attribute49 = FND_API.G_MISS_CHAR THEN
10917       x_charges_detail_rec.pricing_attribute49 := null;
10918     ELSE
10919       x_charges_detail_rec.pricing_attribute49  := p_charges_detail_rec.pricing_attribute49;
10920     END IF;
10921 
10922     IF p_charges_detail_rec.pricing_attribute50 = FND_API.G_MISS_CHAR THEN
10923       x_charges_detail_rec.pricing_attribute50  := null;
10924     ELSE
10925       x_charges_detail_rec.pricing_attribute50  := p_charges_detail_rec.pricing_attribute50;
10926     END IF;
10927 
10928     IF p_charges_detail_rec.pricing_attribute51 = FND_API.G_MISS_CHAR THEN
10929       x_charges_detail_rec.pricing_attribute51  := null;
10930     ELSE
10931       x_charges_detail_rec.pricing_attribute51  := p_charges_detail_rec.pricing_attribute51;
10932     END IF;
10933 
10934      IF p_charges_detail_rec.pricing_attribute52 = FND_API.G_MISS_CHAR THEN
10935       x_charges_detail_rec.pricing_attribute52  := null;
10936     ELSE
10937       x_charges_detail_rec.pricing_attribute52  := p_charges_detail_rec.pricing_attribute52;
10938     END IF;
10939 
10940     IF p_charges_detail_rec.pricing_attribute53 = FND_API.G_MISS_CHAR THEN
10941       x_charges_detail_rec.pricing_attribute53  := null;
10942     ELSE
10943       x_charges_detail_rec.pricing_attribute53  := p_charges_detail_rec.pricing_attribute53;
10944     END IF;
10945 
10946     IF p_charges_detail_rec.pricing_attribute54 = FND_API.G_MISS_CHAR THEN
10947       x_charges_detail_rec.pricing_attribute54  := null;
10948     ELSE
10949       x_charges_detail_rec.pricing_attribute54  := p_charges_detail_rec.pricing_attribute54;
10950     END IF;
10951 
10952     IF p_charges_detail_rec.pricing_attribute55 = FND_API.G_MISS_CHAR THEN
10953       x_charges_detail_rec.pricing_attribute55  := null;
10954     ELSE
10955       x_charges_detail_rec.pricing_attribute55  := p_charges_detail_rec.pricing_attribute55;
10956     END IF;
10957 
10958     IF p_charges_detail_rec.pricing_attribute56 = FND_API.G_MISS_CHAR THEN
10959       x_charges_detail_rec.pricing_attribute56  := null;
10960     ELSE
10961       x_charges_detail_rec.pricing_attribute56  := p_charges_detail_rec.pricing_attribute56;
10962     END IF;
10963 
10964     IF p_charges_detail_rec.pricing_attribute57 = FND_API.G_MISS_CHAR THEN
10965       x_charges_detail_rec.pricing_attribute57  := null;
10966     ELSE
10967       x_charges_detail_rec.pricing_attribute57  := p_charges_detail_rec.pricing_attribute57;
10968     END IF;
10969 
10970     IF p_charges_detail_rec.pricing_attribute58 = FND_API.G_MISS_CHAR THEN
10971       x_charges_detail_rec.pricing_attribute58  := null;
10972     ELSE
10973       x_charges_detail_rec.pricing_attribute58  := p_charges_detail_rec.pricing_attribute58;
10974     END IF;
10975 
10976     IF p_charges_detail_rec.pricing_attribute59 = FND_API.G_MISS_CHAR THEN
10977       x_charges_detail_rec.pricing_attribute59  := null;
10978     ELSE
10979       x_charges_detail_rec.pricing_attribute59  := p_charges_detail_rec.pricing_attribute59;
10980     END IF;
10981 
10982     IF p_charges_detail_rec.pricing_attribute60 = FND_API.G_MISS_CHAR THEN
10983       x_charges_detail_rec.pricing_attribute60  := null;
10984     ELSE
10985       x_charges_detail_rec.pricing_attribute60  := p_charges_detail_rec.pricing_attribute60;
10986     END IF;
10987 
10988     IF p_charges_detail_rec.pricing_attribute61 = FND_API.G_MISS_CHAR THEN
10989       x_charges_detail_rec.pricing_attribute61  := null;
10990     ELSE
10991       x_charges_detail_rec.pricing_attribute61  := p_charges_detail_rec.pricing_attribute61;
10992     END IF;
10993 
10994     IF p_charges_detail_rec.pricing_attribute62 = FND_API.G_MISS_CHAR THEN
10995       x_charges_detail_rec.pricing_attribute62  := null;
10996     ELSE
10997       x_charges_detail_rec.pricing_attribute62  := p_charges_detail_rec.pricing_attribute62;
10998     END IF;
10999 
11000     IF p_charges_detail_rec.pricing_attribute63 = FND_API.G_MISS_CHAR THEN
11001       x_charges_detail_rec.pricing_attribute63  := null;
11002     ELSE
11003       x_charges_detail_rec.pricing_attribute63  := p_charges_detail_rec.pricing_attribute63;
11004     END IF;
11005 
11006     IF p_charges_detail_rec.pricing_attribute64 = FND_API.G_MISS_CHAR THEN
11007       x_charges_detail_rec.pricing_attribute64  := null;
11008     ELSE
11009       x_charges_detail_rec.pricing_attribute64  := p_charges_detail_rec.pricing_attribute64;
11010     END IF;
11011 
11012     IF p_charges_detail_rec.pricing_attribute65 = FND_API.G_MISS_CHAR THEN
11013       x_charges_detail_rec.pricing_attribute65  := null;
11014     ELSE
11015       x_charges_detail_rec.pricing_attribute65  := p_charges_detail_rec.pricing_attribute65;
11016     END IF;
11017 
11018     IF p_charges_detail_rec.pricing_attribute66 = FND_API.G_MISS_CHAR THEN
11019       x_charges_detail_rec.pricing_attribute66  := null;
11020     ELSE
11021       x_charges_detail_rec.pricing_attribute66  := p_charges_detail_rec.pricing_attribute66;
11022     END IF;
11023 
11024     IF p_charges_detail_rec.pricing_attribute67 = FND_API.G_MISS_CHAR THEN
11025       x_charges_detail_rec.pricing_attribute67  := null;
11026     ELSE
11027       x_charges_detail_rec.pricing_attribute67  := p_charges_detail_rec.pricing_attribute67;
11028     END IF;
11029 
11030     IF p_charges_detail_rec.pricing_attribute68 = FND_API.G_MISS_CHAR THEN
11031       x_charges_detail_rec.pricing_attribute68  := null;
11032     ELSE
11033       x_charges_detail_rec.pricing_attribute68  := p_charges_detail_rec.pricing_attribute68;
11034     END IF;
11035 
11036     IF p_charges_detail_rec.pricing_attribute69 = FND_API.G_MISS_CHAR THEN
11037       x_charges_detail_rec.pricing_attribute69  := null;
11038     ELSE
11039       x_charges_detail_rec.pricing_attribute69  := p_charges_detail_rec.pricing_attribute69;
11040     END IF;
11041 
11042     IF p_charges_detail_rec.pricing_attribute70 = FND_API.G_MISS_CHAR THEN
11043       x_charges_detail_rec.pricing_attribute70  := null;
11044     ELSE
11045       x_charges_detail_rec.pricing_attribute70  := p_charges_detail_rec.pricing_attribute70;
11046     END IF;
11047 
11048     IF p_charges_detail_rec.pricing_attribute71 = FND_API.G_MISS_CHAR THEN
11049       x_charges_detail_rec.pricing_attribute71  := null;
11050     ELSE
11051       x_charges_detail_rec.pricing_attribute71 := p_charges_detail_rec.pricing_attribute71;
11052     END IF;
11053 
11054     IF p_charges_detail_rec.pricing_attribute72 = FND_API.G_MISS_CHAR THEN
11055       x_charges_detail_rec.pricing_attribute72  := null;
11056     ELSE
11057       x_charges_detail_rec.pricing_attribute72  := p_charges_detail_rec.pricing_attribute72;
11058     END IF;
11059 
11060     IF p_charges_detail_rec.pricing_attribute73 = FND_API.G_MISS_CHAR THEN
11061       x_charges_detail_rec.pricing_attribute73  := null;
11062     ELSE
11063       x_charges_detail_rec.pricing_attribute73  := p_charges_detail_rec.pricing_attribute73;
11064     END IF;
11065 
11066     IF p_charges_detail_rec.pricing_attribute74 = FND_API.G_MISS_CHAR THEN
11067       x_charges_detail_rec.pricing_attribute74  := null;
11068     ELSE
11069       x_charges_detail_rec.pricing_attribute74  := p_charges_detail_rec.pricing_attribute74;
11070     END IF;
11071 
11072     IF p_charges_detail_rec.pricing_attribute75 = FND_API.G_MISS_CHAR THEN
11073       x_charges_detail_rec.pricing_attribute75  := null;
11074     ELSE
11075       x_charges_detail_rec.pricing_attribute75  := p_charges_detail_rec.pricing_attribute75;
11076     END IF;
11077 
11078     IF p_charges_detail_rec.pricing_attribute76 = FND_API.G_MISS_CHAR THEN
11079       x_charges_detail_rec.pricing_attribute76  := null;
11080     ELSE
11081       x_charges_detail_rec.pricing_attribute76  := p_charges_detail_rec.pricing_attribute76;
11082     END IF;
11083 
11084      IF p_charges_detail_rec.pricing_attribute77 = FND_API.G_MISS_CHAR THEN
11085       x_charges_detail_rec.pricing_attribute77  := null;
11086     ELSE
11087       x_charges_detail_rec.pricing_attribute77  := p_charges_detail_rec.pricing_attribute77;
11088     END IF;
11089 
11090     IF p_charges_detail_rec.pricing_attribute78 = FND_API.G_MISS_CHAR THEN
11091       x_charges_detail_rec.pricing_attribute78  := null;
11092     ELSE
11093       x_charges_detail_rec.pricing_attribute78  := p_charges_detail_rec.pricing_attribute78;
11094     END IF;
11095 
11096     IF p_charges_detail_rec.pricing_attribute79 = FND_API.G_MISS_CHAR THEN
11097       x_charges_detail_rec.pricing_attribute79  := null;
11098     ELSE
11099       x_charges_detail_rec.pricing_attribute79  := p_charges_detail_rec.pricing_attribute79;
11100     END IF;
11101 
11102       IF p_charges_detail_rec.pricing_attribute80 = FND_API.G_MISS_CHAR THEN
11103       x_charges_detail_rec.pricing_attribute80  := null;
11104     ELSE
11105       x_charges_detail_rec.pricing_attribute80  := p_charges_detail_rec.pricing_attribute80;
11106     END IF;
11107 
11108     IF p_charges_detail_rec.pricing_attribute81 = FND_API.G_MISS_CHAR THEN
11109       x_charges_detail_rec.pricing_attribute81  := null;
11110     ELSE
11111       x_charges_detail_rec.pricing_attribute81  := p_charges_detail_rec.pricing_attribute81;
11112     END IF;
11113 
11114     IF p_charges_detail_rec.pricing_attribute82 = FND_API.G_MISS_CHAR THEN
11115       x_charges_detail_rec.pricing_attribute82  := null;
11116     ELSE
11117       x_charges_detail_rec.pricing_attribute82  := p_charges_detail_rec.pricing_attribute82;
11118     END IF;
11119 
11120     IF p_charges_detail_rec.pricing_attribute83 = FND_API.G_MISS_CHAR THEN
11121       x_charges_detail_rec.pricing_attribute83  := null;
11122     ELSE
11123       x_charges_detail_rec.pricing_attribute83  := p_charges_detail_rec.pricing_attribute83;
11124     END IF;
11125 
11126     IF p_charges_detail_rec.pricing_attribute84 = FND_API.G_MISS_CHAR THEN
11127       x_charges_detail_rec.pricing_attribute84  := null;
11128     ELSE
11129       x_charges_detail_rec.pricing_attribute84  := p_charges_detail_rec.pricing_attribute84;
11130     END IF;
11131 
11132     IF p_charges_detail_rec.pricing_attribute85 = FND_API.G_MISS_CHAR THEN
11133       x_charges_detail_rec.pricing_attribute85 := null;
11134     ELSE
11135       x_charges_detail_rec.pricing_attribute85  := p_charges_detail_rec.pricing_attribute85;
11136     END IF;
11137 
11138     IF p_charges_detail_rec.pricing_attribute86 = FND_API.G_MISS_CHAR THEN
11139       x_charges_detail_rec.pricing_attribute86  := null;
11140     ELSE
11141       x_charges_detail_rec.pricing_attribute86  := p_charges_detail_rec.pricing_attribute86;
11142     END IF;
11143 
11144     IF p_charges_detail_rec.pricing_attribute87 = FND_API.G_MISS_CHAR THEN
11145       x_charges_detail_rec.pricing_attribute87  := null;
11146     ELSE
11147       x_charges_detail_rec.pricing_attribute87  := p_charges_detail_rec.pricing_attribute87;
11148     END IF;
11149 
11150     IF p_charges_detail_rec.pricing_attribute88 = FND_API.G_MISS_CHAR THEN
11151       x_charges_detail_rec.pricing_attribute88  := null;
11152     ELSE
11153       x_charges_detail_rec.pricing_attribute88  := p_charges_detail_rec.pricing_attribute88;
11154     END IF;
11155 
11156     IF p_charges_detail_rec.pricing_attribute89 = FND_API.G_MISS_CHAR THEN
11157       x_charges_detail_rec.pricing_attribute89  := null;
11158     ELSE
11159       x_charges_detail_rec.pricing_attribute89  := p_charges_detail_rec.pricing_attribute89;
11160     END IF;
11161 
11162     IF p_charges_detail_rec.pricing_attribute90 = FND_API.G_MISS_CHAR THEN
11163       x_charges_detail_rec.pricing_attribute90  := null;
11164     ELSE
11165       x_charges_detail_rec.pricing_attribute90  := p_charges_detail_rec.pricing_attribute90;
11166     END IF;
11167 
11168     IF p_charges_detail_rec.pricing_attribute91 = FND_API.G_MISS_CHAR THEN
11169       x_charges_detail_rec.pricing_attribute91  := null;
11170     ELSE
11171       x_charges_detail_rec.pricing_attribute91  := p_charges_detail_rec.pricing_attribute91;
11172     END IF;
11173 
11174     IF p_charges_detail_rec.pricing_attribute92 = FND_API.G_MISS_CHAR THEN
11175       x_charges_detail_rec.pricing_attribute92  := null;
11176     ELSE
11177       x_charges_detail_rec.pricing_attribute92  := p_charges_detail_rec.pricing_attribute92;
11178     END IF;
11179 
11180     IF p_charges_detail_rec.pricing_attribute93 = FND_API.G_MISS_CHAR THEN
11181       x_charges_detail_rec.pricing_attribute93  := null;
11182     ELSE
11183       x_charges_detail_rec.pricing_attribute93  := p_charges_detail_rec.pricing_attribute93;
11184     END IF;
11185 
11186     IF p_charges_detail_rec.pricing_attribute94 = FND_API.G_MISS_CHAR THEN
11187       x_charges_detail_rec.pricing_attribute94  := null;
11188     ELSE
11189       x_charges_detail_rec.pricing_attribute94  := p_charges_detail_rec.pricing_attribute94;
11190     END IF;
11191 
11192     IF p_charges_detail_rec.pricing_attribute95 = FND_API.G_MISS_CHAR THEN
11193       x_charges_detail_rec.pricing_attribute95  := null;
11194     ELSE
11195       x_charges_detail_rec.pricing_attribute95  := p_charges_detail_rec.pricing_attribute95;
11196     END IF;
11197 
11198     IF p_charges_detail_rec.pricing_attribute96 = FND_API.G_MISS_CHAR THEN
11199       x_charges_detail_rec.pricing_attribute96  := null;
11200     ELSE
11201       x_charges_detail_rec.pricing_attribute96  := p_charges_detail_rec.pricing_attribute96;
11202     END IF;
11203 
11204     IF p_charges_detail_rec.pricing_attribute97 = FND_API.G_MISS_CHAR THEN
11205       x_charges_detail_rec.pricing_attribute97  := null;
11206     ELSE
11207       x_charges_detail_rec.pricing_attribute97  := p_charges_detail_rec.pricing_attribute97;
11208     END IF;
11209 
11210      IF p_charges_detail_rec.pricing_attribute98 = FND_API.G_MISS_CHAR THEN
11211       x_charges_detail_rec.pricing_attribute98  := null;
11212     ELSE
11213       x_charges_detail_rec.pricing_attribute98  := p_charges_detail_rec.pricing_attribute98;
11214     END IF;
11215 
11216     IF p_charges_detail_rec.pricing_attribute99 = FND_API.G_MISS_CHAR THEN
11217       x_charges_detail_rec.pricing_attribute99  := null;
11218     ELSE
11219       x_charges_detail_rec.pricing_attribute99  := p_charges_detail_rec.pricing_attribute99;
11220     END IF;
11221 
11222     IF p_charges_detail_rec.pricing_attribute100 = FND_API.G_MISS_CHAR THEN
11223       x_charges_detail_rec.pricing_attribute100  := null;
11224     ELSE
11225       x_charges_detail_rec.pricing_attribute100  := p_charges_detail_rec.pricing_attribute100;
11226     END IF;
11227 
11228   END IF;
11229 
11230 END IF;
11231 -- ========================================
11232 -- Call the pricing API
11233 -- ========================================
11234 --DBMS_OUTPUT.PUT_LINE('Call the pricing API ...');
11235 --DBMS_OUTPUT.PUT_LINE('Billing Flag '||x_charges_detail_rec.billing_flag);
11236 --DBMS_OUTPUT.PUT_LINE('List Price '||p_charges_detail_rec.list_price);
11237 --DBMS_OUTPUT.PUT_LINE('After Warranty_cost '||p_charges_detail_rec.after_warranty_cost);
11238 
11239 IF p_validation_mode = 'I' THEN
11240 
11241   x_charges_detail_rec.apply_contract_discount := p_charges_detail_rec.apply_contract_discount;
11242 
11243   IF x_charges_detail_rec.billing_flag = 'L' AND
11244      p_charges_detail_rec.list_price IS NOT NULL THEN
11245 
11246       -- no need to call the pricing api
11247       -- assign to out record
11248       x_charges_detail_rec.list_price    := p_charges_detail_rec.list_price;
11249       x_charges_detail_rec.selling_price := p_charges_detail_rec.list_price;
11250 
11251       --bug # 3056622 charge amount is zero for items with negative prices
11252 
11253       --derive the after_warranty_cost
11254       IF x_charges_detail_rec.no_charge_flag <> 'Y' AND
11255          x_charges_detail_rec.selling_price IS NOT NULL THEN
11256 
11257          --Fix for Bug # 3388373
11258          IF p_charges_detail_rec.after_warranty_cost IS NULL THEN
11259            x_charges_detail_rec.after_warranty_cost := x_charges_detail_rec.selling_price * x_charges_detail_rec.quantity_required;
11260          ELSE
11261            x_charges_detail_rec.after_warranty_cost := p_charges_detail_rec.after_warranty_cost;
11262          END IF;
11263       ELSE
11264         -- no charge flag = 'Y'
11265         x_charges_detail_rec.after_warranty_cost := 0;
11266       END IF;
11267 
11268       --check to see if contract discount needs to be applied
11269       IF x_charges_detail_rec.apply_contract_discount = 'Y' AND
11270          x_charges_detail_rec.contract_line_id IS NOT NULL AND
11271          x_charges_detail_rec.no_charge_flag <> 'Y' THEN
11272 
11273         --assign to out record
11274         x_charges_detail_rec.apply_contract_discount := p_charges_detail_rec.apply_contract_discount;
11275 
11276         --call contracts dicounting API
11277         --DBMS_OUTPUT.PUT_LINE('Call Contracts API to Apply contracts 1');
11278 
11279         CS_Est_Apply_Contract_PKG.Apply_Contract(
11280           p_coverage_id           => x_charges_detail_rec.contract_line_id,
11281           p_coverage_txn_group_id => x_charges_detail_rec.coverage_txn_group_id,
11282           p_txn_billing_type_id   => x_charges_detail_rec.txn_billing_type_id,
11283           P_BUSINESS_PROCESS_ID   => x_charges_detail_rec.business_process_id,
11284           P_REQUEST_DATE          => l_request_date,
11285           p_amount                => x_charges_detail_rec.after_warranty_cost,
11286           p_discount_amount       => l_contract_discount,
11287           X_RETURN_STATUS         => l_return_status,
11288           X_MSG_COUNT             => l_msg_count,
11289           X_MSG_DATA              => l_msg_data);
11290 
11291         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
11292           FND_MESSAGE.Set_Name('CS', 'CS_CHG_APPLY_CONTRACT_WARNING');
11293           FND_MESSAGE.SET_TOKEN('REASON', l_msg_data);
11294           FND_MSG_PUB.Add;
11295           RAISE FND_API.G_EXC_ERROR;
11296         END IF;
11297 
11298         --Bug Fix for Bug # 3088397
11299         IF l_contract_discount IS NOT NULL THEN
11300           --assign the contract discount to the out record
11301           x_charges_detail_rec.contract_discount_amount := x_charges_detail_rec.after_warranty_cost - l_contract_discount;
11302 
11303           --apply discount
11304           x_charges_detail_rec.after_warranty_cost :=  l_contract_discount;
11305         ELSE
11306           -- contract discount amt should be 0
11307           --x_charges_detail_rec.contract_discount_amount := 0;
11308           null;
11309         END IF;
11310 
11311        --DBMS_OUTPUT.PUT_LINE('Contract 1'||x_charges_detail_rec.contract_discount_amount);
11312 
11313 
11314       ELSE
11315         --Apply contract discount = 'N'
11316         --Fixed Bug # 3220253
11317         --passed p_charges_detail_rec.contract_discount_amount
11318         x_charges_detail_rec.apply_contract_discount  := p_charges_detail_rec.apply_contract_discount;
11319         x_charges_detail_rec.contract_discount_amount := p_charges_detail_rec.contract_discount_amount;
11320         IF x_charges_detail_rec.contract_discount_amount IS NULL THEN
11321           x_charges_detail_rec.contract_discount_amount := 0;
11322         ELSE
11323           x_charges_detail_rec.contract_discount_amount := x_charges_detail_rec.contract_discount_amount;
11324         END IF;
11325       END IF ;
11326 
11327   ELSIF
11328      --Fix # 3069583 unable to override charges for labor charge line
11329 
11330      --x_charges_detail_rec.billing_flag <> 'E' AND
11331      --x_charges_detail_rec.billing_flag <> 'M' OR
11332      x_charges_detail_rec.billing_flag IN ('E','M', 'L') AND
11333      p_charges_detail_rec.after_warranty_cost IS NULL AND
11334      p_charges_detail_rec.list_price IS NULL THEN
11335 
11336 
11337     IF ((((x_charges_detail_rec.inventory_item_id_in IS NOT NULL) AND
11338           (x_charges_detail_rec.unit_of_measure_code IS NOT NULL) AND
11339           (x_charges_detail_rec.price_list_id IS NOT NULL) AND
11340           (x_charges_detail_rec.quantity_required IS NOT NULL)))) THEN
11341 
11342       --DBMS_OUTPUT.PUT_LINE('Before calling CS_Pricing_Item_Pkg.Call_Pricing_Item ...');
11343       --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.inventory_item_id_in='||x_charges_detail_rec.inventory_item_id_in);
11344       --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.price_list_id='||x_charges_detail_rec.price_list_id);
11345       --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.unit_of_measure_code='||x_charges_detail_rec.unit_of_measure_code);
11346       --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.currency_code='||x_charges_detail_rec.currency_code);
11347       --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.quantity_required='||x_charges_detail_rec.quantity_required);
11348 
11349       -- Added to fix Bug # 3819167
11350       --
11351       /*
11352       IF ((l_line_order_category_code = 'RETURN') AND
11353           (sign(x_charges_detail_rec.quantity_required) = -1)) THEN
11354           l_absolute_quantity_required := x_charges_detail_rec.quantity_required * -1;
11355       ELSE
11356           l_absolute_quantity_required := x_charges_detail_rec.quantity_required;
11357       END IF;
11358       */
11359         -- Bug 7117553
11360       l_profile_value := fnd_profile.value('CS_SR_CHG_PRIC_DATE');
11361       If l_profile_value = 'CHG_INC_DATE' Then
11362         l_pricing_date := l_incident_date;
11363       Else
11364 	l_pricing_date := sysdate;
11365       End if;
11366       -- Bug 7117553
11367 
11368 
11369       -- Calculate the selling price
11370       CS_Pricing_Item_Pkg.Call_Pricing_Item(
11371             P_Inventory_Item_Id          => x_charges_detail_rec.inventory_item_id_in,
11372             P_Price_List_Id              => x_charges_detail_rec.price_list_id,
11373             P_UOM_Code                   => x_charges_detail_rec.unit_of_measure_code,
11374             p_Currency_Code              => x_charges_detail_rec.currency_code,
11375             P_Quantity                   => abs(x_charges_detail_rec.quantity_required),
11376 	    P_incident_date	         => l_pricing_date,   -- Bug 7117553
11377             P_Org_Id                     => x_charges_detail_rec.org_id,
11378             x_list_price                 => l_list_price,
11379             P_Pricing_Context            => x_charges_detail_rec.pricing_context,
11380             P_Pricing_Attribute1         => x_charges_detail_rec.pricing_attribute1,
11381             P_Pricing_Attribute2         => x_charges_detail_rec.pricing_attribute2,
11382             P_Pricing_Attribute3         => x_charges_detail_rec.pricing_attribute3,
11383             P_Pricing_Attribute4         => x_charges_detail_rec.pricing_attribute4,
11384             P_Pricing_Attribute5         => x_charges_detail_rec.pricing_attribute5,
11385             P_Pricing_Attribute6         => x_charges_detail_rec.pricing_attribute6,
11386             P_Pricing_Attribute7         => x_charges_detail_rec.pricing_attribute7,
11387             P_Pricing_Attribute8         => x_charges_detail_rec.pricing_attribute8,
11388             P_Pricing_Attribute9         => x_charges_detail_rec.pricing_attribute9,
11389             P_Pricing_Attribute10        => x_charges_detail_rec.pricing_attribute10,
11390             P_Pricing_Attribute11        => x_charges_detail_rec.pricing_attribute11,
11391             P_Pricing_Attribute12        => x_charges_detail_rec.pricing_attribute12,
11392             P_Pricing_Attribute13        => x_charges_detail_rec.pricing_attribute13,
11393             P_Pricing_Attribute14        => x_charges_detail_rec.pricing_attribute14,
11394             P_Pricing_Attribute15        => x_charges_detail_rec.pricing_attribute15,
11395             P_Pricing_Attribute16        => x_charges_detail_rec.pricing_attribute16,
11396             P_Pricing_Attribute17        => x_charges_detail_rec.pricing_attribute17,
11397             P_Pricing_Attribute18        => x_charges_detail_rec.pricing_attribute18,
11398             P_Pricing_Attribute19        => x_charges_detail_rec.pricing_attribute19,
11399             P_Pricing_Attribute20        => x_charges_detail_rec.pricing_attribute20,
11400             P_Pricing_Attribute21        => x_charges_detail_rec.pricing_attribute21,
11401             P_Pricing_Attribute22        => x_charges_detail_rec.pricing_attribute22,
11402             P_Pricing_Attribute23        => x_charges_detail_rec.pricing_attribute23,
11403             P_Pricing_Attribute24        => x_charges_detail_rec.pricing_attribute24,
11404             P_Pricing_Attribute25        => x_charges_detail_rec.pricing_attribute25,
11405             p_Pricing_Attribute26        => x_charges_detail_rec.pricing_attribute26,
11406             P_Pricing_Attribute27        => x_charges_detail_rec.pricing_attribute27,
11407             P_Pricing_Attribute28        => x_charges_detail_rec.pricing_attribute28,
11408             P_Pricing_Attribute29        => x_charges_detail_rec.pricing_attribute29,
11409             P_Pricing_Attribute30        => x_charges_detail_rec.pricing_attribute30,
11410             P_PRICING_ATTRIBUTE31        => x_charges_detail_rec.pricing_attribute31,
11411             P_PRICING_ATTRIBUTE32        => x_charges_detail_rec.pricing_attribute32,
11412             P_PRICING_ATTRIBUTE33        => x_charges_detail_rec.pricing_attribute33,
11413             P_PRICING_ATTRIBUTE34        => x_charges_detail_rec.pricing_attribute34,
11414             P_Pricing_Attribute35        => x_charges_detail_rec.pricing_attribute35,
11415             P_Pricing_Attribute36        => x_charges_detail_rec.pricing_attribute36,
11416             P_Pricing_Attribute37        => x_charges_detail_rec.pricing_attribute37,
11417             P_Pricing_Attribute38        => x_charges_detail_rec.pricing_attribute38,
11418             P_Pricing_Attribute39        => x_charges_detail_rec.pricing_attribute39,
11419             P_Pricing_Attribute40        => x_charges_detail_rec.pricing_attribute40,
11420             P_Pricing_Attribute41        => x_charges_detail_rec.pricing_attribute41,
11421             P_Pricing_Attribute42        => x_charges_detail_rec.pricing_attribute42,
11422             P_Pricing_Attribute43        => x_charges_detail_rec.pricing_attribute43,
11423             P_Pricing_Attribute44        => x_charges_detail_rec.pricing_attribute44,
11424             P_Pricing_Attribute45        => x_charges_detail_rec.pricing_attribute45,
11425             P_Pricing_Attribute46        => x_charges_detail_rec.pricing_attribute46,
11426             P_Pricing_Attribute47        => x_charges_detail_rec.pricing_attribute47,
11427             P_Pricing_Attribute48        => x_charges_detail_rec.pricing_attribute48,
11428             P_Pricing_Attribute49        => x_charges_detail_rec.pricing_attribute49,
11429             P_Pricing_Attribute50        => x_charges_detail_rec.pricing_attribute50,
11430             P_Pricing_Attribute51        => x_charges_detail_rec.pricing_attribute51,
11431             P_Pricing_Attribute52        => x_charges_detail_rec.pricing_attribute52,
11432             P_Pricing_Attribute53        => x_charges_detail_rec.pricing_attribute53,
11433             P_Pricing_Attribute54        => x_charges_detail_rec.pricing_attribute54,
11434             P_Pricing_Attribute55        => x_charges_detail_rec.pricing_attribute55,
11435             P_Pricing_Attribute56        => x_charges_detail_rec.pricing_attribute56,
11436             P_Pricing_Attribute57        => x_charges_detail_rec.pricing_attribute57,
11437             P_Pricing_Attribute58        => x_charges_detail_rec.pricing_attribute58,
11438             P_Pricing_Attribute59        => x_charges_detail_rec.pricing_attribute59,
11439             P_Pricing_Attribute60        => x_charges_detail_rec.pricing_attribute60,
11440             P_Pricing_Attribute61        => x_charges_detail_rec.pricing_attribute61,
11441             P_Pricing_Attribute62        => x_charges_detail_rec.pricing_attribute62,
11442             P_Pricing_Attribute63        => x_charges_detail_rec.pricing_attribute63,
11443             P_Pricing_Attribute64        => x_charges_detail_rec.pricing_attribute64,
11444             P_Pricing_Attribute65        => x_charges_detail_rec.pricing_attribute65,
11445             P_Pricing_Attribute66        => x_charges_detail_rec.pricing_attribute66,
11446             P_Pricing_Attribute67        => x_charges_detail_rec.pricing_attribute67,
11447             P_Pricing_Attribute68        => x_charges_detail_rec.pricing_attribute68,
11448             P_Pricing_Attribute69        => x_charges_detail_rec.pricing_attribute69,
11449             P_Pricing_Attribute70        => x_charges_detail_rec.pricing_attribute70,
11450             P_Pricing_Attribute71        => x_charges_detail_rec.pricing_attribute71,
11451             P_Pricing_Attribute72        => x_charges_detail_rec.pricing_attribute72,
11452             P_Pricing_Attribute73        => x_charges_detail_rec.pricing_attribute73,
11453             P_Pricing_Attribute74        => x_charges_detail_rec.pricing_attribute74,
11454             P_Pricing_Attribute75        => x_charges_detail_rec.pricing_attribute75,
11455             P_Pricing_Attribute76        => x_charges_detail_rec.pricing_attribute76,
11456             P_Pricing_Attribute77        => x_charges_detail_rec.pricing_attribute77,
11457             P_Pricing_Attribute78        => x_charges_detail_rec.pricing_attribute78,
11458             P_Pricing_Attribute79        => x_charges_detail_rec.pricing_attribute79,
11459             P_Pricing_Attribute80        => x_charges_detail_rec.pricing_attribute80,
11460             P_Pricing_Attribute81        => x_charges_detail_rec.pricing_attribute81,
11461             P_Pricing_Attribute82        => x_charges_detail_rec.pricing_attribute82,
11462             P_Pricing_Attribute83        => x_charges_detail_rec.pricing_attribute83,
11463             P_Pricing_Attribute84        => x_charges_detail_rec.pricing_attribute84,
11464             P_Pricing_Attribute85        => x_charges_detail_rec.pricing_attribute85,
11465             P_Pricing_Attribute86        => x_charges_detail_rec.pricing_attribute86,
11466             P_Pricing_Attribute87        => x_charges_detail_rec.pricing_attribute87,
11467             P_Pricing_Attribute88        => x_charges_detail_rec.pricing_attribute88,
11468             P_Pricing_Attribute89        => x_charges_detail_rec.pricing_attribute89,
11469             P_Pricing_Attribute90        => x_charges_detail_rec.pricing_attribute90,
11470             P_Pricing_Attribute91        => x_charges_detail_rec.pricing_attribute91,
11471             P_Pricing_Attribute92        => x_charges_detail_rec.pricing_attribute92,
11472             P_Pricing_Attribute93        => x_charges_detail_rec.pricing_attribute93,
11473             P_Pricing_Attribute94        => x_charges_detail_rec.pricing_attribute94,
11474             P_Pricing_Attribute95        => x_charges_detail_rec.pricing_attribute95,
11475             P_Pricing_Attribute96        => x_charges_detail_rec.pricing_attribute96,
11476             P_Pricing_Attribute97        => x_charges_detail_rec.pricing_attribute97,
11477             P_Pricing_Attribute98        => x_charges_detail_rec.pricing_attribute98,
11478             P_Pricing_Attribute99        => x_charges_detail_rec.pricing_attribute99,
11479             P_Pricing_Attribute100       => x_charges_detail_rec.pricing_attribute100,
11480             x_return_status              => l_return_status,
11481             x_msg_count                  => l_msg_count,
11482             x_msg_data                   => l_msg_data);
11483 
11484       --DBMS_OUTPUT.PUT_LINE('After calling CS_Pricing_Item_Pkg.Call_Pricing_Item ...');
11485       --DBMS_OUTPUT.PUT_LINE('l_msg_data '||l_msg_data);
11486 
11487       IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
11488         FND_MESSAGE.Set_Name('CS', 'CS_CHG_API_PRICING_ITEM_ERROR');
11489         FND_MESSAGE.set_token('INV_ID', x_charges_detail_rec.inventory_item_id_in);
11490         FND_MESSAGE.set_token('PRICE_LIST_ID', x_charges_detail_rec.price_list_id);
11491         FND_MESSAGE.set_token('UOM', x_charges_detail_rec.unit_of_measure_code);
11492         FND_MESSAGE.set_token('CURR_CODE', x_charges_detail_rec.currency_code);
11493         --FND_MESSAGE.SET_TOKEN('TEXT', l_msg_data, TRUE);
11494         FND_MSG_PUB.Add;
11495         RAISE FND_API.G_EXC_ERROR;
11496       END IF;
11497 
11498       --assign to out record
11499       x_charges_detail_rec.list_price    := l_list_price;
11500 
11501       --bug # 3056622 charge amount is zero for items with negative prices
11502 
11503       IF p_charges_detail_rec.selling_price IS NOT NULL THEN
11504         x_charges_detail_rec.selling_price :=  p_charges_detail_rec.selling_price;
11505       ELSE
11506         x_charges_detail_rec.selling_price := x_charges_detail_rec.list_price;
11507       END IF;
11508 
11509 
11510       IF x_charges_detail_rec.billing_flag = 'L' AND
11511          p_charges_detail_rec.con_pct_over_list_price IS NOT NULL THEN
11512 
11513          --get the new list price and selling price
11514          x_charges_detail_rec.list_price := x_charges_detail_rec.list_price +
11515                                                (x_charges_detail_rec.list_price *  p_charges_detail_rec.con_pct_over_list_price/100);
11516 
11517          x_charges_detail_rec.selling_price := x_charges_detail_rec.list_price;
11518       ELSE
11519          x_charges_detail_rec.list_price    := x_charges_detail_rec.list_price;
11520          x_charges_detail_rec.selling_price := x_charges_detail_rec.selling_price;
11521       END IF;
11522 
11523 
11524       --DBMS_OUTPUT.PUT_LINE('list_price '||x_charges_detail_rec.list_price);
11525       --DBMS_OUTPUT.PUT_LINE('Selling Price '||x_charges_detail_rec.selling_price);
11526       --DBMS_OUTPUT.PUT_LINE(' No Charge Flag is  '||x_charges_detail_rec.no_charge_flag);
11527       --DBMS_OUTPUT.PUT_LINE(' Conversion needed flag '||l_conversion_needed_flag);
11528 
11529       --bug # 3056622 charge amount is zero for items with negative prices
11530 
11531       IF x_charges_detail_rec.no_charge_flag <> 'Y' AND x_charges_detail_rec.selling_price IS NOT NULL THEN
11532         IF l_conversion_needed_flag = 'Y' THEN
11533           IF p_charges_detail_rec.selling_price IS NOT NULL THEN
11534             x_charges_detail_rec.selling_price := x_charges_detail_rec.selling_price * x_charges_detail_rec.conversion_rate;
11535             x_charges_detail_rec.after_warranty_cost := x_charges_detail_rec.selling_price * x_charges_detail_rec.quantity_required;
11536           ELSE
11537             x_charges_detail_rec.after_warranty_cost := x_charges_detail_rec.selling_price * x_charges_detail_rec.quantity_required * x_charges_detail_rec.conversion_rate;
11538           END IF;
11539         ELSE
11540           x_charges_detail_rec.after_warranty_cost := x_charges_detail_rec.selling_price * x_charges_detail_rec.quantity_required;
11541         END IF;
11542       ELSE
11543         -- no charge flag = 'Y'
11544         x_charges_detail_rec.after_warranty_cost := 0;
11545       END IF;
11546 
11547       --DBMS_OUTPUT.PUT_LINE(' after warr cost is '|| x_charges_detail_rec.after_warranty_cost);
11548 
11549 
11550       --check to see if contract discount needs to be applied
11551 
11552       --DBMS_OUTPUT.PUT_LINE('apply contract discount '|| x_charges_detail_rec.apply_contract_discount);
11553       --DBMS_OUTPUT.PUT_LINE('contract_id '||x_charges_detail_rec.contract_id);
11554       --DBMS_OUTPUT.PUT_LINE('coverage_id '||x_charges_detail_rec.coverage_id);
11555 
11556       IF x_charges_detail_rec.apply_contract_discount = 'Y' AND
11557          x_charges_detail_rec.no_charge_flag <> 'Y' AND
11558          x_charges_detail_rec.contract_line_id IS NOT NULL THEN
11559 
11560         --assign to out record
11561         x_charges_detail_rec.apply_contract_discount := p_charges_detail_rec.apply_contract_discount;
11562 
11563         --DBMS_OUTPUT.PUT_LINE('calling get_contract_line_id');
11564 
11565         --DBMS_OUTPUT.PUT_LINE('after calling get_contract_line_id');
11566         --call contracts dicounting API
11567         --DBMS_OUTPUT.PUT_LINE('Call Contracts API to Apply contracts 2');
11568 
11569         CS_Est_Apply_Contract_PKG.Apply_Contract(
11570           p_coverage_id           => x_charges_detail_rec.contract_line_id,
11571           p_coverage_txn_group_id => x_charges_detail_rec.coverage_txn_group_id,
11572           p_txn_billing_type_id   => x_charges_detail_rec.txn_billing_type_id,
11573           P_BUSINESS_PROCESS_ID   => x_charges_detail_rec.business_process_id,
11574           P_REQUEST_DATE          => l_request_date,
11575           p_amount                => x_charges_detail_rec.after_warranty_cost,
11576           p_discount_amount       => l_contract_discount,
11577           X_RETURN_STATUS         => l_return_status,
11578           X_MSG_COUNT             => l_msg_count,
11579           X_MSG_DATA              => l_msg_data);
11580 
11581         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
11582           FND_MESSAGE.Set_Name('CS', 'CS_CHG_APPLY_CONTRACT_WARNING');
11583           FND_MESSAGE.SET_TOKEN('REASON', l_msg_data);
11584           FND_MSG_PUB.Add;
11585           RAISE FND_API.G_EXC_ERROR;
11586         END IF;
11587 
11588         --Bug Fix for Bug # 3088397
11589         IF l_contract_discount IS NOT NULL THEN
11590           --assign the contract discount to the out record
11591           x_charges_detail_rec.contract_discount_amount := x_charges_detail_rec.after_warranty_cost - l_contract_discount;
11592 
11593           --apply discount
11594           x_charges_detail_rec.after_warranty_cost := l_contract_discount;
11595 
11596         ELSE
11597           -- contract discount amt should be 0
11598           --x_charges_detail_rec.contract_discount_amount := 0;
11599           null;
11600         END IF;
11601         --DBMS_OUTPUT.PUT_LINE('l_contract_discount'||l_contract_discount);
11602         --DBMS_OUTPUT.PUT_LINE('Contract 2'||x_charges_detail_rec.contract_discount_amount);
11603 
11604       ELSE
11605         --Apply contract discount = 'N'
11606         --Fixed Bug # 3220253
11607         --passed p_charges_detail_rec.contract_discount_amount
11608         x_charges_detail_rec.apply_contract_discount := p_charges_detail_rec.apply_contract_discount;
11609         x_charges_detail_rec.contract_discount_amount := p_charges_detail_rec.contract_discount_amount;
11610 
11611         IF x_charges_detail_rec.contract_discount_amount IS NULL THEN
11612           x_charges_detail_rec.contract_discount_amount := 0;
11613         ELSE
11614           x_charges_detail_rec.contract_discount_amount := x_charges_detail_rec.contract_discount_amount;
11615         END IF;
11616 
11617       END IF ;
11618 
11619 
11620     ELSE
11621       --x_charges_detail_rec.inventory_item_id_in IS NULL
11622       --x_charges_detail_rec.unit_of_measure_code IS NULL
11623       --x_charges_detail_rec.price_list_id IS NULL
11624       --x_charges_detail_rec.quantity_required IS NULL
11625       --the list price cannot be derived and the
11626       --after warranty cost cannot be computed
11627       --assign 0 to list_price and after_warranty_cost
11628       x_charges_detail_rec.list_price := 0;
11629       x_charges_detail_rec.selling_price := 0;
11630       x_charges_detail_rec.after_warranty_cost := 0;
11631       x_charges_detail_rec.contract_discount_amount := 0;
11632 
11633     END IF;
11634 
11635   --Added to fix bug # 3217757
11636   --debriefed expense line not displaying correct amount
11637 
11638   ELSIF x_charges_detail_rec.billing_flag = 'E' AND
11639         x_charges_detail_rec.source_code = 'SD' AND
11640         p_charges_detail_rec.after_warranty_cost IS NOT NULL THEN
11641         --DBMS_OUTPUT.PUT_LINE('Expense line with after warr cost ');
11642  /* Start Bug 6960562 */
11643     IF l_line_order_category_code = 'RETURN' THEN
11644         x_charges_detail_rec.after_warranty_cost := p_charges_detail_rec.after_warranty_cost * x_charges_detail_rec.quantity_required;
11645     ELSE
11646     -- Assign the after warranty that comes on the line
11647         x_charges_detail_rec.after_warranty_cost := p_charges_detail_rec.after_warranty_cost;
11648     END IF;
11649   /* End Bug 6960562 */
11650 
11651     x_charges_detail_rec.list_price := p_charges_detail_rec.after_warranty_cost;
11652 
11653     IF l_conversion_needed_flag = 'Y' THEN
11654       --assign coverted amt to after_list_price
11655       x_charges_detail_rec.list_price := x_charges_detail_rec.list_price * x_charges_detail_rec.conversion_rate;
11656 
11657       --bug # 3056600 charge amount is zero for items with negative prices
11658 
11659       IF p_charges_detail_rec.selling_price IS NOT NULL THEN
11660         x_charges_detail_rec.selling_price :=  p_charges_detail_rec.selling_price * x_charges_detail_rec.conversion_rate;
11661       ELSE
11662         x_charges_detail_rec.selling_price :=  x_charges_detail_rec.list_price;
11663       END IF;
11664 
11665       -- Fixed second issue in Bug 3468146
11666       -- If the line originates from SD and has a after_warranty_cost
11667       -- but the no_charge_flag = 'Y' then make after_warranty_cost = 0
11668 
11669       IF x_charges_detail_rec.no_charge_flag = 'Y' THEN
11670          x_charges_detail_rec.after_warranty_cost := 0;
11671       ELSE
11672          x_charges_detail_rec.after_warranty_cost := x_charges_detail_rec.after_warranty_cost * x_charges_detail_rec.conversion_rate;
11673       END IF;
11674 
11675     ELSE
11676       --l_conversion_needed_flag = 'N'
11677       --bug # 3056600 charge amount is zero for items with negative prices
11678       IF p_charges_detail_rec.selling_price IS NOT NULL THEN
11679         x_charges_detail_rec.selling_price :=  p_charges_detail_rec.selling_price;
11680       ELSE
11681         x_charges_detail_rec.selling_price :=  x_charges_detail_rec.list_price;
11682       END IF;
11683 
11684       -- Fixed second issue in Bug 3468146
11685       -- If the line originates from SD and has a after_warranty_cost
11686       -- but the no_charge_flag = 'Y' then make after_warranty_cost = 0
11687       IF x_charges_detail_rec.no_charge_flag = 'Y' THEN
11688          x_charges_detail_rec.after_warranty_cost := 0;
11689       END IF;
11690     END IF;
11691 
11692     --Fixed Bug # 3468146
11693     --need to do this here so that contract discounting is done correctly
11694     --re-set the no_charge_flag for Charge Lines
11695     --since the line has come with after warranty cost from upstream
11696     IF x_charges_detail_rec.after_warranty_cost <> 0 THEN
11697       x_charges_detail_rec.no_charge_flag := 'N';
11698     END IF;
11699 
11700 
11701     --DBMS_OUTPUT.PUT_LINE('re-setting the no_charge_flag' ||x_charges_detail_rec.no_charge_flag);
11702 
11703     IF x_charges_detail_rec.apply_contract_discount = 'Y' AND
11704        x_charges_detail_rec.no_charge_flag <> 'Y' AND
11705        x_charges_detail_rec.contract_line_id IS NOT NULL THEN
11706 
11707          --call contracts dicounting API
11708          CS_Est_Apply_Contract_PKG.Apply_Contract (
11709             p_coverage_id           => x_charges_detail_rec.contract_line_id,
11710             p_coverage_txn_group_id => x_charges_detail_rec.coverage_txn_group_id,
11711             p_business_process_id   => x_charges_detail_rec.business_process_id,
11712             p_request_date          => l_request_date,
11713             p_txn_billing_type_id   => x_charges_detail_rec.txn_billing_type_id,
11714             p_amount                => x_charges_detail_rec.after_warranty_cost,
11715             p_discount_amount       => l_contract_discount,
11716             X_RETURN_STATUS         => l_return_status,
11717             X_MSG_COUNT             => l_msg_count,
11718             X_MSG_DATA              => l_msg_data);
11719 
11720         IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
11721           FND_MESSAGE.Set_Name('CS', 'CS_CHG_APPLY_CONTRACT_WARNING');
11722           FND_MESSAGE.SET_TOKEN('REASON', l_msg_data);
11723           FND_MSG_PUB.Add;
11724           RAISE FND_API.G_EXC_ERROR;
11725         END IF;
11726 
11727          IF l_contract_discount IS NOT NULL THEN
11728           --assign the contract discount to the out record
11729           x_charges_detail_rec.contract_discount_amount := x_charges_detail_rec.after_warranty_cost - l_contract_discount;
11730 
11731           --apply discount
11732           x_charges_detail_rec.after_warranty_cost := l_contract_discount;
11733 
11734         ELSE
11735           -- contract discount amt should be 0
11736           --x_charges_detail_rec.contract_discount_amount := 0;
11737           null;
11738         END IF;
11739 
11740     ELSE
11741       --Apply contract discount = 'N'
11742       --Fixed Bug # 3220253
11743       --passed p_charges_detail_rec.contract_discount_amount
11744       x_charges_detail_rec.apply_contract_discount := p_charges_detail_rec.apply_contract_discount;
11745       x_charges_detail_rec.contract_discount_amount := p_charges_detail_rec.contract_discount_amount;
11746 
11747       IF x_charges_detail_rec.contract_discount_amount IS NULL THEN
11748           x_charges_detail_rec.contract_discount_amount := 0;
11749       ELSE
11750           x_charges_detail_rec.contract_discount_amount := x_charges_detail_rec.contract_discount_amount;
11751       END IF;
11752     END IF ;
11753 
11754 
11755   ELSIF
11756         --Fix # 3069583 unable to override charges for labor charge line
11757         x_charges_detail_rec.billing_flag IN ('E', 'M', 'L') AND
11758         p_charges_detail_rec.after_warranty_cost IS NOT NULL THEN
11759 
11760         --DBMS_OUTPUT.PUT_LINE('Expense line with after warr cost ');
11761         --DBMS_OUTPUT.PUT_LINE('l_conversion_needed_flag '||l_conversion_needed_flag);
11762         --DBMS_OUTPUT.PUT_LINE('after_warranty_cost = '||p_charges_detail_rec.after_warranty_cost );
11763 
11764         -- Added to fix Bug # 3819167
11765         --
11766         /*
11767         IF ((l_line_order_category_code = 'RETURN') AND
11768           (sign(x_charges_detail_rec.quantity_required) = -1)) THEN
11769           l_absolute_quantity_required := x_charges_detail_rec.quantity_required * -1;
11770         ELSE
11771           l_absolute_quantity_required := x_charges_detail_rec.quantity_required;
11772         END IF;
11773         */
11774 
11775         -- Call the pricing API just to verify that the item is on the price list
11776         CS_Pricing_Item_Pkg.Call_Pricing_Item(
11777             P_Inventory_Item_Id          => x_charges_detail_rec.inventory_item_id_in,
11778             P_Price_List_Id              => x_charges_detail_rec.price_list_id,
11779             P_UOM_Code                   => x_charges_detail_rec.unit_of_measure_code,
11780             p_Currency_Code              => x_charges_detail_rec.currency_code,
11781             P_Quantity                   => abs(x_charges_detail_rec.quantity_required),
11782             P_Org_Id                     => x_charges_detail_rec.org_id,
11783             x_list_price                 => l_list_price,
11784             P_Pricing_Context            => x_charges_detail_rec.pricing_context,
11785             P_Pricing_Attribute1         => x_charges_detail_rec.pricing_attribute1,
11786             P_Pricing_Attribute2         => x_charges_detail_rec.pricing_attribute2,
11787             P_Pricing_Attribute3         => x_charges_detail_rec.pricing_attribute3,
11788             P_Pricing_Attribute4         => x_charges_detail_rec.pricing_attribute4,
11789             P_Pricing_Attribute5         => x_charges_detail_rec.pricing_attribute5,
11790             P_Pricing_Attribute6         => x_charges_detail_rec.pricing_attribute6,
11791             P_Pricing_Attribute7         => x_charges_detail_rec.pricing_attribute7,
11792             P_Pricing_Attribute8         => x_charges_detail_rec.pricing_attribute8,
11793             P_Pricing_Attribute9         => x_charges_detail_rec.pricing_attribute9,
11794             P_Pricing_Attribute10        => x_charges_detail_rec.pricing_attribute10,
11795             P_Pricing_Attribute11        => x_charges_detail_rec.pricing_attribute11,
11796             P_Pricing_Attribute12        => x_charges_detail_rec.pricing_attribute12,
11797             P_Pricing_Attribute13        => x_charges_detail_rec.pricing_attribute13,
11798             P_Pricing_Attribute14        => x_charges_detail_rec.pricing_attribute14,
11799             P_Pricing_Attribute15        => x_charges_detail_rec.pricing_attribute15,
11800             P_Pricing_Attribute16        => x_charges_detail_rec.pricing_attribute16,
11801             P_Pricing_Attribute17        => x_charges_detail_rec.pricing_attribute17,
11802             P_Pricing_Attribute18        => x_charges_detail_rec.pricing_attribute18,
11803             P_Pricing_Attribute19        => x_charges_detail_rec.pricing_attribute19,
11804             P_Pricing_Attribute20        => x_charges_detail_rec.pricing_attribute20,
11805             P_Pricing_Attribute21        => x_charges_detail_rec.pricing_attribute21,
11806             P_Pricing_Attribute22        => x_charges_detail_rec.pricing_attribute22,
11807             P_Pricing_Attribute23        => x_charges_detail_rec.pricing_attribute23,
11808             P_Pricing_Attribute24        => x_charges_detail_rec.pricing_attribute24,
11809             P_Pricing_Attribute25        => x_charges_detail_rec.pricing_attribute25,
11810             p_Pricing_Attribute26        => x_charges_detail_rec.pricing_attribute26,
11811             P_Pricing_Attribute27        => x_charges_detail_rec.pricing_attribute27,
11812             P_Pricing_Attribute28        => x_charges_detail_rec.pricing_attribute28,
11813             P_Pricing_Attribute29        => x_charges_detail_rec.pricing_attribute29,
11814             P_Pricing_Attribute30        => x_charges_detail_rec.pricing_attribute30,
11815             P_PRICING_ATTRIBUTE31        => x_charges_detail_rec.pricing_attribute31,
11816             P_PRICING_ATTRIBUTE32        => x_charges_detail_rec.pricing_attribute32,
11817             P_PRICING_ATTRIBUTE33        => x_charges_detail_rec.pricing_attribute33,
11818             P_PRICING_ATTRIBUTE34        => x_charges_detail_rec.pricing_attribute34,
11819             P_Pricing_Attribute35        => x_charges_detail_rec.pricing_attribute35,
11820             P_Pricing_Attribute36        => x_charges_detail_rec.pricing_attribute36,
11821             P_Pricing_Attribute37        => x_charges_detail_rec.pricing_attribute37,
11822             P_Pricing_Attribute38        => x_charges_detail_rec.pricing_attribute38,
11823             P_Pricing_Attribute39        => x_charges_detail_rec.pricing_attribute39,
11824             P_Pricing_Attribute40        => x_charges_detail_rec.pricing_attribute40,
11825             P_Pricing_Attribute41        => x_charges_detail_rec.pricing_attribute41,
11826             P_Pricing_Attribute42        => x_charges_detail_rec.pricing_attribute42,
11827             P_Pricing_Attribute43        => x_charges_detail_rec.pricing_attribute43,
11828             P_Pricing_Attribute44        => x_charges_detail_rec.pricing_attribute44,
11829             P_Pricing_Attribute45        => x_charges_detail_rec.pricing_attribute45,
11830             P_Pricing_Attribute46        => x_charges_detail_rec.pricing_attribute46,
11831             P_Pricing_Attribute47        => x_charges_detail_rec.pricing_attribute47,
11832             P_Pricing_Attribute48        => x_charges_detail_rec.pricing_attribute48,
11833             P_Pricing_Attribute49        => x_charges_detail_rec.pricing_attribute49,
11834             P_Pricing_Attribute50        => x_charges_detail_rec.pricing_attribute50,
11835             P_Pricing_Attribute51        => x_charges_detail_rec.pricing_attribute51,
11836             P_Pricing_Attribute52        => x_charges_detail_rec.pricing_attribute52,
11837             P_Pricing_Attribute53        => x_charges_detail_rec.pricing_attribute53,
11838             P_Pricing_Attribute54        => x_charges_detail_rec.pricing_attribute54,
11839             P_Pricing_Attribute55        => x_charges_detail_rec.pricing_attribute55,
11840             P_Pricing_Attribute56        => x_charges_detail_rec.pricing_attribute56,
11841             P_Pricing_Attribute57        => x_charges_detail_rec.pricing_attribute57,
11842             P_Pricing_Attribute58        => x_charges_detail_rec.pricing_attribute58,
11843             P_Pricing_Attribute59        => x_charges_detail_rec.pricing_attribute59,
11844             P_Pricing_Attribute60        => x_charges_detail_rec.pricing_attribute60,
11845             P_Pricing_Attribute61        => x_charges_detail_rec.pricing_attribute61,
11846             P_Pricing_Attribute62        => x_charges_detail_rec.pricing_attribute62,
11847             P_Pricing_Attribute63        => x_charges_detail_rec.pricing_attribute63,
11848             P_Pricing_Attribute64        => x_charges_detail_rec.pricing_attribute64,
11849             P_Pricing_Attribute65        => x_charges_detail_rec.pricing_attribute65,
11850             P_Pricing_Attribute66        => x_charges_detail_rec.pricing_attribute66,
11851             P_Pricing_Attribute67        => x_charges_detail_rec.pricing_attribute67,
11852             P_Pricing_Attribute68        => x_charges_detail_rec.pricing_attribute68,
11853             P_Pricing_Attribute69        => x_charges_detail_rec.pricing_attribute69,
11854             P_Pricing_Attribute70        => x_charges_detail_rec.pricing_attribute70,
11855             P_Pricing_Attribute71        => x_charges_detail_rec.pricing_attribute71,
11856             P_Pricing_Attribute72        => x_charges_detail_rec.pricing_attribute72,
11857             P_Pricing_Attribute73        => x_charges_detail_rec.pricing_attribute73,
11858             P_Pricing_Attribute74        => x_charges_detail_rec.pricing_attribute74,
11859             P_Pricing_Attribute75        => x_charges_detail_rec.pricing_attribute75,
11860             P_Pricing_Attribute76        => x_charges_detail_rec.pricing_attribute76,
11861             P_Pricing_Attribute77        => x_charges_detail_rec.pricing_attribute77,
11862             P_Pricing_Attribute78        => x_charges_detail_rec.pricing_attribute78,
11863             P_Pricing_Attribute79        => x_charges_detail_rec.pricing_attribute79,
11864             P_Pricing_Attribute80        => x_charges_detail_rec.pricing_attribute80,
11865             P_Pricing_Attribute81        => x_charges_detail_rec.pricing_attribute81,
11866             P_Pricing_Attribute82        => x_charges_detail_rec.pricing_attribute82,
11867             P_Pricing_Attribute83        => x_charges_detail_rec.pricing_attribute83,
11868             P_Pricing_Attribute84        => x_charges_detail_rec.pricing_attribute84,
11869             P_Pricing_Attribute85        => x_charges_detail_rec.pricing_attribute85,
11870             P_Pricing_Attribute86        => x_charges_detail_rec.pricing_attribute86,
11871             P_Pricing_Attribute87        => x_charges_detail_rec.pricing_attribute87,
11872             P_Pricing_Attribute88        => x_charges_detail_rec.pricing_attribute88,
11873             P_Pricing_Attribute89        => x_charges_detail_rec.pricing_attribute89,
11874             P_Pricing_Attribute90        => x_charges_detail_rec.pricing_attribute90,
11875             P_Pricing_Attribute91        => x_charges_detail_rec.pricing_attribute91,
11876             P_Pricing_Attribute92        => x_charges_detail_rec.pricing_attribute92,
11877             P_Pricing_Attribute93        => x_charges_detail_rec.pricing_attribute93,
11878             P_Pricing_Attribute94        => x_charges_detail_rec.pricing_attribute94,
11879             P_Pricing_Attribute95        => x_charges_detail_rec.pricing_attribute95,
11880             P_Pricing_Attribute96        => x_charges_detail_rec.pricing_attribute96,
11881             P_Pricing_Attribute97        => x_charges_detail_rec.pricing_attribute97,
11882             P_Pricing_Attribute98        => x_charges_detail_rec.pricing_attribute98,
11883             P_Pricing_Attribute99        => x_charges_detail_rec.pricing_attribute99,
11884             P_Pricing_Attribute100       => x_charges_detail_rec.pricing_attribute100,
11885             x_return_status              => l_return_status,
11886             x_msg_count                  => l_msg_count,
11887             x_msg_data                   => l_msg_data);
11888 
11889       --DBMS_OUTPUT.PUT_LINE('After calling CS_Pricing_Item_Pkg.Call_Pricing_Item ...');
11890       --DBMS_OUTPUT.PUT_LINE('l_msg_data '||l_msg_data);
11891 
11892       IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
11893         FND_MESSAGE.Set_Name('CS', 'CS_CHG_API_PRICING_ITEM_ERROR');
11894         FND_MESSAGE.set_token('INV_ID', x_charges_detail_rec.inventory_item_id_in);
11895         FND_MESSAGE.set_token('PRICE_LIST_ID', x_charges_detail_rec.price_list_id);
11896         FND_MESSAGE.set_token('UOM', x_charges_detail_rec.unit_of_measure_code);
11897         FND_MESSAGE.set_token('CURR_CODE', x_charges_detail_rec.currency_code);
11898         --FND_MESSAGE.SET_TOKEN('TEXT', l_msg_data, TRUE);
11899         FND_MSG_PUB.Add;
11900         RAISE FND_API.G_EXC_ERROR;
11901       END IF;
11902 
11903 
11904 
11905       -- Assign the after warranty that comes on the line
11906         x_charges_detail_rec.after_warranty_cost := p_charges_detail_rec.after_warranty_cost;
11907 
11908     IF l_conversion_needed_flag = 'Y' THEN
11909       --assign coverted amt to after_warranty_cost
11910       x_charges_detail_rec.after_warranty_cost := x_charges_detail_rec.after_warranty_cost * x_charges_detail_rec.conversion_rate;
11911       x_charges_detail_rec.list_price := l_list_price;
11912 
11913       --bug # 3056622 charge amount is zero for items with negative prices
11914 
11915       IF p_charges_detail_rec.selling_price IS NOT NULL THEN
11916         x_charges_detail_rec.selling_price :=  p_charges_detail_rec.selling_price * x_charges_detail_rec.conversion_rate;
11917       ELSE
11918         x_charges_detail_rec.selling_price :=  x_charges_detail_rec.list_price;
11919       END IF;
11920 
11921     ELSE
11922       x_charges_detail_rec.after_warranty_cost := p_charges_detail_rec.after_warranty_cost;
11923       x_charges_detail_rec.list_price := l_list_price;
11924 
11925       --bug # 3056622 charge amount is zero for items with negative prices
11926 
11927       IF p_charges_detail_rec.selling_price IS NOT NULL THEN
11928         x_charges_detail_rec.selling_price :=  p_charges_detail_rec.selling_price;
11929       ELSE
11930         x_charges_detail_rec.selling_price :=  x_charges_detail_rec.list_price;
11931       END IF;
11932 
11933     END IF;
11934 
11935     --DBMS_OUTPUT.PUT_LINE(' after_warranty_cost '||x_charges_detail_rec.after_warranty_cost );
11936 
11937     --Fixed Bug # 3468146
11938     --need to do this here so that contract discounting is done correctly
11939     --re-set the no_charge_flag for Charge Lines
11940     --since the line has come with after warranty cost from upstream
11941     IF x_charges_detail_rec.after_warranty_cost <> 0 THEN
11942       x_charges_detail_rec.no_charge_flag := 'N';
11943     END IF;
11944 
11945 
11946     --DBMS_OUTPUT.PUT_LINE('re-setting the no_charge_flag' ||x_charges_detail_rec.no_charge_flag);
11947 
11948 
11949     IF x_charges_detail_rec.apply_contract_discount = 'Y' AND
11950        x_charges_detail_rec.no_charge_flag <> 'Y' AND
11951        x_charges_detail_rec.contract_line_id IS NOT NULL THEN
11952 
11953       --call contracts dicounting API
11954       CS_Est_Apply_Contract_PKG.Apply_Contract (
11955             p_coverage_id           => x_charges_detail_rec.contract_line_id,
11956             p_coverage_txn_group_id => x_charges_detail_rec.coverage_txn_group_id,
11957             p_business_process_id   => x_charges_detail_rec.business_process_id,
11958             p_request_date          => l_request_date,
11959             p_txn_billing_type_id   => x_charges_detail_rec.txn_billing_type_id,
11960             p_amount                => x_charges_detail_rec.after_warranty_cost,
11961             p_discount_amount       => l_contract_discount,
11962             X_RETURN_STATUS         => l_return_status,
11963             X_MSG_COUNT             => l_msg_count,
11964             X_MSG_DATA              => l_msg_data);
11965 
11966       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
11967         FND_MESSAGE.Set_Name('CS', 'CS_CHG_APPLY_CONTRACT_WARNING');
11968         FND_MESSAGE.SET_TOKEN('REASON', l_msg_data);
11969         FND_MSG_PUB.Add;
11970         RAISE FND_API.G_EXC_ERROR;
11971       END IF;
11972 
11973       --Bug Fix for Bug # 3088397
11974       IF l_contract_discount IS NOT NULL THEN
11975         --assign the contract discount to the out record
11976         x_charges_detail_rec.contract_discount_amount := x_charges_detail_rec.after_warranty_cost - l_contract_discount;
11977 
11978         --apply discount
11979         x_charges_detail_rec.after_warranty_cost := l_contract_discount;
11980 
11981        ELSE
11982           -- contract discount amt should be 0
11983           --x_charges_detail_rec.contract_discount_amount := 0;
11984           null;
11985       END IF;
11986 
11987     ELSE
11988       --Apply contract discount = 'N'
11989       --Fixed Bug # 3220253
11990       --passed p_charges_detail_rec.contract_discount_amount
11991       x_charges_detail_rec.apply_contract_discount := p_charges_detail_rec.apply_contract_discount;
11992       x_charges_detail_rec.contract_discount_amount := p_charges_detail_rec.contract_discount_amount;
11993 
11994       IF x_charges_detail_rec.contract_discount_amount IS NULL THEN
11995           x_charges_detail_rec.contract_discount_amount := 0;
11996       ELSE
11997           x_charges_detail_rec.contract_discount_amount := x_charges_detail_rec.contract_discount_amount;
11998       END IF;
11999     END IF ;
12000   END IF;
12001   IF   l_line_order_category_code = 'ORDER' THEN      --Bug 6960562
12002       /* Start : 5705568 */
12003 --      If x_charges_detail_rec.after_warranty_cost < 0  Then
12004       If x_charges_detail_rec.after_warranty_cost < 0  and x_charges_detail_rec.line_category_code <> 'RETURN' Then  -- bug 7459205
12005           x_charges_detail_rec.after_warranty_cost := 0;
12006       End If;
12007      /* End : 5705568 */
12008   End If;
12009 ELSIF p_validation_mode = 'U' THEN
12010 
12011   --DBMS_OUTPUT.PUT_LINE('In Update of Pricing API');
12012   --DBMS_OUTPUT.PUT_LINE('Billing Flag '||x_charges_detail_rec.billing_flag);
12013   --DBMS_OUTPUT.PUT_LINE('AFter_warranty_cost '||p_charges_detail_rec.after_warranty_cost);
12014   --DBMS_OUTPUT.PUT_LINE('selling price '||p_charges_detail_rec.selling_price);
12015 
12016   IF x_charges_detail_rec.billing_flag = 'L' AND
12017      p_charges_detail_rec.list_price <> FND_API.G_MISS_NUM AND
12018      p_charges_detail_rec.list_price IS NOT NULL THEN
12019 
12020     IF p_charges_detail_rec.list_price <> l_db_det_rec.list_price THEN
12021 
12022        l_calc_sp := 'Y';
12023 
12024 
12025        -- no need to call the pricing api
12026        -- assign to out record
12027        x_charges_detail_rec.list_price    := p_charges_detail_rec.list_price;
12028 
12029        x_charges_detail_rec.selling_price := p_charges_detail_rec.list_price;
12030 
12031        --bug # 3056622 charge amount is zero for items with negative prices
12032 
12033        --derive the after_warranty_cost
12034        IF x_charges_detail_rec.no_charge_flag <> 'Y' AND
12035           x_charges_detail_rec.selling_price IS NOT NULL THEN
12036 
12037           --Fix for Bug # 3388373
12038           IF p_charges_detail_rec.after_warranty_cost IS NOT NULL THEN
12039 
12040             x_charges_detail_rec.after_warranty_cost := p_charges_detail_rec.after_warranty_cost;
12041             l_calc_sp := 'N';
12042           ELSIF p_charges_detail_rec.after_warranty_cost = FND_API.G_MISS_NUM THEN
12043             x_charges_detail_rec.after_warranty_cost := l_db_det_rec.after_warranty_cost;
12044             l_calc_sp := 'N';
12045           ELSE
12046             --after warr cost is null
12047             x_charges_detail_rec.after_warranty_cost := x_charges_detail_rec.selling_price * x_charges_detail_rec.quantity_required;
12048           END IF;
12049 
12050        ELSE
12051           -- no charge flag = 'Y'
12052           x_charges_detail_rec.after_warranty_cost := 0;
12053        END IF;
12054 
12055        --check to see if contract discount needs to be applied
12056        IF x_charges_detail_rec.apply_contract_discount = 'Y' AND
12057           x_charges_detail_rec.no_charge_flag <> 'Y' AND
12058           x_charges_detail_rec.contract_line_id IS NOT NULL THEN
12059 
12060           --assign to out record
12061           x_charges_detail_rec.apply_contract_discount := p_charges_detail_rec.apply_contract_discount;
12062 
12063           --call contracts dicounting API
12064           --DBMS_OUTPUT.PUT_LINE('Call Contracts API to Apply contracts 3');
12065 
12066          CS_Est_Apply_Contract_PKG.Apply_Contract(
12067            p_coverage_id           => x_charges_detail_rec.contract_line_id,
12068            p_coverage_txn_group_id => x_charges_detail_rec.coverage_txn_group_id,
12069            p_txn_billing_type_id   => x_charges_detail_rec.txn_billing_type_id,
12070            P_BUSINESS_PROCESS_ID   => x_charges_detail_rec.business_process_id,
12071            P_REQUEST_DATE          => l_request_date,
12072            p_amount                => x_charges_detail_rec.after_warranty_cost,
12073            p_discount_amount       => l_contract_discount,
12074            X_RETURN_STATUS         => l_return_status,
12075            X_MSG_COUNT             => l_msg_count,
12076            X_MSG_DATA              => l_msg_data);
12077 
12078           IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
12079             FND_MESSAGE.Set_Name('CS', 'CS_CHG_APPLY_CONTRACT_WARNING');
12080             FND_MESSAGE.SET_TOKEN('REASON', l_msg_data);
12081             FND_MSG_PUB.Add;
12082             RAISE FND_API.G_EXC_ERROR;
12083           END IF;
12084 
12085           --Bug Fix for Bug # 3088397
12086           IF l_contract_discount IS NOT NULL THEN
12087             --assign the contract discount to the out record
12088             x_charges_detail_rec.contract_discount_amount := x_charges_detail_rec.after_warranty_cost - l_contract_discount;
12089 
12090             --apply discount
12091             x_charges_detail_rec.after_warranty_cost := l_contract_discount;
12092           ELSE
12093             -- contract discount amt should be 0
12094             --x_charges_detail_rec.contract_discount_amount := 0;
12095             null;
12096           END IF;
12097 
12098           --DBMS_OUTPUT.PUT_LINE('Contract 3'||x_charges_detail_rec.contract_discount_amount);
12099 
12100       ELSE
12101         --Apply contract discount = 'N'
12102         --Fixed Bug # 3220253
12103         --passed p_charges_detail_rec.contract_discount_amount
12104         x_charges_detail_rec.apply_contract_discount := p_charges_detail_rec.apply_contract_discount;
12105         x_charges_detail_rec.contract_discount_amount := p_charges_detail_rec.contract_discount_amount;
12106 
12107         IF x_charges_detail_rec.contract_discount_amount IS NULL THEN
12108           x_charges_detail_rec.contract_discount_amount := 0;
12109         ELSE
12110           x_charges_detail_rec.contract_discount_amount := x_charges_detail_rec.contract_discount_amount;
12111         END IF;
12112 
12113       END IF ;
12114     ELSE
12115        --p_charges_detail_rec.list_price = l_db_det_rec.list_price
12116 
12117        -- no need to call the pricing api
12118        -- assign to out record what is the dbatabase
12119        x_charges_detail_rec.list_price    := l_db_det_rec.list_price;
12120        x_charges_detail_rec.selling_price := l_db_det_rec.list_price;
12121 
12122        --bug # 3056622 charge amount is zero for items with negative prices
12123         --derive the after_warranty_cost
12124        IF x_charges_detail_rec.no_charge_flag <> 'Y' THEN
12125           --Condition added to fix Bug # 3358531
12126           x_charges_detail_rec.after_warranty_cost := l_db_det_rec.after_warranty_cost;
12127        ELSE
12128           -- no charge flag = 'Y'
12129           x_charges_detail_rec.after_warranty_cost := 0;
12130        END IF;
12131 
12132 
12133       --check to see if contract discount needs to be applied
12134       IF x_charges_detail_rec.apply_contract_discount = 'Y' AND
12135          x_charges_detail_rec.contract_line_id IS NOT NULL AND
12136          x_charges_detail_rec.no_charge_flag <> 'Y' THEN
12137 
12138           --assign to out record
12139           x_charges_detail_rec.apply_contract_discount := p_charges_detail_rec.apply_contract_discount;
12140 
12141           --call contracts dicounting API
12142           --DBMS_OUTPUT.PUT_LINE('Call Contracts API to Apply contracts 4');
12143 
12144           CS_Est_Apply_Contract_PKG.Apply_Contract(
12145             p_coverage_id           => x_charges_detail_rec.apply_contract_discount,
12146             p_coverage_txn_group_id => x_charges_detail_rec.coverage_txn_group_id,
12147             p_txn_billing_type_id   => x_charges_detail_rec.txn_billing_type_id,
12148             P_BUSINESS_PROCESS_ID   => x_charges_detail_rec.business_process_id,
12149             P_REQUEST_DATE          => l_request_date,
12150             p_amount                => x_charges_detail_rec.after_warranty_cost,
12151             p_discount_amount       => l_contract_discount,
12152             X_RETURN_STATUS         => l_return_status,
12153             X_MSG_COUNT             => l_msg_count,
12154             X_MSG_DATA              => l_msg_data);
12155 
12156           IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
12157             FND_MESSAGE.Set_Name('CS', 'CS_CHG_APPLY_CONTRACT_WARNING');
12158             FND_MESSAGE.SET_TOKEN('REASON', l_msg_data);
12159             FND_MSG_PUB.Add;
12160             RAISE FND_API.G_EXC_ERROR;
12161           END IF;
12162 
12163           --Bug Fix for Bug # 3088397
12164           IF l_contract_discount IS NOT NULL THEN
12165             --assign the contract discount to the out record
12166             x_charges_detail_rec.contract_discount_amount := x_charges_detail_rec.after_warranty_cost - l_contract_discount;
12167 
12168             --apply discount
12169             x_charges_detail_rec.after_warranty_cost := l_contract_discount;
12170           ELSE
12171             -- contract discount amt should be 0
12172             --x_charges_detail_rec.contract_discount_amount := 0;
12173             null;
12174           END IF;
12175 
12176           --DBMS_OUTPUT.PUT_LINE('Contract 4'||x_charges_detail_rec.contract_discount_amount);
12177 
12178       ELSE
12179         --Apply contract discount = 'N'
12180         --Fixed Bug # 3220253
12181         --passed p_charges_detail_rec.contract_discount_amount
12182         x_charges_detail_rec.apply_contract_discount := p_charges_detail_rec.apply_contract_discount;
12183 
12184         IF p_charges_detail_rec.contract_discount_amount <> FND_API.G_MISS_NUM OR
12185            p_charges_detail_rec.contract_discount_amount IS NOT NULL THEN
12186            x_charges_detail_rec.contract_discount_amount := l_db_rec.contract_discount_amount;
12187         ELSIF p_charges_detail_rec.contract_discount_amount IS NULL THEN
12188            x_charges_detail_rec.contract_discount_amount := 0;
12189         ELSE
12190           x_charges_detail_rec.contract_discount_amount := p_charges_detail_rec.contract_discount_amount;
12191         END IF;
12192 
12193       END IF ;
12194     END IF;
12195 
12196   ELSIF
12197 
12198      --Fix # 3069583 unable to override charges for labor charge line
12199      --x_charges_detail_rec.billing_flag <> 'E' AND
12200      --x_charges_detail_rec.billing_flag <> 'M' OR
12201      (x_charges_detail_rec.billing_flag IN ('E','M', 'L') AND
12202      ((p_charges_detail_rec.after_warranty_cost = FND_API.G_MISS_NUM OR
12203      p_charges_detail_rec.after_warranty_cost IS NULL) AND
12204      (p_charges_detail_rec.list_price = FND_API.G_MISS_NUM OR
12205      p_charges_detail_rec.list_price IS NULL))) THEN
12206 
12207 
12208      IF l_calc_sp = 'Y' THEN
12209        IF ((((x_charges_detail_rec.inventory_item_id_in IS NOT NULL) AND
12210              (x_charges_detail_rec.unit_of_measure_code IS NOT NULL) AND
12211              (x_charges_detail_rec.price_list_id IS NOT NULL) AND
12212              (x_charges_detail_rec.quantity_required IS NOT NULL)))) THEN
12213           --DBMS_OUTPUT.PUT_LINE('Before calling CS_Pricing_Item_Pkg.Call_Pricing_Item ...');
12214           --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.inventory_item_id_in='||x_charges_detail_rec.inventory_item_id_in);
12215           --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.price_list_id='||x_charges_detail_rec.price_list_id);
12216           --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.unit_of_measure_code='||x_charges_detail_rec.unit_of_measure_code);
12217           --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.currency_code='||x_charges_detail_rec.currency_code);
12218           --DBMS_OUTPUT.PUT_LINE('x_charges_detail_rec.quantity_required='||x_charges_detail_rec.quantity_required);
12219 
12220           -- Added to fix Bug # 3819167
12221           --
12222           /*
12223           IF ((l_line_order_category_code = 'RETURN') AND
12224               (sign(x_charges_detail_rec.quantity_required) = -1)) THEN
12225              l_absolute_quantity_required := x_charges_detail_rec.quantity_required * -1;
12226           ELSE
12227              l_absolute_quantity_required := x_charges_detail_rec.quantity_required;
12228           END IF;
12229           */
12230 
12231           -- Calculate the selling price
12232           CS_Pricing_Item_Pkg.Call_Pricing_Item(
12233             P_Inventory_Item_Id          => x_charges_detail_rec.inventory_item_id_in,
12234             P_Price_List_Id              => x_charges_detail_rec.price_list_id,
12235             P_UOM_Code                   => x_charges_detail_rec.unit_of_measure_code,
12236             p_Currency_Code              => x_charges_detail_rec.currency_code,
12237             P_Quantity                   => abs(x_charges_detail_rec.quantity_required),
12238             P_Org_Id                     => x_charges_detail_rec.org_id,
12239             x_list_price                 => l_list_price,
12240             P_Pricing_Context            => x_charges_detail_rec.pricing_context,
12241             P_Pricing_Attribute1         => x_charges_detail_rec.pricing_attribute1,
12242             P_Pricing_Attribute2         => x_charges_detail_rec.pricing_attribute2,
12243             P_Pricing_Attribute3         => x_charges_detail_rec.pricing_attribute3,
12244             P_Pricing_Attribute4         => x_charges_detail_rec.pricing_attribute4,
12245             P_Pricing_Attribute5         => x_charges_detail_rec.pricing_attribute5,
12246             P_Pricing_Attribute6         => x_charges_detail_rec.pricing_attribute6,
12247             P_Pricing_Attribute7         => x_charges_detail_rec.pricing_attribute7,
12248             P_Pricing_Attribute8         => x_charges_detail_rec.pricing_attribute8,
12249             P_Pricing_Attribute9         => x_charges_detail_rec.pricing_attribute9,
12250             P_Pricing_Attribute10        => x_charges_detail_rec.pricing_attribute10,
12251             P_Pricing_Attribute11        => x_charges_detail_rec.pricing_attribute11,
12252             P_Pricing_Attribute12        => x_charges_detail_rec.pricing_attribute12,
12253             P_Pricing_Attribute13        => x_charges_detail_rec.pricing_attribute13,
12254             P_Pricing_Attribute14        => x_charges_detail_rec.pricing_attribute14,
12255             P_Pricing_Attribute15        => x_charges_detail_rec.pricing_attribute15,
12256             P_Pricing_Attribute16        => x_charges_detail_rec.pricing_attribute16,
12257             P_Pricing_Attribute17        => x_charges_detail_rec.pricing_attribute17,
12258             P_Pricing_Attribute18        => x_charges_detail_rec.pricing_attribute18,
12259             P_Pricing_Attribute19        => x_charges_detail_rec.pricing_attribute19,
12260             P_Pricing_Attribute20        => x_charges_detail_rec.pricing_attribute20,
12261             P_Pricing_Attribute21        => x_charges_detail_rec.pricing_attribute21,
12262             P_Pricing_Attribute22        => x_charges_detail_rec.pricing_attribute22,
12263             P_Pricing_Attribute23        => x_charges_detail_rec.pricing_attribute23,
12264             P_Pricing_Attribute24        => x_charges_detail_rec.pricing_attribute24,
12265             P_Pricing_Attribute25        => x_charges_detail_rec.pricing_attribute25,
12266             p_Pricing_Attribute26        => x_charges_detail_rec.pricing_attribute26,
12267             P_Pricing_Attribute27        => x_charges_detail_rec.pricing_attribute27,
12268             P_Pricing_Attribute28        => x_charges_detail_rec.pricing_attribute28,
12269             P_Pricing_Attribute29        => x_charges_detail_rec.pricing_attribute29,
12270             P_Pricing_Attribute30        => x_charges_detail_rec.pricing_attribute30,
12271             P_PRICING_ATTRIBUTE31        => x_charges_detail_rec.pricing_attribute31,
12272             P_PRICING_ATTRIBUTE32        => x_charges_detail_rec.pricing_attribute32,
12273             P_PRICING_ATTRIBUTE33        => x_charges_detail_rec.pricing_attribute33,
12274             P_PRICING_ATTRIBUTE34        => x_charges_detail_rec.pricing_attribute34,
12275             P_Pricing_Attribute35        => x_charges_detail_rec.pricing_attribute35,
12276             P_Pricing_Attribute36        => x_charges_detail_rec.pricing_attribute36,
12277             P_Pricing_Attribute37        => x_charges_detail_rec.pricing_attribute37,
12278             P_Pricing_Attribute38        => x_charges_detail_rec.pricing_attribute38,
12279             P_Pricing_Attribute39        => x_charges_detail_rec.pricing_attribute39,
12280             P_Pricing_Attribute40        => x_charges_detail_rec.pricing_attribute40,
12281             P_Pricing_Attribute41        => x_charges_detail_rec.pricing_attribute41,
12282             P_Pricing_Attribute42        => x_charges_detail_rec.pricing_attribute42,
12283             P_Pricing_Attribute43        => x_charges_detail_rec.pricing_attribute43,
12284             P_Pricing_Attribute44        => x_charges_detail_rec.pricing_attribute44,
12285             P_Pricing_Attribute45        => x_charges_detail_rec.pricing_attribute45,
12286             P_Pricing_Attribute46        => x_charges_detail_rec.pricing_attribute46,
12287             P_Pricing_Attribute47        => x_charges_detail_rec.pricing_attribute47,
12288             P_Pricing_Attribute48        => x_charges_detail_rec.pricing_attribute48,
12289             P_Pricing_Attribute49        => x_charges_detail_rec.pricing_attribute49,
12290             P_Pricing_Attribute50        => x_charges_detail_rec.pricing_attribute50,
12291             P_Pricing_Attribute51        => x_charges_detail_rec.pricing_attribute51,
12292             P_Pricing_Attribute52        => x_charges_detail_rec.pricing_attribute52,
12293             P_Pricing_Attribute53        => x_charges_detail_rec.pricing_attribute53,
12294             P_Pricing_Attribute54        => x_charges_detail_rec.pricing_attribute54,
12295             P_Pricing_Attribute55        => x_charges_detail_rec.pricing_attribute55,
12296             P_Pricing_Attribute56        => x_charges_detail_rec.pricing_attribute56,
12297             P_Pricing_Attribute57        => x_charges_detail_rec.pricing_attribute57,
12298             P_Pricing_Attribute58        => x_charges_detail_rec.pricing_attribute58,
12299             P_Pricing_Attribute59        => x_charges_detail_rec.pricing_attribute59,
12300             P_Pricing_Attribute60        => x_charges_detail_rec.pricing_attribute60,
12301             P_Pricing_Attribute61        => x_charges_detail_rec.pricing_attribute61,
12302             P_Pricing_Attribute62        => x_charges_detail_rec.pricing_attribute62,
12303             P_Pricing_Attribute63        => x_charges_detail_rec.pricing_attribute63,
12304             P_Pricing_Attribute64        => x_charges_detail_rec.pricing_attribute64,
12305             P_Pricing_Attribute65        => x_charges_detail_rec.pricing_attribute65,
12306             P_Pricing_Attribute66        => x_charges_detail_rec.pricing_attribute66,
12307             P_Pricing_Attribute67        => x_charges_detail_rec.pricing_attribute67,
12308             P_Pricing_Attribute68        => x_charges_detail_rec.pricing_attribute68,
12309             P_Pricing_Attribute69        => x_charges_detail_rec.pricing_attribute69,
12310             P_Pricing_Attribute70        => x_charges_detail_rec.pricing_attribute70,
12311             P_Pricing_Attribute71        => x_charges_detail_rec.pricing_attribute71,
12312             P_Pricing_Attribute72        => x_charges_detail_rec.pricing_attribute72,
12313             P_Pricing_Attribute73        => x_charges_detail_rec.pricing_attribute73,
12314             P_Pricing_Attribute74        => x_charges_detail_rec.pricing_attribute74,
12315             P_Pricing_Attribute75        => x_charges_detail_rec.pricing_attribute75,
12316             P_Pricing_Attribute76        => x_charges_detail_rec.pricing_attribute76,
12317             P_Pricing_Attribute77        => x_charges_detail_rec.pricing_attribute77,
12318             P_Pricing_Attribute78        => x_charges_detail_rec.pricing_attribute78,
12319             P_Pricing_Attribute79        => x_charges_detail_rec.pricing_attribute79,
12320             P_Pricing_Attribute80        => x_charges_detail_rec.pricing_attribute80,
12321             P_Pricing_Attribute81        => x_charges_detail_rec.pricing_attribute81,
12322             P_Pricing_Attribute82        => x_charges_detail_rec.pricing_attribute82,
12323             P_Pricing_Attribute83        => x_charges_detail_rec.pricing_attribute83,
12324             P_Pricing_Attribute84        => x_charges_detail_rec.pricing_attribute84,
12325             P_Pricing_Attribute85        => x_charges_detail_rec.pricing_attribute85,
12326             P_Pricing_Attribute86        => x_charges_detail_rec.pricing_attribute86,
12327             P_Pricing_Attribute87        => x_charges_detail_rec.pricing_attribute87,
12328             P_Pricing_Attribute88        => x_charges_detail_rec.pricing_attribute88,
12329             P_Pricing_Attribute89        => x_charges_detail_rec.pricing_attribute89,
12330             P_Pricing_Attribute90        => x_charges_detail_rec.pricing_attribute90,
12331             P_Pricing_Attribute91        => x_charges_detail_rec.pricing_attribute91,
12332             P_Pricing_Attribute92        => x_charges_detail_rec.pricing_attribute92,
12333             P_Pricing_Attribute93        => x_charges_detail_rec.pricing_attribute93,
12334             P_Pricing_Attribute94        => x_charges_detail_rec.pricing_attribute94,
12335             P_Pricing_Attribute95        => x_charges_detail_rec.pricing_attribute95,
12336             P_Pricing_Attribute96        => x_charges_detail_rec.pricing_attribute96,
12337             P_Pricing_Attribute97        => x_charges_detail_rec.pricing_attribute97,
12338             P_Pricing_Attribute98        => x_charges_detail_rec.pricing_attribute98,
12339             P_Pricing_Attribute99        => x_charges_detail_rec.pricing_attribute99,
12340             P_Pricing_Attribute100       => x_charges_detail_rec.pricing_attribute100,
12341             x_return_status              => l_return_status,
12342             x_msg_count                  => l_msg_count,
12343             x_msg_data                   => l_msg_data);
12344 
12345           --DBMS_OUTPUT.PUT_LINE('After calling CS_Pricing_Item_Pkg.Call_Pricing_Item ...');
12346           --DBMS_OUTPUT.PUT_LINE('l_msg_data '||l_msg_data);
12347 
12348           IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
12349             FND_MESSAGE.Set_Name('CS', 'CS_CHG_API_PRICING_ITEM_ERROR');
12350             FND_MESSAGE.set_token('INV_ID', x_charges_detail_rec.inventory_item_id_in);
12351             FND_MESSAGE.set_token('PRICE_LIST_ID', x_charges_detail_rec.price_list_id);
12352             FND_MESSAGE.set_token('UOM', x_charges_detail_rec.unit_of_measure_code);
12353             FND_MESSAGE.set_token('CURR_CODE', x_charges_detail_rec.currency_code);
12354             --FND_MESSAGE.SET_TOKEN('TEXT', l_msg_data, TRUE);
12355             FND_MSG_PUB.Add;
12356             RAISE FND_API.G_EXC_ERROR;
12357           END IF;
12358 
12359           --bug # 3056622 charge amount is zero for items with negative prices
12360           --assign to out record
12361           x_charges_detail_rec.list_price    := l_list_price;
12362           IF p_charges_detail_rec.selling_price <> FND_API.G_MISS_NUM AND
12363              p_charges_detail_rec.selling_price IS NOT NULL THEN
12364             x_charges_detail_rec.selling_price :=  p_charges_detail_rec.selling_price;
12365           ELSE
12366             x_charges_detail_rec.selling_price := x_charges_detail_rec.list_price;
12367           END IF;
12368 
12369 
12370           IF x_charges_detail_rec.billing_flag = 'L' AND
12371              x_charges_detail_rec.con_pct_over_list_price IS NOT NULL THEN
12372 
12373             --get the new list price and selling price
12374             x_charges_detail_rec.list_price := x_charges_detail_rec.list_price +
12375                                                (x_charges_detail_rec.list_price *  x_charges_detail_rec.con_pct_over_list_price/100);
12376 
12377             x_charges_detail_rec.selling_price := x_charges_detail_rec.list_price;
12378           ELSE
12379             x_charges_detail_rec.list_price    := x_charges_detail_rec.list_price;
12380             x_charges_detail_rec.selling_price := x_charges_detail_rec.selling_price;
12381           END IF;
12382 
12383 
12384           --DBMS_OUTPUT.PUT_LINE('list_price '||x_charges_detail_rec.list_price);
12385           --DBMS_OUTPUT.PUT_LINE('Selling Price '||x_charges_detail_rec.selling_price);
12386           --DBMS_OUTPUT.PUT_LINE(' No Charge Flag is  '||x_charges_detail_rec.no_charge_flag);
12387           --DBMS_OUTPUT.PUT_LINE(' Conversion needed flag '||l_conversion_needed_flag);
12388 
12389 
12390           --bug # 3056622 charge amount is zero for items with negative prices
12391           IF x_charges_detail_rec.no_charge_flag <> 'Y' AND x_charges_detail_rec.selling_price IS NOT NULL THEN
12392             IF l_conversion_needed_flag = 'Y' THEN
12393               IF p_charges_detail_rec.selling_price IS NOT NULL THEN
12394                 x_charges_detail_rec.selling_price := x_charges_detail_rec.selling_price * x_charges_detail_rec.conversion_rate;
12395                 x_charges_detail_rec.after_warranty_cost := x_charges_detail_rec.selling_price * x_charges_detail_rec.quantity_required;
12396               ELSE
12397                 x_charges_detail_rec.after_warranty_cost := x_charges_detail_rec.selling_price * x_charges_detail_rec.quantity_required * x_charges_detail_rec.conversion_rate;
12398               END IF;
12399             ELSE
12400               x_charges_detail_rec.after_warranty_cost := x_charges_detail_rec.selling_price * x_charges_detail_rec.quantity_required;
12401             END IF;
12402           ELSE
12403             -- no charge flag = 'Y'
12404             x_charges_detail_rec.after_warranty_cost := 0;
12405           END IF;
12406 
12407           --DBMS_OUTPUT.PUT_LINE(' after warr cost is '|| x_charges_detail_rec.after_warranty_cost);
12408 
12409 
12410           --check to see if contract discount needs to be applied
12411 
12412           --DBMS_OUTPUT.PUT_LINE('apply contract discount '|| x_charges_detail_rec.apply_contract_discount);
12413 
12414           IF x_charges_detail_rec.apply_contract_discount = 'Y' AND
12415              x_charges_detail_rec.contract_line_id IS NOT NULL AND
12416              x_charges_detail_rec.no_charge_flag <> 'Y' THEN
12417 
12418             --assign to out record
12419             x_charges_detail_rec.apply_contract_discount := p_charges_detail_rec.apply_contract_discount;
12420 
12421             --call contracts dicounting API
12422             --DBMS_OUTPUT.PUT_LINE('Call Contracts API to Apply contracts 5');
12423 
12424             CS_Est_Apply_Contract_PKG.Apply_Contract(
12425               p_coverage_id           => x_charges_detail_rec.contract_line_id,
12426               p_coverage_txn_group_id => x_charges_detail_rec.coverage_txn_group_id,
12427               p_txn_billing_type_id   => x_charges_detail_rec.txn_billing_type_id,
12428               P_BUSINESS_PROCESS_ID   => x_charges_detail_rec.business_process_id,
12429               P_REQUEST_DATE          => l_request_date,
12430               p_amount                => x_charges_detail_rec.after_warranty_cost,
12431               p_discount_amount       => l_contract_discount,
12432               X_RETURN_STATUS         => l_return_status,
12433               X_MSG_COUNT             => l_msg_count,
12434               X_MSG_DATA              => l_msg_data);
12435 
12436             IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
12437               FND_MESSAGE.Set_Name('CS', 'CS_CHG_APPLY_CONTRACT_WARNING');
12438               FND_MESSAGE.SET_TOKEN('REASON', l_msg_data);
12439               FND_MSG_PUB.Add;
12440               RAISE FND_API.G_EXC_ERROR;
12441             END IF;
12442 
12443             --Bug Fix for Bug # 3088397
12444             IF l_contract_discount IS NOT NULL THEN
12445               --assign the contract discount to the out record
12446               x_charges_detail_rec.contract_discount_amount := x_charges_detail_rec.after_warranty_cost - l_contract_discount;
12447 
12448               --apply discount
12449               x_charges_detail_rec.after_warranty_cost :=  l_contract_discount;
12450 
12451             ELSE
12452               -- contract discount amt should be 0
12453               --x_charges_detail_rec.contract_discount_amount := 0;
12454               null;
12455             END IF;
12456             --DBMS_OUTPUT.PUT_LINE('Contract 5'||x_charges_detail_rec.contract_discount_amount);
12457 
12458           ELSE
12459             --Apply contract discount = 'N'
12460             --Fixed Bug # 3220253
12461             --passed p_charges_detail_rec.contract_discount_amount
12462             x_charges_detail_rec.apply_contract_discount := p_charges_detail_rec.apply_contract_discount;
12463             x_charges_detail_rec.contract_discount_amount := p_charges_detail_rec.contract_discount_amount;
12464 
12465             IF x_charges_detail_rec.contract_discount_amount IS NULL THEN
12466               x_charges_detail_rec.contract_discount_amount := 0;
12467             ELSE
12468               x_charges_detail_rec.contract_discount_amount := x_charges_detail_rec.contract_discount_amount;
12469             END IF;
12470           END IF ;
12471 
12472       ELSE
12473         --x_charges_detail_rec.inventory_item_id_in IS NULL
12474         --x_charges_detail_rec.unit_of_measure_code IS NULL
12475         --x_charges_detail_rec.price_list_id IS NULL
12476         --x_charges_detail_rec.quantity_required IS NULL
12477         --the list price cannot be derived and the
12478         --after warranty cost cannot be computed
12479         --assign 0 to list_price and after_warranty_cost
12480         x_charges_detail_rec.list_price := 0;
12481         x_charges_detail_rec.selling_price := 0;
12482         x_charges_detail_rec.after_warranty_cost := 0;
12483         x_charges_detail_rec.contract_discount_amount := 0;
12484 
12485       END IF;
12486     ELSE
12487       --l_calc_sp = 'N'
12488       x_charges_detail_rec.list_price := l_db_det_rec.list_price;
12489       x_charges_detail_rec.selling_price := l_db_det_rec.selling_price;
12490 
12491 
12492       --calculate the contract % over list price
12493       IF x_charges_detail_rec.billing_flag = 'L' AND
12494          x_charges_detail_rec.con_pct_over_list_price IS NOT NULL THEN
12495 
12496         --get the new list price and selling price
12497         x_charges_detail_rec.list_price := x_charges_detail_rec.list_price +
12498                                         (x_charges_detail_rec.list_price *  x_charges_detail_rec.con_pct_over_list_price/100);
12499 
12500         x_charges_detail_rec.selling_price := x_charges_detail_rec.list_price;
12501       ELSE
12502         x_charges_detail_rec.list_price    := l_db_det_rec.list_price;
12503         --x_charges_detail_rec.selling_price := l_db_det_rec.selling_price;
12504         -- Commented above and added below for Bug# 4689183
12505         IF (p_charges_detail_rec.selling_price <> FND_API.G_MISS_NUM AND
12506             p_charges_detail_rec.selling_price IS NOT NULL) THEN
12507           IF (p_charges_detail_rec.selling_price <> l_db_det_rec.selling_price) THEN
12508             x_charges_detail_rec.selling_price := p_charges_detail_rec.selling_price;
12509           ELSE
12510             x_charges_detail_rec.selling_price := l_db_det_rec.selling_price;
12511           END IF;
12512         END IF;
12513       END IF;
12514 
12515       --bug # 3056622 charge amount is zero for items with negative prices
12516 
12517       IF x_charges_detail_rec.no_charge_flag <> 'Y' AND x_charges_detail_rec.selling_price IS NOT NULL THEN
12518         IF l_conversion_needed_flag = 'Y' THEN
12519           x_charges_detail_rec.after_warranty_cost := x_charges_detail_rec.selling_price * x_charges_detail_rec.quantity_required * x_charges_detail_rec.conversion_rate;
12520         ELSE
12521           --Condition added to fix Bug # 3358531
12522           x_charges_detail_rec.after_warranty_cost := l_db_det_rec.after_warranty_cost;
12523         END IF;
12524       ELSE
12525         -- no charge flag = 'Y'
12526         x_charges_detail_rec.after_warranty_cost := 0;
12527       END IF;
12528 
12529        --DBMS_OUTPUT.PUT_LINE(' after warr cost is '|| x_charges_detail_rec.after_warranty_cost);
12530 
12531 
12532           --check to see if contract discount needs to be applied
12533 
12534           --DBMS_OUTPUT.PUT_LINE('apply contract discount '|| x_charges_detail_rec.apply_contract_discount);
12535 
12536           IF x_charges_detail_rec.apply_contract_discount = 'Y' AND
12537              x_charges_detail_rec.contract_line_id IS NOT NULL AND
12538              x_charges_detail_rec.no_charge_flag <> 'Y' THEN
12539 
12540             --assign to out record
12541             x_charges_detail_rec.apply_contract_discount := p_charges_detail_rec.apply_contract_discount;
12542 
12543 
12544             --call contracts dicounting API
12545             --DBMS_OUTPUT.PUT_LINE('Call Contracts API to Apply contracts 6');
12546 
12547             CS_Est_Apply_Contract_PKG.Apply_Contract(
12548               p_coverage_id           => x_charges_detail_rec.coverage_id,
12549               p_coverage_txn_group_id => x_charges_detail_rec.coverage_txn_group_id,
12550               p_txn_billing_type_id   => x_charges_detail_rec.txn_billing_type_id,
12551               P_BUSINESS_PROCESS_ID   => x_charges_detail_rec.business_process_id,
12552               P_REQUEST_DATE          => l_request_date,
12553               p_amount                => x_charges_detail_rec.after_warranty_cost,
12554               p_discount_amount       => l_contract_discount,
12555               X_RETURN_STATUS         => l_return_status,
12556               X_MSG_COUNT             => l_msg_count,
12557               X_MSG_DATA              => l_msg_data);
12558 
12559             IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
12560               FND_MESSAGE.Set_Name('CS', 'CS_CHG_APPLY_CONTRACT_WARNING');
12561               FND_MESSAGE.SET_TOKEN('REASON', l_msg_data);
12562               FND_MSG_PUB.Add;
12563               RAISE FND_API.G_EXC_ERROR;
12564             END IF;
12565 
12566             --Bug Fix for Bug # 3088397
12567             IF l_contract_discount IS NOT NULL THEN
12568               --assign the contract discount to the out record
12569               x_charges_detail_rec.contract_discount_amount := x_charges_detail_rec.after_warranty_cost - l_contract_discount;
12570 
12571               --apply discount
12572               x_charges_detail_rec.after_warranty_cost := l_contract_discount;
12573             ELSE
12574               -- contract discount amt should be 0
12575               --x_charges_detail_rec.contract_discount_amount := 0;
12576               null;
12577             END IF;
12578             --DBMS_OUTPUT.PUT_LINE('Contract 6'||x_charges_detail_rec.contract_discount_amount);
12579 
12580           ELSE
12581             --Apply contract discount = 'N'
12582             --Fixed Bug # 3220253
12583             --passed p_charges_detail_rec.contract_discount_amount
12584             x_charges_detail_rec.apply_contract_discount := p_charges_detail_rec.apply_contract_discount;
12585             IF p_charges_detail_rec.contract_discount_amount <> FND_API.G_MISS_NUM OR
12586               p_charges_detail_rec.contract_discount_amount IS NOT NULL THEN
12587               x_charges_detail_rec.contract_discount_amount := l_db_rec.contract_discount_amount;
12588             ELSIF p_charges_detail_rec.contract_discount_amount IS NULL THEN
12589               x_charges_detail_rec.contract_discount_amount := 0;
12590             ELSE
12591               x_charges_detail_rec.contract_discount_amount := p_charges_detail_rec.contract_discount_amount;
12592             END IF;
12593           END IF ;
12594     END IF;
12595 
12596   ELSIF
12597         --Fix # 3069583 unable to override charges for labor charge line
12598         x_charges_detail_rec.billing_flag IN ('E', 'M', 'L') AND
12599         p_charges_detail_rec.after_warranty_cost <> FND_API.G_MISS_NUM AND
12600         p_charges_detail_rec.after_warranty_cost IS NOT NULL THEN
12601 
12602         --DBMS_OUTPUT.PUT_LINE('Update Expense line with after warr cost ');
12603         --DBMS_OUTPUT.PUT_LINE('Update l_conversion_needed_flag '||l_conversion_needed_flag);
12604         --DBMS_OUTPUT.PUT_LINE('Update after_warranty_cost = '||p_charges_detail_rec.after_warranty_cost );
12605         --DBMS_OUTPUT.PUT_LINE('DB After warranty cost = '||l_db_det_rec.after_warranty_cost);
12606 
12607         IF p_charges_detail_rec.after_warranty_cost <> nvl(l_db_det_rec.after_warranty_cost, 0) THEN
12608 
12609           l_calc_sp := 'Y';
12610 
12611           --DBMS_OUTPUT.PUT_LINE(' In here ');
12612 
12613           -- Added to fix Bug # 3819167
12614           --
12615           /*
12616           IF ((l_line_order_category_code = 'RETURN') AND
12617               (sign(x_charges_detail_rec.quantity_required) = -1)) THEN
12618              l_absolute_quantity_required := x_charges_detail_rec.quantity_required * -1;
12619           ELSE
12620              l_absolute_quantity_required := x_charges_detail_rec.quantity_required;
12621           END IF;
12622           */
12623 
12624           -- Call the pricing API just to verify that the item is on the price list
12625           CS_Pricing_Item_Pkg.Call_Pricing_Item(
12626             P_Inventory_Item_Id          => x_charges_detail_rec.inventory_item_id_in,
12627             P_Price_List_Id              => x_charges_detail_rec.price_list_id,
12628             P_UOM_Code                   => x_charges_detail_rec.unit_of_measure_code,
12629             p_Currency_Code              => x_charges_detail_rec.currency_code,
12630             P_Quantity                   => abs(x_charges_detail_rec.quantity_required),
12631             P_Org_Id                     => x_charges_detail_rec.org_id,
12632             x_list_price                 => l_list_price,
12633             P_Pricing_Context            => x_charges_detail_rec.pricing_context,
12634             P_Pricing_Attribute1         => x_charges_detail_rec.pricing_attribute1,
12635             P_Pricing_Attribute2         => x_charges_detail_rec.pricing_attribute2,
12636             P_Pricing_Attribute3         => x_charges_detail_rec.pricing_attribute3,
12637             P_Pricing_Attribute4         => x_charges_detail_rec.pricing_attribute4,
12638             P_Pricing_Attribute5         => x_charges_detail_rec.pricing_attribute5,
12639             P_Pricing_Attribute6         => x_charges_detail_rec.pricing_attribute6,
12640             P_Pricing_Attribute7         => x_charges_detail_rec.pricing_attribute7,
12641             P_Pricing_Attribute8         => x_charges_detail_rec.pricing_attribute8,
12642             P_Pricing_Attribute9         => x_charges_detail_rec.pricing_attribute9,
12643             P_Pricing_Attribute10        => x_charges_detail_rec.pricing_attribute10,
12644             P_Pricing_Attribute11        => x_charges_detail_rec.pricing_attribute11,
12645             P_Pricing_Attribute12        => x_charges_detail_rec.pricing_attribute12,
12646             P_Pricing_Attribute13        => x_charges_detail_rec.pricing_attribute13,
12647             P_Pricing_Attribute14        => x_charges_detail_rec.pricing_attribute14,
12648             P_Pricing_Attribute15        => x_charges_detail_rec.pricing_attribute15,
12649             P_Pricing_Attribute16        => x_charges_detail_rec.pricing_attribute16,
12650             P_Pricing_Attribute17        => x_charges_detail_rec.pricing_attribute17,
12651             P_Pricing_Attribute18        => x_charges_detail_rec.pricing_attribute18,
12652             P_Pricing_Attribute19        => x_charges_detail_rec.pricing_attribute19,
12653             P_Pricing_Attribute20        => x_charges_detail_rec.pricing_attribute20,
12654             P_Pricing_Attribute21        => x_charges_detail_rec.pricing_attribute21,
12655             P_Pricing_Attribute22        => x_charges_detail_rec.pricing_attribute22,
12656             P_Pricing_Attribute23        => x_charges_detail_rec.pricing_attribute23,
12657             P_Pricing_Attribute24        => x_charges_detail_rec.pricing_attribute24,
12658             P_Pricing_Attribute25        => x_charges_detail_rec.pricing_attribute25,
12659             p_Pricing_Attribute26        => x_charges_detail_rec.pricing_attribute26,
12660             P_Pricing_Attribute27        => x_charges_detail_rec.pricing_attribute27,
12661             P_Pricing_Attribute28        => x_charges_detail_rec.pricing_attribute28,
12662             P_Pricing_Attribute29        => x_charges_detail_rec.pricing_attribute29,
12663             P_Pricing_Attribute30        => x_charges_detail_rec.pricing_attribute30,
12664             P_PRICING_ATTRIBUTE31        => x_charges_detail_rec.pricing_attribute31,
12665             P_PRICING_ATTRIBUTE32        => x_charges_detail_rec.pricing_attribute32,
12666             P_PRICING_ATTRIBUTE33        => x_charges_detail_rec.pricing_attribute33,
12667             P_PRICING_ATTRIBUTE34        => x_charges_detail_rec.pricing_attribute34,
12668             P_Pricing_Attribute35        => x_charges_detail_rec.pricing_attribute35,
12669             P_Pricing_Attribute36        => x_charges_detail_rec.pricing_attribute36,
12670             P_Pricing_Attribute37        => x_charges_detail_rec.pricing_attribute37,
12671             P_Pricing_Attribute38        => x_charges_detail_rec.pricing_attribute38,
12672             P_Pricing_Attribute39        => x_charges_detail_rec.pricing_attribute39,
12673             P_Pricing_Attribute40        => x_charges_detail_rec.pricing_attribute40,
12674             P_Pricing_Attribute41        => x_charges_detail_rec.pricing_attribute41,
12675             P_Pricing_Attribute42        => x_charges_detail_rec.pricing_attribute42,
12676             P_Pricing_Attribute43        => x_charges_detail_rec.pricing_attribute43,
12677             P_Pricing_Attribute44        => x_charges_detail_rec.pricing_attribute44,
12678             P_Pricing_Attribute45        => x_charges_detail_rec.pricing_attribute45,
12679             P_Pricing_Attribute46        => x_charges_detail_rec.pricing_attribute46,
12680             P_Pricing_Attribute47        => x_charges_detail_rec.pricing_attribute47,
12681             P_Pricing_Attribute48        => x_charges_detail_rec.pricing_attribute48,
12682             P_Pricing_Attribute49        => x_charges_detail_rec.pricing_attribute49,
12683             P_Pricing_Attribute50        => x_charges_detail_rec.pricing_attribute50,
12684             P_Pricing_Attribute51        => x_charges_detail_rec.pricing_attribute51,
12685             P_Pricing_Attribute52        => x_charges_detail_rec.pricing_attribute52,
12686             P_Pricing_Attribute53        => x_charges_detail_rec.pricing_attribute53,
12687             P_Pricing_Attribute54        => x_charges_detail_rec.pricing_attribute54,
12688             P_Pricing_Attribute55        => x_charges_detail_rec.pricing_attribute55,
12689             P_Pricing_Attribute56        => x_charges_detail_rec.pricing_attribute56,
12690             P_Pricing_Attribute57        => x_charges_detail_rec.pricing_attribute57,
12691             P_Pricing_Attribute58        => x_charges_detail_rec.pricing_attribute58,
12692             P_Pricing_Attribute59        => x_charges_detail_rec.pricing_attribute59,
12693             P_Pricing_Attribute60        => x_charges_detail_rec.pricing_attribute60,
12694             P_Pricing_Attribute61        => x_charges_detail_rec.pricing_attribute61,
12695             P_Pricing_Attribute62        => x_charges_detail_rec.pricing_attribute62,
12696             P_Pricing_Attribute63        => x_charges_detail_rec.pricing_attribute63,
12697             P_Pricing_Attribute64        => x_charges_detail_rec.pricing_attribute64,
12698             P_Pricing_Attribute65        => x_charges_detail_rec.pricing_attribute65,
12699             P_Pricing_Attribute66        => x_charges_detail_rec.pricing_attribute66,
12700             P_Pricing_Attribute67        => x_charges_detail_rec.pricing_attribute67,
12701             P_Pricing_Attribute68        => x_charges_detail_rec.pricing_attribute68,
12702             P_Pricing_Attribute69        => x_charges_detail_rec.pricing_attribute69,
12703             P_Pricing_Attribute70        => x_charges_detail_rec.pricing_attribute70,
12704             P_Pricing_Attribute71        => x_charges_detail_rec.pricing_attribute71,
12705             P_Pricing_Attribute72        => x_charges_detail_rec.pricing_attribute72,
12706             P_Pricing_Attribute73        => x_charges_detail_rec.pricing_attribute73,
12707             P_Pricing_Attribute74        => x_charges_detail_rec.pricing_attribute74,
12708             P_Pricing_Attribute75        => x_charges_detail_rec.pricing_attribute75,
12709             P_Pricing_Attribute76        => x_charges_detail_rec.pricing_attribute76,
12710             P_Pricing_Attribute77        => x_charges_detail_rec.pricing_attribute77,
12711             P_Pricing_Attribute78        => x_charges_detail_rec.pricing_attribute78,
12712             P_Pricing_Attribute79        => x_charges_detail_rec.pricing_attribute79,
12713             P_Pricing_Attribute80        => x_charges_detail_rec.pricing_attribute80,
12714             P_Pricing_Attribute81        => x_charges_detail_rec.pricing_attribute81,
12715             P_Pricing_Attribute82        => x_charges_detail_rec.pricing_attribute82,
12716             P_Pricing_Attribute83        => x_charges_detail_rec.pricing_attribute83,
12717             P_Pricing_Attribute84        => x_charges_detail_rec.pricing_attribute84,
12718             P_Pricing_Attribute85        => x_charges_detail_rec.pricing_attribute85,
12719             P_Pricing_Attribute86        => x_charges_detail_rec.pricing_attribute86,
12720             P_Pricing_Attribute87        => x_charges_detail_rec.pricing_attribute87,
12721             P_Pricing_Attribute88        => x_charges_detail_rec.pricing_attribute88,
12722             P_Pricing_Attribute89        => x_charges_detail_rec.pricing_attribute89,
12723             P_Pricing_Attribute90        => x_charges_detail_rec.pricing_attribute90,
12724             P_Pricing_Attribute91        => x_charges_detail_rec.pricing_attribute91,
12725             P_Pricing_Attribute92        => x_charges_detail_rec.pricing_attribute92,
12726             P_Pricing_Attribute93        => x_charges_detail_rec.pricing_attribute93,
12727             P_Pricing_Attribute94        => x_charges_detail_rec.pricing_attribute94,
12728             P_Pricing_Attribute95        => x_charges_detail_rec.pricing_attribute95,
12729             P_Pricing_Attribute96        => x_charges_detail_rec.pricing_attribute96,
12730             P_Pricing_Attribute97        => x_charges_detail_rec.pricing_attribute97,
12731             P_Pricing_Attribute98        => x_charges_detail_rec.pricing_attribute98,
12732             P_Pricing_Attribute99        => x_charges_detail_rec.pricing_attribute99,
12733             P_Pricing_Attribute100       => x_charges_detail_rec.pricing_attribute100,
12734             x_return_status              => l_return_status,
12735             x_msg_count                  => l_msg_count,
12736             x_msg_data                   => l_msg_data);
12737 
12738         --DBMS_OUTPUT.PUT_LINE('After calling CS_Pricing_Item_Pkg.Call_Pricing_Item ...');
12739         --DBMS_OUTPUT.PUT_LINE('l_msg_data '||l_msg_data);
12740 
12741         IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
12742           FND_MESSAGE.Set_Name('CS', 'CS_CHG_API_PRICING_ITEM_ERROR');
12743           FND_MESSAGE.set_token('INV_ID', x_charges_detail_rec.inventory_item_id_in);
12744           FND_MESSAGE.set_token('PRICE_LIST_ID', x_charges_detail_rec.price_list_id);
12745           FND_MESSAGE.set_token('UOM', x_charges_detail_rec.unit_of_measure_code);
12746           FND_MESSAGE.set_token('CURR_CODE', x_charges_detail_rec.currency_code);
12747           --FND_MESSAGE.SET_TOKEN('TEXT', l_msg_data, TRUE);
12748           FND_MSG_PUB.Add;
12749           RAISE FND_API.G_EXC_ERROR;
12750         END IF;
12751 
12752         -- Assign the after warranty that comes on the line
12753         x_charges_detail_rec.after_warranty_cost := p_charges_detail_rec.after_warranty_cost;
12754 
12755         IF l_conversion_needed_flag = 'Y' THEN
12756          --assign coverted amt to after_warranty_cost
12757          x_charges_detail_rec.after_warranty_cost := x_charges_detail_rec.after_warranty_cost * x_charges_detail_rec.conversion_rate;
12758          x_charges_detail_rec.list_price := l_list_price;
12759 
12760          --bug # 3056622 charge amount is zero for items with negative prices
12761 
12762          IF p_charges_detail_rec.selling_price <> FND_API.G_MISS_NUM AND
12763             p_charges_detail_rec.selling_price IS NOT NULL THEN
12764            x_charges_detail_rec.selling_price :=  p_charges_detail_rec.selling_price * x_charges_detail_rec.conversion_rate;
12765          ELSE
12766            x_charges_detail_rec.selling_price :=  x_charges_detail_rec.list_price;
12767          END IF;
12768 
12769         ELSE
12770           x_charges_detail_rec.after_warranty_cost := p_charges_detail_rec.after_warranty_cost;
12771           x_charges_detail_rec.list_price := l_list_price;
12772 
12773           --bug # 3056622 charge amount is zero for items with negative prices
12774 
12775           IF p_charges_detail_rec.selling_price IS NOT NULL THEN
12776             x_charges_detail_rec.selling_price :=  p_charges_detail_rec.selling_price;
12777           ELSE
12778             x_charges_detail_rec.selling_price :=  x_charges_detail_rec.list_price;
12779           END IF;
12780         END IF;
12781 
12782 
12783         --DBMS_OUTPUT.PUT_LINE(' after_warranty_cost '||x_charges_detail_rec.after_warranty_cost );
12784         --DBMS_OUTPUT.PUT_LINE(' selling price is '|| x_charges_detail_rec.selling_price);
12785         --DBMS_OUTPUT.PUT_LINE(' list price is '|| x_charges_detail_rec.list_price);
12786         --DBMS_OUTPUT.PUT_LINE(' apply_contract_discount is '||x_charges_detail_rec.apply_contract_discount);
12787         --DBMS_OUTPUT.PUT_LINE(' no_charge_flag is '||x_charges_detail_rec.no_charge_flag);
12788         --DBMS_OUTPUT.PUT_LINE('l_request_date is '||l_request_date);
12789 
12790         --Fixed Bug # 3468146
12791         --need to do this here so that contract discounting is done correctly
12792         --re-set the no_charge_flag for Charge Lines
12793         --since the line has come with after warranty cost from upstream
12794         IF x_charges_detail_rec.after_warranty_cost <> 0 THEN
12795           x_charges_detail_rec.no_charge_flag := 'N';
12796         END IF;
12797 
12798         --DBMS_OUTPUT.PUT_LINE('re-setting the no_charge_flag' ||x_charges_detail_rec.no_charge_flag);
12799 
12800 
12801         IF x_charges_detail_rec.apply_contract_discount = 'Y' AND
12802           x_charges_detail_rec.contract_line_id IS NOT NULL AND
12803           x_charges_detail_rec.no_charge_flag <> 'Y' THEN
12804 
12805 
12806           --DBMS_OUTPUT.PUT_LINE('calling contract discount ');
12807 
12808 
12809           --call contracts dicounting API
12810          CS_Est_Apply_Contract_PKG.Apply_Contract(
12811            p_coverage_id           => x_charges_detail_rec.contract_line_id,
12812            p_coverage_txn_group_id => x_charges_detail_rec.coverage_txn_group_id,
12813            p_txn_billing_type_id   => x_charges_detail_rec.txn_billing_type_id,
12814            P_BUSINESS_PROCESS_ID   => x_charges_detail_rec.business_process_id,
12815            P_REQUEST_DATE          => l_request_date,
12816            p_amount                => x_charges_detail_rec.after_warranty_cost,
12817            p_discount_amount       => l_contract_discount,
12818            X_RETURN_STATUS         => l_return_status,
12819            X_MSG_COUNT             => l_msg_count,
12820            X_MSG_DATA              => l_msg_data);
12821 
12822           IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
12823             FND_MESSAGE.Set_Name('CS', 'CS_CHG_APPLY_CONTRACT_WARNING');
12824             FND_MESSAGE.SET_TOKEN('REASON', l_msg_data);
12825             FND_MSG_PUB.Add;
12826             RAISE FND_API.G_EXC_ERROR;
12827           END IF;
12828 
12829           --DBMS_OUTPUT.PUT_LINE('l_contract_discount '||l_contract_discount);
12830 
12831          --Bug Fix for Bug # 3088397
12832          IF l_contract_discount IS NOT NULL THEN
12833            --assign the contract discount to the out record
12834            x_charges_detail_rec.contract_discount_amount := x_charges_detail_rec.after_warranty_cost - l_contract_discount;
12835 
12836            --apply discount
12837            x_charges_detail_rec.after_warranty_cost := l_contract_discount;
12838 
12839            --DBMS_OUTPUT.PUT_LINE(' contract discount is : '||x_charges_detail_rec.contract_discount_amount);
12840            --DBMS_OUTPUT.PUT_LINE(' after_warranty_cost  : '||x_charges_detail_rec.after_warranty_cost );
12841 
12842          ELSE
12843            -- contract discount amt should be 0
12844            --x_charges_detail_rec.contract_discount_amount := 0;
12845            null;
12846 
12847          END IF;
12848 
12849            --DBMS_OUTPUT.PUT_LINE('Contract 7'||x_charges_detail_rec.contract_discount_amount);
12850            --DBMS_OUTPUT.PUT_LINE(' contract discount is : '||x_charges_detail_rec.contract_discount_amount);
12851            --DBMS_OUTPUT.PUT_LINE(' after_warranty_cost  : '||x_charges_detail_rec.after_warranty_cost );
12852       ELSE
12853         --Apply contract discount = 'N'
12854         --Fixed Bug # 3220253
12855         --passed p_charges_detail_rec.contract_discount_amount
12856         x_charges_detail_rec.apply_contract_discount := p_charges_detail_rec.apply_contract_discount;
12857         x_charges_detail_rec.contract_discount_amount := p_charges_detail_rec.contract_discount_amount;
12858 
12859          IF x_charges_detail_rec.contract_discount_amount IS NULL THEN
12860             x_charges_detail_rec.contract_discount_amount := 0;
12861          ELSE
12862             x_charges_detail_rec.contract_discount_amount := x_charges_detail_rec.contract_discount_amount;
12863          END IF;
12864       END IF ;
12865    ELSE
12866      --l_calc_sp = 'N'
12867      -- Assign the after warranty that is in the databse
12868         x_charges_detail_rec.after_warranty_cost := l_db_det_rec.after_warranty_cost;
12869 
12870     IF l_conversion_needed_flag = 'Y' AND
12871        l_db_det_rec.conversion_rate IS NULL THEN
12872        --assign coverted amt to after_warranty_cost
12873 
12874       --bug # 3056622 charge amount is zero for items with negative prices
12875 
12876       IF p_charges_detail_rec.selling_price <> FND_API.G_MISS_NUM AND
12877          p_charges_detail_rec.selling_price IS NOT NULL THEN
12878         x_charges_detail_rec.selling_price :=  p_charges_detail_rec.selling_price * x_charges_detail_rec.conversion_rate;
12879         x_charges_detail_rec.after_warranty_cost := x_charges_detail_rec.after_warranty_cost * x_charges_detail_rec.conversion_rate;
12880         x_charges_detail_rec.list_price := l_db_det_rec.list_price * x_charges_detail_rec.conversion_rate;
12881       ELSE
12882         x_charges_detail_rec.selling_price :=  l_db_det_rec.selling_price * x_charges_detail_rec.conversion_rate  ;
12883         x_charges_detail_rec.after_warranty_cost := x_charges_detail_rec.after_warranty_cost * x_charges_detail_rec.conversion_rate;
12884         x_charges_detail_rec.list_price := l_db_det_rec.list_price * x_charges_detail_rec.conversion_rate;
12885       END IF;
12886 
12887     ELSE
12888        --bug # 3056622 charge amount is zero for items with negative prices
12889        IF p_charges_detail_rec.selling_price <> FND_API.G_MISS_NUM AND
12890           p_charges_detail_rec.selling_price IS NOT NULL THEN
12891          x_charges_detail_rec.selling_price :=  p_charges_detail_rec.selling_price;
12892          x_charges_detail_rec.after_warranty_cost := x_charges_detail_rec.after_warranty_cost;
12893          x_charges_detail_rec.list_price := l_db_det_rec.list_price;
12894        ELSE
12895          x_charges_detail_rec.after_warranty_cost := l_db_det_rec.after_warranty_cost;
12896          x_charges_detail_rec.list_price := l_db_det_rec.list_price;
12897          x_charges_detail_rec.selling_price := l_db_det_rec.selling_price;
12898        END IF;
12899     END IF;
12900 
12901     --DBMS_OUTPUT.PUT_LINE(' after_warranty_cost '||x_charges_detail_rec.after_warranty_cost );
12902 
12903     IF x_charges_detail_rec.apply_contract_discount = 'Y' AND
12904        x_charges_detail_rec.contract_line_id IS NOT NULL AND
12905        x_charges_detail_rec.no_charge_flag <> 'Y' THEN
12906 
12907 
12908       --call contracts dicounting API
12909      CS_Est_Apply_Contract_PKG.Apply_Contract(
12910           p_coverage_id           => x_charges_detail_rec.contract_line_id,
12911           p_coverage_txn_group_id => x_charges_detail_rec.coverage_txn_group_id,
12912           p_txn_billing_type_id   => x_charges_detail_rec.txn_billing_type_id,
12913           P_BUSINESS_PROCESS_ID   => x_charges_detail_rec.business_process_id,
12914           P_REQUEST_DATE          => l_request_date,
12915           p_amount                => x_charges_detail_rec.after_warranty_cost,
12916           p_discount_amount       => l_contract_discount,
12917           X_RETURN_STATUS         => l_return_status,
12918           X_MSG_COUNT             => l_msg_count,
12919           X_MSG_DATA              => l_msg_data);
12920 
12921       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
12922         FND_MESSAGE.Set_Name('CS', 'CS_CHG_APPLY_CONTRACT_WARNING');
12923         FND_MESSAGE.SET_TOKEN('REASON', l_msg_data);
12924         FND_MSG_PUB.Add;
12925         RAISE FND_API.G_EXC_ERROR;
12926       END IF;
12927 
12928       --Bug Fix for Bug # 3088397
12929       IF l_contract_discount IS NOT NULL THEN
12930         --assign the contract discount to the out record
12931         x_charges_detail_rec.contract_discount_amount := x_charges_detail_rec.after_warranty_cost - l_contract_discount;
12932 
12933         --apply discount
12934         x_charges_detail_rec.after_warranty_cost := l_contract_discount;
12935 
12936        ELSE
12937           -- contract discount amt should be 0
12938           --x_charges_detail_rec.contract_discount_amount := 0;
12939           null;
12940       END IF;
12941       --DBMS_OUTPUT.PUT_LINE('Contract 8'||x_charges_detail_rec.contract_discount_amount);
12942 
12943       --DBMS_OUTPUT.PUT_LINE('Contract Amount '||x_charges_detail_rec.contract_discount_amount );
12944 
12945     ELSE
12946       --Apply contract discount = 'N'
12947       --Fixed Bug # 3220253
12948       --passed p_charges_detail_rec.contract_discount_amount
12949       x_charges_detail_rec.apply_contract_discount := p_charges_detail_rec.apply_contract_discount;
12950       IF p_charges_detail_rec.contract_discount_amount <> FND_API.G_MISS_NUM OR
12951          p_charges_detail_rec.contract_discount_amount IS NOT NULL THEN
12952         x_charges_detail_rec.contract_discount_amount := l_db_rec.contract_discount_amount;
12953       ELSIF p_charges_detail_rec.contract_discount_amount IS NULL THEN
12954         x_charges_detail_rec.contract_discount_amount := 0;
12955       ELSE
12956         x_charges_detail_rec.contract_discount_amount := p_charges_detail_rec.contract_discount_amount;
12957       END IF;
12958     END IF ;
12959    END IF;
12960   END IF;
12961   IF   l_line_order_category_code = 'ORDER' THEN      --Bug 6960562
12962   /* Start : 5705568 */
12963 --    If x_charges_detail_rec.after_warranty_cost < 0  Then
12964   If x_charges_detail_rec.after_warranty_cost < 0  and x_charges_detail_rec.line_category_code <> 'RETURN' Then  -- bug 7459205
12965      x_charges_detail_rec.after_warranty_cost := 0;
12966   End If;
12967   /* End : 5705568 */
12968   End If;
12969 END IF;
12970 
12971 --==================================
12972 --final re-set of no_charge_flag
12973 --if after_warranty_cost <> 0
12974 --Fixed Bug # 3468146
12975 --since the line has come with after warranty cost from upstream
12976 IF x_charges_detail_rec.after_warranty_cost <> 0 THEN
12977   x_charges_detail_rec.no_charge_flag := 'N';
12978 END IF;
12979 
12980 
12981 --===================================
12982 --Validate Transaction Inventory Org
12983 --===================================
12984 --DBMS_OUTPUT.PUT_LINE('Validate Transaction Inventory Org ...');
12985 --DBMS_OUTPUT.PUT_LINE('p_charges_detail_rec.transaction_inventory_org = '||p_charges_detail_rec.transaction_inventory_org);
12986 IF p_validation_mode = 'I' THEN
12987   IF p_charges_detail_rec.transaction_inventory_org IS NOT NULL THEN
12988     l_valid_check := IS_TXN_INV_ORG_VALID(p_txn_inv_org   => p_charges_detail_rec.transaction_inventory_org,
12989                             --p_org_id         => l_org_id,
12990                             p_org_id           => x_charges_detail_rec.org_id,
12991                             x_msg_data         => l_msg_data,
12992                             x_msg_count        => l_msg_count,
12993                             x_return_status    => l_return_status  ) ;
12994 
12995       IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
12996         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
12997       ELSIF l_return_status = G_RET_STS_ERROR THEN
12998         RAISE FND_API.G_EXC_ERROR;
12999       END IF;
13000 
13001       IF l_valid_check <> 'Y' THEN
13002         FND_MESSAGE.Set_Name('CS', 'CS_CHG_INVALID_TXN_INV_ORG');
13003         FND_MESSAGE.Set_Token('ORG_ID', p_charges_detail_rec.transaction_inventory_org);
13004         FND_MSG_PUB.Add;
13005         RAISE FND_API.G_EXC_ERROR;
13006       END IF;
13007 
13008   END IF;
13009   x_charges_detail_rec.transaction_inventory_org := p_charges_detail_rec.transaction_inventory_org;
13010 
13011 ELSIF p_validation_mode = 'U' THEN
13012   -- assign from db record
13013   -- need to find out if we can update the transaction_inventory_org
13014   --
13015 
13016   IF p_charges_detail_rec.transaction_inventory_org <> FND_API.G_MISS_NUM AND
13017      p_charges_detail_rec.transaction_inventory_org IS NOT NULL THEN
13018 
13019      l_valid_check := IS_TXN_INV_ORG_VALID
13020                            (p_txn_inv_org   => p_charges_detail_rec.transaction_inventory_org,
13021                             p_org_id           => x_charges_detail_rec.org_id,
13022                             x_msg_data         => l_msg_data,
13023                             x_msg_count        => l_msg_count,
13024                             x_return_status    => l_return_status  ) ;
13025 
13026       IF l_return_status = G_RET_STS_UNEXP_ERROR THEN
13027         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
13028       ELSIF l_return_status = G_RET_STS_ERROR THEN
13029         RAISE FND_API.G_EXC_ERROR;
13030       END IF;
13031 
13032       IF l_valid_check <> 'Y' THEN
13033         FND_MESSAGE.Set_Name('CS', 'CS_CHG_INVALID_TXN_INV_ORG');
13034         FND_MESSAGE.Set_Token('ORG_ID', p_charges_detail_rec.transaction_inventory_org);
13035         FND_MSG_PUB.Add;
13036         RAISE FND_API.G_EXC_ERROR;
13037       END IF;
13038 
13039       x_charges_detail_rec.transaction_inventory_org := p_charges_detail_rec.transaction_inventory_org;
13040 
13041   ELSIF p_charges_detail_rec.transaction_inventory_org  = FND_API.G_MISS_NUM THEN
13042       x_charges_detail_rec.transaction_inventory_org := l_db_det_rec.transaction_inventory_org;
13043   ELSE
13044       x_charges_detail_rec.transaction_inventory_org := NULL;
13045   END IF;
13046 
13047 END IF;
13048 
13049 --DBMS_OUTPUT.PUT_LINE('Validate Transaction Inventory Org completed. x_charges_detail_rec.transaction_inventory_org = '|| x_charges_detail_rec.transaction_inventory_org);
13050 
13051 
13052 --===================================
13053 -- Validate Order Information
13054 --===================================
13055 --DBMS_OUTPUT.PUT_LINE('Validate Order Information ...');
13056 
13057 IF p_validation_mode = 'I' THEN
13058 
13059   IF x_charges_detail_rec.add_to_order_flag = 'Y' AND
13060      x_charges_detail_rec.interface_to_oe_flag = 'Y' THEN
13061 
13062     IF p_charges_detail_rec.order_header_id IS NULL THEN
13063 
13064       --Charges needs a order number when interfaceing
13065       --to OM if add to order flag = 'Y'
13066 
13067       --RAISE FND_API.G_EXC_ERROR;
13068       --null;
13069       FND_MESSAGE.Set_Name('CS', 'CS_CHG_ORDER_NUMBER_REQUIRED');
13070       FND_MSG_PUB.Add;
13071       RAISE FND_API.G_EXC_ERROR;
13072     ELSE
13073 
13074       -- If order number provided then validate the order
13075 
13076       Validate_Order(
13077         p_api_name           => p_api_name,
13078         p_order_header_id    => p_charges_detail_rec.order_header_id,
13079         --p_org_id           => l_org_id,
13080         p_org_id             => x_charges_detail_rec.org_id,
13081         x_return_status      => l_return_status,
13082         x_msg_count          => l_msg_count,
13083         x_msg_data           => l_msg_data);
13084 
13085       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
13086 
13087         --RAISE FND_API.G_EXC_ERROR ;
13088         FND_MESSAGE.Set_Name('CS', 'CS_CHG_INVALID_ORDER');
13089         FND_MESSAGE.SET_TOKEN('ORDER_HEADER_ID', p_charges_detail_rec.order_header_id);
13090         --FND_MESSAGE.SET_TOKEN('TEXT', l_msg_data, TRUE);
13091         FND_MSG_PUB.Add;
13092         RAISE FND_API.G_EXC_ERROR;
13093       ELSE
13094 
13095         x_charges_detail_rec.order_header_id := p_charges_detail_rec.order_header_id;
13096         x_charges_detail_rec.order_line_id :=  p_charges_detail_rec.order_line_id;
13097 
13098       END IF;
13099 
13100     END IF;
13101 
13102    ELSE
13103 
13104    --If the add_to_order_flag = 'Y' and order is provided
13105 
13106     IF x_charges_detail_rec.add_to_order_flag = 'Y' AND
13107        p_charges_detail_rec.order_header_id IS NOT NULL THEN
13108 
13109       Validate_Order(
13110         p_api_name           => p_api_name,
13111         p_order_header_id    => p_charges_detail_rec.order_header_id,
13112         --p_org_id           => l_org_id,
13113         p_org_id             => x_charges_detail_rec.org_id,
13114         x_return_status      => l_return_status,
13115         x_msg_count          => l_msg_count,
13116         x_msg_data           => l_msg_data);
13117 
13118       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
13119 
13120         --RAISE FND_API.G_EXC_ERROR ;
13121         FND_MESSAGE.Set_Name('CS', 'CS_CHG_INVALID_ORDER');
13122         FND_MESSAGE.SET_TOKEN('ORDER_HEADER_ID', p_charges_detail_rec.order_header_id);
13123         --FND_MESSAGE.SET_TOKEN('TEXT', l_msg_data, TRUE);
13124         FND_MSG_PUB.Add;
13125         RAISE FND_API.G_EXC_ERROR;
13126 
13127       ELSE
13128 
13129          x_charges_detail_rec.order_header_id := p_charges_detail_rec.order_header_id;
13130         x_charges_detail_rec.order_line_id :=  p_charges_detail_rec.order_line_id;
13131 
13132       END IF;
13133 
13134     --In all other cases
13135 
13136     ELSE
13137 
13138       x_charges_detail_rec.order_line_id := NULL;
13139       x_charges_detail_rec.order_header_id := NULL;
13140 
13141     END IF;
13142  END IF;
13143 
13144 ELSIF p_validation_mode = 'U' THEN
13145 
13146  IF l_db_det_rec.order_line_id IS NULL THEN
13147 
13148    IF x_charges_detail_rec.add_to_order_flag = 'Y' AND
13149       x_charges_detail_rec.interface_to_oe_flag = 'Y' THEN
13150 
13151 
13152      IF p_charges_detail_rec.order_header_id <> FND_API.G_MISS_NUM AND
13153         p_charges_detail_rec.order_header_id IS NOT NULL THEN
13154 
13155          Validate_Order(
13156                p_api_name           => p_api_name,
13157                p_order_header_id    => p_charges_detail_rec.order_header_id,
13158                p_org_id             => x_charges_detail_rec.org_id,
13159                x_return_status      => l_return_status,
13160                x_msg_count          => l_msg_count,
13161                x_msg_data           => l_msg_data);
13162 
13163          IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
13164            --RAISE FND_API.G_EXC_ERROR ;
13165            FND_MESSAGE.Set_Name('CS', 'CS_CHG_INVALID_ORDER');
13166            FND_MESSAGE.SET_TOKEN('ORDER_HEADER_ID', p_charges_detail_rec.order_header_id);
13167            FND_MSG_PUB.Add;
13168            RAISE FND_API.G_EXC_ERROR;
13169          ELSE
13170             x_charges_detail_rec.order_header_id := p_charges_detail_rec.order_header_id;
13171          END IF;
13172 
13173      ELSIF p_charges_detail_rec.order_header_id = FND_API.G_MISS_NUM THEN
13174        IF  l_db_det_rec.order_header_id IS NOT NULL THEN
13175          x_charges_detail_rec.order_header_id := l_db_det_rec.order_header_id;
13176        ELSE
13177          --order number required
13178          FND_MESSAGE.Set_Name('CS', 'CS_CHG_ORDER_NUMBER_REQUIRED');
13179          FND_MSG_PUB.Add;
13180          RAISE FND_API.G_EXC_ERROR;
13181        END IF;
13182      ELSE
13183        --order number not passed
13184        --order number required
13185        FND_MESSAGE.Set_Name('CS', 'CS_CHG_ORDER_NUMBER_REQUIRED');
13186        FND_MSG_PUB.Add;
13187        RAISE FND_API.G_EXC_ERROR;
13188      END IF;
13189 
13190 
13191    ELSE
13192      --If the add_to_order_flag = 'Y' and order is provided
13193      IF x_charges_detail_rec.add_to_order_flag = 'Y' AND
13194         p_charges_detail_rec.order_header_id <> FND_API.G_MISS_NUM AND
13195         p_charges_detail_rec.order_header_id IS NOT NULL THEN
13196 
13197       Validate_Order(
13198         p_api_name           => p_api_name,
13199         p_order_header_id    => p_charges_detail_rec.order_header_id,
13200         --p_org_id           => l_org_id,
13201         p_org_id             => x_charges_detail_rec.org_id,
13202         x_return_status      => l_return_status,
13203         x_msg_count          => l_msg_count,
13204         x_msg_data           => l_msg_data);
13205 
13206       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
13207 
13208         --RAISE FND_API.G_EXC_ERROR ;
13209         FND_MESSAGE.Set_Name('CS', 'CS_CHG_INVALID_ORDER');
13210         FND_MESSAGE.SET_TOKEN('ORDER_HEADER_ID', p_charges_detail_rec.order_header_id);
13211         --FND_MESSAGE.SET_TOKEN('TEXT', l_msg_data, TRUE);
13212         FND_MSG_PUB.Add;
13213         RAISE FND_API.G_EXC_ERROR;
13214 
13215       ELSE
13216 
13217         x_charges_detail_rec.order_header_id := p_charges_detail_rec.order_header_id;
13218         x_charges_detail_rec.order_line_id :=  p_charges_detail_rec.order_line_id;
13219 
13220       END IF;
13221 
13222      --In all other cases
13223 
13224     ELSE
13225 
13226       x_charges_detail_rec.order_line_id := NULL;
13227       x_charges_detail_rec.order_header_id := NULL;
13228 
13229     END IF;
13230    END IF;
13231  ELSE
13232 
13233    --cannot add to order
13234    --line already interfaced to om
13235    --raise error
13236    FND_MESSAGE.SET_NAME('CS', 'CS_CHG_CANNOT_ADD_CHG_TO_ORDER');
13237    FND_MESSAGE.SET_TOKEN('API_NAME', p_api_name);
13238    FND_MSG_PUB.Add;
13239    RAISE FND_API.G_EXC_ERROR;
13240  END IF;
13241 END IF;
13242 
13243 
13244 --===================================
13245 --Validate Purchase Order Information
13246 --===================================
13247 --DBMS_OUTPUT.PUT_LINE('Validate Purchase Order Information ...');
13248 
13249 IF p_validation_mode = 'I' THEN
13250   IF p_charges_detail_rec.purchase_order_num IS NOT NULL THEN
13251     -- assign to out record
13252     x_charges_detail_rec.purchase_order_num := p_charges_detail_rec.purchase_order_num;
13253   ELSE
13254     IF l_cust_po_number IS NOT NULL THEN
13255       -- assign the customer po number from service
13256       x_charges_detail_rec.purchase_order_num := l_cust_po_number;
13257     ELSE
13258       -- get the po number from contracts of a contract exists
13259       IF l_po_number IS NOT NULL THEN
13260         x_charges_detail_rec.purchase_order_num := l_po_number;
13261       ELSE
13262         x_charges_detail_rec.purchase_order_num := null;
13263       END IF;
13264     END IF;
13265   END IF;
13266 ELSIF p_validation_mode = 'U' THEN
13267   -- bug Fix for Bug # 3084256
13268   IF p_charges_detail_rec.purchase_order_num <> FND_API.G_MISS_CHAR AND
13269      p_charges_detail_rec.purchase_order_num IS NOT NULL THEN
13270      x_charges_detail_rec.purchase_order_num := p_charges_detail_rec.purchase_order_num;
13271   ELSIF
13272      p_charges_detail_rec.purchase_order_num = FND_API.G_MISS_CHAR THEN
13273      x_charges_detail_rec.purchase_order_num := l_db_det_rec.purchase_order_num;
13274   ELSE
13275      --null is passed
13276      x_charges_detail_rec.purchase_order_num := null;
13277   END IF;
13278 END IF;
13279 
13280 
13281 --====================================
13282 --Validate Billing Engine Information
13283 --====================================
13284 --DBMS_OUTPUT.PUT_LINE('Validate Billing Engine Information ...');
13285 
13286 IF p_validation_mode = 'I' THEN
13287 
13288   IF p_charges_detail_rec.generated_by_bca_engine IS NULL THEN
13289     x_charges_detail_rec.generated_by_bca_engine := 'N';
13290   ELSE
13291     x_charges_detail_rec.generated_by_bca_engine := p_charges_detail_rec.generated_by_bca_engine;
13292   END IF;
13293 
13294   x_charges_detail_rec.activity_start_time := p_charges_detail_rec.activity_start_time;
13295   x_charges_detail_rec.activity_end_time := p_charges_detail_rec.activity_end_time;
13296 
13297   --DBMS_OUTPUT.PUT_LINE('Customer Product Id '||x_charges_detail_rec.customer_product_id);
13298 
13299 END IF;
13300 
13301 
13302   --DBMS_OUTPUT.PUT_LINE('ORDER_LINE_ID IS '||x_charges_detail_rec.order_line_id);
13303 
13304 
13305 --=================================
13306 --Assign to out record --
13307 --=================================
13308 
13309    -- Exception Block
13310    EXCEPTION
13311 
13312       WHEN FND_API.G_EXC_ERROR THEN
13313         ROLLBACK TO Validate_Charge_Details_PUB;
13314 
13315         x_return_status := FND_API.G_RET_STS_ERROR;
13316         FND_MSG_PUB.Count_And_Get(
13317           p_count => x_msg_count,
13318           p_data  => x_msg_data,
13319           p_encoded => FND_API.G_FALSE);
13320 
13321       WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
13322         ROLLBACK TO Validate_Charge_Details_PUB;
13323         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
13324         FND_MSG_PUB.Count_And_Get(
13325           p_count => x_msg_count,
13326           p_data  => x_msg_data,
13327           p_encoded => FND_API.G_FALSE);
13328 
13329       WHEN OTHERS THEN
13330         ROLLBACK TO Validate_Charge_Details_PUB;
13331         FND_MESSAGE.SET_NAME('CS', 'CS_CHG_UNEXPECTED_EXEC_ERRORS');
13332         FND_MESSAGE.SET_TOKEN('ROUTINE', l_api_name);
13333         FND_MESSAGE.SET_TOKEN('SQLERRM', sqlerrm);
13334         FND_MSG_PUB.ADD;
13335         IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
13336           FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME,l_api_name);
13337         END IF ;
13338         fnd_msg_pub.count_and_get(
13339            p_count => x_msg_count
13340           ,p_data  => x_msg_data);
13341         x_return_status := FND_API.G_RET_STS_ERROR;
13342 
13343 END VALIDATE_CHARGE_DETAILS;
13344 
13345 
13346 --==================================
13347 -- Get Defaults from Service Request
13348 --==================================
13349 
13350 PROCEDURE GET_SR_DEFAULTS(P_API_NAME               IN          VARCHAR2,
13351                           P_INCIDENT_ID            IN          NUMBER,
13352                           X_BUSINESS_PROCESS_ID    OUT NOCOPY  NUMBER,
13353                           X_CUSTOMER_ID            OUT NOCOPY  NUMBER,
13354                           X_CUSTOMER_SITE_ID       OUT NOCOPY  NUMBER,
13355                           X_CUST_PO_NUMBER         OUT NOCOPY  VARCHAR2,
13356                           X_CUSTOMER_PRODUCT_ID    OUT NOCOPY  NUMBER,
13357                           X_SYSTEM_ID              OUT NOCOPY  NUMBER, -- Fix bug
13358                           X_INVENTORY_ITEM_ID      OUT NOCOPY  NUMBER, -- Fix bug
13359                           X_ACCOUNT_ID             OUT NOCOPY  NUMBER,
13360                           X_BILL_TO_PARTY_ID       OUT NOCOPY  NUMBER,
13361                           X_BILL_TO_ACCOUNT_ID     OUT NOCOPY  NUMBER,
13362                           X_BILL_TO_CONTACT_ID     OUT NOCOPY  NUMBER,
13363                           X_BILL_TO_SITE_ID        OUT NOCOPY  NUMBER,
13364                           X_SHIP_TO_PARTY_ID       OUT NOCOPY  NUMBER,
13365                           X_SHIP_TO_ACCOUNT_ID     OUT NOCOPY  NUMBER,
13366                           X_SHIP_TO_CONTACT_ID     OUT NOCOPY  NUMBER,
13367                           X_SHIP_TO_SITE_ID        OUT NOCOPY  NUMBER,
13368                           X_CONTRACT_ID            OUT NOCOPY  NUMBER,
13369                           X_CONTRACT_SERVICE_ID    OUT NOCOPY  NUMBER,
13370                           X_INCIDENT_DATE          OUT NOCOPY  DATE,
13371                           X_CREATION_DATE          OUT NOCOPY  DATE,
13372                           X_MSG_DATA               OUT NOCOPY  VARCHAR2,
13373                           X_MSG_COUNT              OUT NOCOPY  NUMBER,
13374                           X_RETURN_STATUS          OUT NOCOPY  VARCHAR2) IS
13375 
13376 
13377 CURSOR c_incidents_def(p_incident_id IN NUMBER) IS
13378 
13379   SELECT intp.business_process_id,
13380             inc.customer_id,
13381             inc.customer_site_id,
13382             inc.contract_id,
13383             inc.contract_service_id,
13384             inc.customer_po_number,
13385             inc.customer_product_id,
13386             inc.system_id,         -- Fix bug
13387             inc.inventory_item_id, -- Fix bug
13388             inc.account_id,
13389             inc.incident_date,
13390             inc.creation_date,
13391             substr(hza.account_name,1,30),
13392             NVL(inc.bill_to_party_id, -999)  bill_to_party_id,
13393             NVL(inc.ship_to_party_id, -999)  ship_to_party_id,
13394             NVL(inc.bill_to_site_id,-999),bill_to_site_id,
13395             NVL(inc.ship_to_site_id,-999)ship_to_site_id,
13396 	    NVL(inc.bill_to_account_id,-999) bill_to_account_id,
13397 	    NVL(inc.ship_to_account_id,-999) ship_to_account_id,
13398 	    NVL(inc.bill_to_contact_id,-999) bill_to_contact_id,
13399 	    NVL(inc.ship_to_contact_id,-999) ship_to_contact_id,
13400 	    inc.caller_type
13401      FROM   cs_incidents_all_b inc,
13402             CS_INCIDENT_TYPES intp,
13403             CS_BUSINESS_PROCESSES bp,
13404             hz_parties hzp,
13405             hz_cust_accounts hza
13406      WHERE  inc.incident_id = p_incident_id
13407      AND    inc.incident_type_id = intp.incident_type_id
13408      AND    intp.business_process_id = bp.business_process_id
13409      AND    inc.customer_id = hzp.party_id
13410      AND    inc.account_id  = hza.cust_account_id(+);
13411 
13412 
13413 
13414 
13415 BEGIN
13416 
13417   x_return_status :=  FND_API.G_RET_STS_SUCCESS;
13418 
13419   FOR v_incidents_def IN c_incidents_def(p_incident_id) LOOP
13420 
13421     x_business_process_id    :=  v_incidents_def.business_process_id;
13422     x_customer_id            :=  v_incidents_def.customer_id;
13423     x_customer_site_id       :=  v_incidents_def.customer_site_id;
13424     x_cust_po_number         :=  v_incidents_def.customer_po_number;
13425     x_customer_product_id    :=  v_incidents_def.customer_product_id;
13426     x_system_id              :=  v_incidents_def.system_id;
13427     x_inventory_item_id      :=  v_incidents_def.inventory_item_id;
13428     x_account_id             :=  v_incidents_def.account_id;
13429     x_bill_to_party_id       :=  v_incidents_def.bill_to_party_id;
13430     x_bill_to_account_id     :=  v_incidents_def.bill_to_account_id;
13431     x_bill_to_contact_id     :=  v_incidents_def.bill_to_contact_id;
13432     x_bill_to_site_id        :=  v_incidents_def.bill_to_site_id;
13433     x_ship_to_party_id       :=  v_incidents_def.ship_to_party_id;
13434     x_ship_to_account_id     :=  v_incidents_def.ship_to_account_id;
13435     x_ship_to_contact_id     :=  v_incidents_def.ship_to_contact_id;
13436     x_ship_to_site_id        :=  v_incidents_def.ship_to_site_id;
13437     x_contract_id            :=  v_incidents_def.contract_id;
13438     x_contract_service_id    :=  v_incidents_def.contract_service_id;
13439     x_incident_date          :=  v_incidents_def.incident_date;
13440     x_creation_date          :=  v_incidents_def.creation_date;
13441 
13442   END LOOP;
13443 
13444   EXCEPTION
13445 
13446     WHEN OTHERS THEN
13447       x_return_status :=  FND_API.G_RET_STS_ERROR;
13448       fnd_msg_pub.count_and_get(
13449         p_count => x_msg_count,
13450         p_data  => x_msg_data);
13451 
13452 END GET_SR_DEFAULTS;
13453 
13454 --================================
13455 --Validate Transaction Type Id
13456 --================================
13457 PROCEDURE VALIDATE_TXN_TYPE(P_API_NAME                  IN         VARCHAR2,
13458                             P_BUSINESS_PROCESS_ID       IN         NUMBER,
13459                             P_TXN_TYPE_ID               IN         NUMBER,
13460                             P_SOURCE_CODE               IN         VARCHAR2,
13461                             X_LINE_ORDER_CATEGORY_CODE  OUT NOCOPY VARCHAR2,
13462                             X_NO_CHARGE_FLAG            OUT NOCOPY VARCHAR2,
13463                             X_INTERFACE_TO_OE_FLAG      OUT NOCOPY VARCHAR2,
13464                             X_UPDATE_IB_FLAG            OUT NOCOPY VARCHAR2,
13465                             X_SRC_REFERENCE_REQD_FLAG   OUT NOCOPY VARCHAR2,
13466                             X_SRC_RETURN_REQD_FLAG      OUT NOCOPY VARCHAR2,
13467                             X_NON_SRC_REFERENCE_REQD    OUT NOCOPY VARCHAR2,
13468                             X_NON_SRC_RETURN_REQD       OUT NOCOPY VARCHAR2,
13469                             X_MSG_DATA                  OUT NOCOPY VARCHAR2,
13470                             X_MSG_COUNT                 OUT NOCOPY NUMBER,
13471                             X_RETURN_STATUS             OUT NOCOPY VARCHAR2) IS
13472 
13473 Cursor c_txn_type(p_txn_type_id         IN NUMBER,
13474                   p_business_process_id IN NUMBER) IS
13475 SELECT  tt.transaction_type_id,
13476         NVL(citt.src_reference_reqd,'N') src_reference_reqd,
13477         NVL(citt.src_return_reqd,'N') src_return_reqd,
13478         citt.src_change_owner_to_code,
13479         NVL(citt.non_src_reference_reqd,'N') non_src_reference_reqd,
13480         NVL(citt.non_src_return_reqd,'N') non_src_return_reqd,
13481         citt.non_src_change_owner_to_code,
13482         NVL(csit.update_ib_flag,'N') update_ib_flag,
13483         nvl(tt.no_charge_flag, 'N') no_charge_flag,
13484         nvl(tt.interface_to_oe_flag, 'N')interface_to_oe_flag,
13485         tt.line_order_category_code,
13486         ol.meaning line_category_meaning
13487 FROM    CS_TRANSACTION_TYPES_VL  tt,
13488         CS_BUS_PROCESS_TXNS  bt,
13489         csi_ib_txn_types citt,
13490         csi_source_ib_types csit,
13491         CSI_TXN_TYPES ctt,
13492         OE_LOOKUPS ol
13493 WHERE  tt.transaction_type_id = p_txn_type_id
13494   and  bt.business_process_id = p_business_process_id
13495   and  bt.transaction_type_id = tt.transaction_type_id
13496   and  tt.line_order_category_code is not null
13497   and  ol.lookup_code = tt.line_order_category_code
13498   and  ol.lookup_type = 'LINE_CATEGORY'
13499   and  tt.transaction_type_id = citt.cs_transaction_type_id (+)
13500   and nvl(citt.parent_reference_reqd, 'N') = 'N'
13501   and nvl(ctt.source_transaction_type, 'OM_SHIPMENT') =
13502   decode(tt.line_order_category_code, 'ORDER', 'OM_SHIPMENT',
13503   nvl(ctt.source_transaction_type, 'OM_SHIPMENT'))
13504   and nvl(ctt.source_transaction_type, 'RMA_RECEIPT') =
13505   decode(tt.line_order_category_code, 'RETURN', 'RMA_RECEIPT',
13506   nvl(ctt.source_transaction_type, 'RMA_RECEIPT'))
13507   and citt.sub_type_id = csit.sub_type_id (+)
13508   and csit.transaction_type_id = ctt.transaction_type_id (+)
13509   and nvl(ctt.source_application_id, 660) = 660
13510   and trunc(sysdate) between trunc(nvl(bt.start_date_active, sysdate))
13511   and trunc(nvl(bt.end_date_active, sysdate));
13512 
13513 
13514 
13515 
13516 Cursor c_txn_type_sd(p_txn_type_id         IN NUMBER,
13517                      p_business_process_id IN NUMBER) IS
13518 SELECT  tt.transaction_type_id,
13519         nvl(tt.no_charge_flag, 'N') no_charge_flag,
13520         nvl(tt.interface_to_oe_flag, 'N')interface_to_oe_flag,
13521         tt.line_order_category_code,
13522         ol.meaning line_category_meaning
13523 FROM    CS_TRANSACTION_TYPES_VL  tt,
13524         CS_BUS_PROCESS_TXNS  bt,
13525         OE_LOOKUPS ol
13526 WHERE  tt.transaction_type_id = p_txn_type_id
13527   and  bt.business_process_id = p_business_process_id
13528   and  bt.transaction_type_id = tt.transaction_type_id
13529   and  tt.line_order_category_code is not null
13530   and  ol.lookup_code = tt.line_order_category_code
13531   and  ol.lookup_type = 'LINE_CATEGORY'
13532   and trunc(sysdate) between trunc(nvl(bt.start_date_active, sysdate))
13533   and trunc(nvl(bt.end_date_active, sysdate));
13534 
13535   lv_exists_flag VARCHAR2(1) := 'N';
13536 
13537 BEGIN
13538   -- Initialize API return status to success
13539   x_return_status := FND_API.G_RET_STS_SUCCESS;
13540 
13541   --DBMS_OUTPUT.PUT_LINE(' Source Code = :'||p_source_code);
13542 
13543   IF p_source_code <> 'SD' THEN
13544 
13545     FOR v_txn_type IN c_txn_type(p_txn_type_id, p_business_process_id) LOOP
13546       lv_exists_flag := 'Y';
13547 
13548       -- Check with Anu if this logic is OK here
13549       IF v_txn_type.line_order_category_code = 'RETURN' THEN
13550         IF v_txn_type.src_change_owner_to_code = 'E' THEN
13551           --RAISE FND_API.G_EXC_ERROR;
13552           --null;
13553           FND_MESSAGE.Set_Name('CS', 'CS_CHG_INVALID_TXN_TYPE_OWNER');
13554           FND_MESSAGE.SET_TOKEN('TXN_TYPE_ID', p_txn_type_id);
13555           FND_MSG_PUB.Add;
13556           RAISE FND_API.G_EXC_ERROR;
13557         END IF;
13558 
13559       ELSIF v_txn_type.line_order_category_code = 'ORDER' THEN
13560         IF v_txn_type.non_src_change_owner_to_code = 'E' THEN
13561           --RAISE FND_API.G_EXC_ERROR;
13562           --null;
13563           FND_MESSAGE.Set_Name('CS', 'CS_CHG_INVALID_TXN_TYPE_OWNER');
13564           FND_MESSAGE.SET_TOKEN('TXN_TYPE_ID', p_txn_type_id);
13565           FND_MSG_PUB.Add;
13566           RAISE FND_API.G_EXC_ERROR;
13567         END IF;
13568       END IF;
13569 
13570       x_line_order_category_code  := v_txn_type.line_order_category_code;
13571       x_no_charge_flag            := v_txn_type.no_charge_flag;
13572       x_interface_to_oe_flag      := v_txn_type.interface_to_oe_flag;
13573       x_update_ib_flag            := v_txn_type.update_ib_flag;
13574       x_src_reference_reqd_flag   := v_txn_type.src_reference_reqd;
13575       x_src_return_reqd_flag      := v_txn_type.src_return_reqd;
13576       x_non_src_reference_reqd    := v_txn_type.non_src_reference_reqd;
13577       x_non_src_return_reqd       := v_txn_type.non_src_return_reqd;
13578 
13579     END LOOP;
13580 
13581   ELSE
13582 
13583      FOR v_txn_type_sd IN c_txn_type_sd(p_txn_type_id, p_business_process_id) LOOP
13584       lv_exists_flag := 'Y';
13585 
13586       x_line_order_category_code  := v_txn_type_sd.line_order_category_code;
13587       x_no_charge_flag            := v_txn_type_sd.no_charge_flag;
13588       x_interface_to_oe_flag      := v_txn_type_sd.interface_to_oe_flag;
13589      END LOOP;
13590   END IF;
13591 
13592 
13593 
13594   IF lv_exists_flag = 'N' THEN
13595     FND_MESSAGE.Set_Name('CS', 'CS_CHG_INVALID_TXN_TYPE');
13596     FND_MESSAGE.SET_TOKEN('TXN_TYPE_ID', p_txn_type_id);
13597     FND_MESSAGE.SET_TOKEN('BUSINESS_PROCESS_ID', p_business_process_id);
13598     FND_MSG_PUB.Add;
13599 
13600     RAISE FND_API.G_EXC_ERROR;
13601 
13602   END IF;
13603 
13604   EXCEPTION
13605     WHEN FND_API.G_EXC_ERROR THEN
13606       x_return_status := FND_API.G_RET_STS_ERROR;
13607       fnd_msg_pub.count_and_get(
13608       p_count => x_msg_count
13609      ,p_data  => x_msg_data);
13610 
13611 
13612     WHEN OTHERS THEN
13613       x_return_status := FND_API.G_RET_STS_ERROR;
13614       FND_MESSAGE.Set_Name('CS', 'CS_CHG_INVALID_TXN_TYPE');
13615       FND_MESSAGE.SET_TOKEN('TXN_TYPE_ID', p_txn_type_id);
13616       FND_MESSAGE.SET_TOKEN('BUSINESS_PROCESS_ID', p_business_process_id);
13617       FND_MSG_PUB.Add;
13618 
13619       fnd_msg_pub.count_and_get(
13620       p_count => x_msg_count
13621      ,p_data  => x_msg_data);
13622 
13623 
13624 
13625 
13626 END VALIDATE_TXN_TYPE;
13627 
13628 
13629 --=================================
13630 -- Validate Inventory Item ID
13631 --=================================
13632 PROCEDURE VALIDATE_ITEM(P_API_NAME             IN         VARCHAR2,
13633                         P_INV_ID               IN         NUMBER,
13634                         P_UPDATE_IB_FLAG       IN         VARCHAR2,
13635                         X_COMMS_TRACKABLE_FLAG OUT NOCOPY VARCHAR2,
13636                         X_SERIAL_CONTROL_FLAG  OUT NOCOPY VARCHAR2,
13637                         X_REV_CONTROL_FLAG     OUT NOCOPY VARCHAR2,
13638                         X_MSG_DATA             OUT NOCOPY VARCHAR2,
13639                         X_MSG_COUNT            OUT NOCOPY NUMBER,
13640                         X_RETURN_STATUS        OUT NOCOPY VARCHAR2) IS
13641 
13642 Cursor c_get_inv_item(p_inv_id NUMBER) IS
13643 SELECT inventory_item_id,
13644        serial_number_control_code,
13645        revision_qty_control_code,
13646        nvl(comms_nl_trackable_flag, 'N') comms_nl_trackable_flag
13647        -- contract_item_type_code -- Fix for Bug # 3109160
13648  FROM MTL_SYSTEM_ITEMS_KFV
13649 WHERE organization_id = cs_std.get_item_valdn_orgzn_id
13650   AND inventory_item_id = p_inv_id;
13651 
13652 
13653 
13654 lv_exists_flag VARCHAR2(1) := 'N';
13655 
13656 BEGIN
13657 
13658 
13659   -- Initialize API return status to success
13660   x_return_status := FND_API.G_RET_STS_SUCCESS;
13661 
13662   --DBMS_OUTPUT.PUT_LINE('cs_std.get_item_valdn_orgzn_id = ' || cs_std.get_item_valdn_orgzn_id);
13663   --DBMS_OUTPUT.PUT_LINE('p_inv_id = ' || p_inv_id);
13664   --DBMS_OUTPUT.PUT_LINE('p_update_ib_flag = ' || p_update_ib_flag);
13665 
13666 
13667   FOR v_get_inv_item IN c_get_inv_item(p_inv_id) LOOP
13668 
13669     x_comms_trackable_flag := v_get_inv_item.comms_nl_trackable_flag;
13670 
13671       --DBMS_OUTPUT.PUT_LINE('inside loop');
13672       --DBMS_OUTPUT.PUT_LINE('comms_nl_trackable '||v_get_inv_item.comms_nl_trackable_flag);
13673 
13674     --Comment this for bug # 3809160
13675     --
13676 
13677     -- IF NOT (NVL(v_get_inv_item.contract_item_type_code, 'N') = 'N') THEN
13678     -- lv_exists_flag := 'N';
13679     -- --RAISE FND_API.G_EXC_ERROR;
13680     -- FND_MESSAGE.Set_Name('CS', 'CS_CHG_CONTRACT_ITEM_ERROR');
13681     -- FND_MESSAGE.SET_TOKEN('INVENTORY_ITEM_ID', p_inv_id, TRUE);
13682     -- FND_MSG_PUB.Add;
13683     -- RAISE FND_API.G_EXC_ERROR;
13684     -- END IF;
13685 
13686     ------DBMS_OUTPUT.PUT_LINE('v_get_inv_item.contract_item_type_code '||v_get_inv_item.contract_item_type_code);
13687 
13688      -- Indicator If Serial Number Controlled or not
13689     IF v_get_inv_item.serial_number_control_code <> 1 THEN
13690       x_serial_control_flag := 'Y';
13691     ELSE
13692       x_serial_control_flag := 'N';
13693     END IF;
13694 
13695     --DBMS_OUTPUT.PUT_LINE('v_get_inv_item.serial_number_control_code '||v_get_inv_item.serial_number_control_code);
13696 
13697 
13698     -- Indicator If Item Revision Controlled or not
13699     IF v_get_inv_item.revision_qty_control_code <> 1 THEN
13700       x_rev_control_flag := 'Y';
13701     ELSE
13702       x_rev_control_flag := 'N';
13703     END IF;
13704 
13705     lv_exists_flag := 'Y';
13706 
13707   END LOOP;
13708   --DBMS_OUTPUT.PUT_LINE('lv_exists_flag '||lv_exists_flag);
13709 
13710   IF lv_exists_flag = 'N' THEN
13711    -- --DBMS_OUTPUT.PUT_LINE('lv_exists_flag = ' || 'N');
13712     FND_MESSAGE.Set_Name('CS', 'CS_CHG_INVALID_INVENTORY_ITEM');
13713     FND_MESSAGE.SET_TOKEN('INVENTORY_ITEM_ID', p_inv_id);
13714     FND_MSG_PUB.Add;
13715     RAISE FND_API.G_EXC_ERROR;
13716   END IF;
13717 
13718   EXCEPTION
13719 
13720   WHEN FND_API.G_EXC_ERROR  THEN
13721     x_return_status := FND_API.G_RET_STS_ERROR;
13722     fnd_msg_pub.count_and_get(
13723       p_count => x_msg_count
13724      ,p_data  => x_msg_data);
13725 
13726   WHEN OTHERS THEN
13727     x_return_status := FND_API.G_RET_STS_ERROR;
13728     FND_MESSAGE.Set_Name('CS', 'CS_CHG_INVALID_INVENTORY_ITEM');
13729     FND_MESSAGE.SET_TOKEN('INVENTORY_ITEM_ID', p_inv_id);
13730     FND_MSG_PUB.Add;
13731     fnd_msg_pub.count_and_get(
13732       p_count => x_msg_count
13733      ,p_data  => x_msg_data);
13734 
13735 END VALIDATE_ITEM;
13736 
13737 --==============================================
13738 -- Get Item Billing Flag
13739 --==============================================
13740 
13741 PROCEDURE GET_BILLING_FLAG(
13742                  P_API_NAME            IN         VARCHAR2,
13743                  P_INV_ID              IN         NUMBER,
13744                  P_TXN_TYPE_ID         IN         NUMBER,
13745                  X_BILLING_FLAG        OUT NOCOPY VARCHAR2,
13746                  X_MSG_DATA            OUT NOCOPY VARCHAR2,
13747                  X_MSG_COUNT           OUT NOCOPY NUMBER,
13748                  X_RETURN_STATUS       OUT NOCOPY VARCHAR2) IS
13749 
13750 Cursor c_get_billing_flag(p_inv_id IN NUMBER,
13751                           p_txn_type_id IN NUMBER) IS
13752 SELECT bc.billing_category
13753   FROM cs_billing_type_categories bc,
13754   cs_txn_billing_types bt
13755   WHERE sysdate between nvl(bc.start_date_active,sysdate)
13756     AND nvl(bc.end_date_active,sysdate)
13757     AND sysdate between nvl(bt.start_date_active,sysdate)
13758                             AND nvl(bt.end_date_active,sysdate)
13759                             AND bt.billing_type = bc.billing_type
13760                             AND bt.transaction_type_id = p_txn_type_id
13761                             AND bc.billing_type IN (SELECT material_billable_flag
13762                                                       FROM MTL_SYSTEM_ITEMS_KFV
13763                                                      WHERE organization_id = cs_std.get_item_valdn_orgzn_id
13764                                                        AND inventory_item_id = p_inv_id);
13765 
13766 
13767 lv_exists_flag VARCHAR2(1) := 'N';
13768 
13769 BEGIN
13770   -- Initialize API return status to success
13771   x_return_status := FND_API.G_RET_STS_SUCCESS;
13772 
13773  -- --DBMS_OUTPUT.PUT_LINE('p_inv_id = ' || p_inv_id);
13774  -- --DBMS_OUTPUT.PUT_LINE('p_txn_type_id = ' || p_txn_type_id);
13775 
13776   FOR v_get_billing_flag in c_get_billing_flag(p_inv_id, p_txn_type_id) LOOP
13777 
13778     lv_exists_flag := 'Y';
13779     x_billing_flag := v_get_billing_flag.billing_category;
13780 
13781   END LOOP;
13782 
13783   IF lv_exists_flag <> 'Y' THEN
13784     --RAISE FND_API.G_EXC_ERROR;
13785     FND_MESSAGE.Set_Name('CS', 'CS_CHG_ITM_BILL_FLG_NOT_IN_TXN');
13786     FND_MESSAGE.SET_TOKEN('INVENTORY_ITEM_ID', p_inv_id);
13787     FND_MESSAGE.SET_TOKEN('TXN_TYPE_ID', p_txn_type_id);
13788     FND_MSG_PUB.Add;
13789     RAISE FND_API.G_EXC_ERROR;
13790   END IF;
13791 
13792   --DBMS_OUTPUT.PUT_LINE('lv_exists_flag = ' || lv_exists_flag);
13793   --DBMS_OUTPUT.PUT_LINE('x_return_status = ' || x_return_status);
13794 
13795   EXCEPTION
13796 
13797   WHEN FND_API.G_EXC_ERROR  THEN
13798     x_return_status := FND_API.G_RET_STS_ERROR;
13799     fnd_msg_pub.count_and_get(
13800       p_count => x_msg_count
13801      ,p_data  => x_msg_data);
13802 
13803   WHEN OTHERS THEN
13804     x_return_status := FND_API.G_RET_STS_ERROR;
13805     FND_MESSAGE.Set_Name('CS', 'CS_CHG_ITM_BILL_FLG_NOT_IN_TXN');
13806     FND_MESSAGE.SET_TOKEN('INVENTORY_ITEM_ID', p_inv_id);
13807     FND_MESSAGE.SET_TOKEN('TXN_TYPE_ID', p_txn_type_id);
13808     FND_MSG_PUB.Add;
13809     fnd_msg_pub.count_and_get(
13810       p_count => x_msg_count
13811      ,p_data  => x_msg_data);
13812 
13813 END GET_BILLING_FLAG;
13814 
13815 
13816 --=============================================
13817 -- Get Txn Billing Type Id
13818 --=============================================
13819 PROCEDURE GET_TXN_BILLING_TYPE(
13820                  P_API_NAME            IN         VARCHAR2,
13821                  P_INV_ID              IN         NUMBER,
13822                  P_TXN_TYPE_ID         IN         NUMBER,
13823                  X_TXN_BILLING_TYPE_ID OUT NOCOPY NUMBER,
13824                  X_MSG_DATA            OUT NOCOPY VARCHAR2,
13825                  X_MSG_COUNT           OUT NOCOPY NUMBER,
13826                  X_RETURN_STATUS       OUT NOCOPY VARCHAR2) IS
13827 
13828 Cursor c_txn_billing_type(p_inventory_item_id   IN NUMBER,
13829                           p_txn_type_id         IN NUMBER) IS
13830   SELECT ctbt.txn_billing_type_id
13831     FROM mtl_system_items_kfv kfv,
13832          cs_txn_billing_types ctbt
13833    WHERE kfv.inventory_item_id = p_inventory_item_id
13834      AND organization_id = cs_std.get_item_valdn_orgzn_id   --
13835      AND ctbt.transaction_type_id = p_txn_type_id
13836      AND ctbt.billing_type = kfv.material_billable_flag;
13837 
13838   lv_exists_flag VARCHAR2(1) := 'N';
13839 
13840 
13841 BEGIN
13842   -- Initialize API return status to success
13843   x_return_status := FND_API.G_RET_STS_SUCCESS;
13844 
13845   FOR v_txn_billing_type IN c_txn_billing_type(p_inv_id,
13846                 p_txn_type_id) LOOP
13847     x_txn_billing_type_id := v_txn_billing_type.txn_billing_type_id;
13848     lv_exists_flag := 'Y';
13849   END LOOP;
13850 
13851   IF lv_exists_flag <> 'Y' THEN
13852     --RAISE FND_API.G_EXC_ERROR;
13853     --null;
13854     FND_MESSAGE.Set_Name('CS', 'CS_CHG_ITM_BILL_TYP_NOT_IN_TXN');
13855     FND_MESSAGE.SET_TOKEN('INVENTORY_ITEM_ID', p_inv_id);
13856     FND_MESSAGE.SET_TOKEN('TXN_TYPE_ID', p_txn_type_id);
13857     FND_MSG_PUB.Add;
13858     RAISE FND_API.G_EXC_ERROR;
13859   END IF;
13860 
13861   EXCEPTION
13862 
13863   WHEN FND_API.G_EXC_ERROR  THEN
13864     x_return_status := FND_API.G_RET_STS_ERROR;
13865     fnd_msg_pub.count_and_get(
13866       p_count => x_msg_count
13867      ,p_data  => x_msg_data);
13868 
13869   WHEN OTHERS THEN
13870     x_return_status := FND_API.G_RET_STS_ERROR;
13871     FND_MESSAGE.Set_Name('CS', 'CS_CHG_ITM_BILL_TYP_NOT_IN_TXN');
13872     FND_MESSAGE.SET_TOKEN('INVENTORY_ITEM_ID', p_inv_id);
13873     FND_MESSAGE.SET_TOKEN('TXN_TYPE_ID', p_txn_type_id);
13874     FND_MSG_PUB.Add;
13875     fnd_msg_pub.count_and_get(
13876       p_count => x_msg_count
13877      ,p_data  => x_msg_data);
13878 
13879 END GET_TXN_BILLING_TYPE;
13880 
13881 
13882 --==============================================
13883 -- Get Unit Of Measure
13884 --==============================================
13885 
13886 PROCEDURE GET_UOM(P_INV_ID            IN NUMBER,
13887                   X_TBL_UOM           OUT NOCOPY TBL_UOM,
13888                   X_MSG_DATA          OUT NOCOPY VARCHAR2,
13889                   X_MSG_COUNT         OUT NOCOPY NUMBER,
13890                   X_RETURN_STATUS     OUT NOCOPY VARCHAR2) IS
13891 
13892 
13893 Cursor c_uom(p_inv_id IN NUMBER) IS
13894 SELECT   uom_code
13895   FROM   MTL_ITEM_UOMS_VIEW
13896   WHERE  inventory_item_id = P_INV_ID AND
13897          organization_id = cs_std.get_item_valdn_orgzn_id;
13898 
13899 i NUMBER := 0;
13900 
13901 BEGIN
13902   -- Initialize API return status to success
13903   x_return_status := FND_API.G_RET_STS_SUCCESS;
13904 
13905   FOR v_uom IN c_uom(p_inv_id) LOOP
13906     i := i + 1;
13907     X_TBL_UOM(i).unit_of_measure := v_uom.uom_code;
13908   END LOOP;
13909 
13910   EXCEPTION
13911 
13912   WHEN OTHERS THEN
13913     x_return_status := FND_API.G_RET_STS_ERROR;
13914     FND_MESSAGE.Set_Name('CS', 'CS_CHG_GET_UOM_FAILED');
13915     FND_MESSAGE.SET_TOKEN('INVENTORY_ITEM_ID', p_inv_id);
13916     FND_MESSAGE.SET_TOKEN('ORGANIZATION_ID', cs_std.get_item_valdn_orgzn_id);
13917     FND_MSG_PUB.Add;
13918     fnd_msg_pub.count_and_get(
13919       p_count => x_msg_count
13920      ,p_data  => x_msg_data);
13921 
13922 END GET_UOM;
13923 
13924 
13925 --================================================
13926 -- Get Primary Unit of Measure
13927 --================================================
13928 
13929 PROCEDURE GET_PRIMARY_UOM(P_INV_ID            IN NUMBER,
13930                           X_PRIMARY_UOM       OUT NOCOPY VARCHAR2,
13931                           X_MSG_DATA          OUT NOCOPY VARCHAR2,
13932                           X_MSG_COUNT         OUT NOCOPY NUMBER,
13933                           X_RETURN_STATUS     OUT NOCOPY VARCHAR2)
13934 IS
13935 
13936 Cursor c_primary_uom(p_inv_id IN NUMBER) IS
13937  SELECT mum.uom_code
13938   FROM  mtl_system_items_b msi,
13939         MTL_UNITS_OF_MEASURE_TL mum
13940  WHERE msi.PRIMARY_UNIT_OF_MEASURE = mum.unit_of_measure
13941    AND msi.INVENTORY_ITEM_ID = P_INV_ID
13942    AND msi.organization_id = cs_std.get_item_valdn_orgzn_id;
13943 
13944 lv_exists_flag VARCHAR2(1) := 'N';
13945 BEGIN
13946   -- Initialize API return status to success
13947   x_return_status := FND_API.G_RET_STS_SUCCESS;
13948 
13949   FOR v_primary_uom IN c_primary_uom(p_inv_id) LOOP
13950     lv_exists_flag := 'Y';
13951     x_primary_uom := v_primary_uom.uom_code;
13952   END LOOP;
13953 
13954   IF lv_exists_flag = 'N' THEN
13955     --RAISE FND_API.G_EXC_ERROR;
13956     --null;
13957     FND_MESSAGE.Set_Name('CS', 'CS_CHG_GET_UOM_FAILED');
13958     FND_MESSAGE.SET_TOKEN('INVENTORY_ITEM_ID', p_inv_id);
13959     FND_MESSAGE.SET_TOKEN('ORGANIZATION_ID', cs_std.get_item_valdn_orgzn_id);
13960     FND_MSG_PUB.Add;
13961     RAISE FND_API.G_EXC_ERROR;
13962   END IF;
13963 
13964   EXCEPTION
13965 
13966   WHEN FND_API.G_EXC_ERROR THEN
13967     x_return_status := FND_API.G_RET_STS_ERROR;
13968     fnd_msg_pub.count_and_get(
13969       p_count => x_msg_count
13970      ,p_data  => x_msg_data);
13971 
13972   WHEN OTHERS THEN
13973     x_return_status := FND_API.G_RET_STS_ERROR;
13974     FND_MESSAGE.Set_Name('CS', 'CS_CHG_GET_UOM_FAILED');
13975     FND_MESSAGE.SET_TOKEN('INVENTORY_ITEM_ID', p_inv_id);
13976     FND_MESSAGE.SET_TOKEN('ORGANIZATION_ID', cs_std.get_item_valdn_orgzn_id);
13977     FND_MSG_PUB.Add;
13978     fnd_msg_pub.count_and_get(
13979       p_count => x_msg_count
13980      ,p_data  => x_msg_data);
13981 
13982 END GET_PRIMARY_UOM;
13983 
13984 --================================================
13985 -- Validate Source Code and Source Id being passed
13986 --===============================================
13987 PROCEDURE VALIDATE_SOURCE(
13988                 P_API_NAME          IN   VARCHAR2,
13989                 P_SOURCE_CODE       IN   VARCHAR2,
13990                 P_SOURCE_ID         IN   NUMBER,
13991                 P_ORG_ID            IN   NUMBER,
13992                 X_SOURCE_ID         OUT NOCOPY   NUMBER,
13993                 X_MSG_DATA          OUT NOCOPY VARCHAR2,
13994                 X_MSG_COUNT         OUT NOCOPY NUMBER,
13995                 X_RETURN_STATUS     OUT NOCOPY   VARCHAR2)  IS
13996 
13997 Cursor c_val_sr_source(p_source_id IN NUMBER) IS
13998 
13999 -- Bug Fix for Bug # 3044488
14000 SELECT incident_id
14001   FROM CS_INCIDENTS_ALL_b
14002  WHERE incident_id = p_source_id;
14003    --AND org_id = p_org_id;
14004 
14005 Cursor c_val_dr_source(p_source_id IN NUMBER) IS
14006 SELECT repair_line_id
14007   FROM CSD_REPAIRS
14008  WHERE repair_line_id = p_source_id;
14009 
14010 Cursor c_val_sd_source(p_source_id IN NUMBER) IS
14011 --SELECT debrief_header_id
14012 --  FROM csf_debrief_headers
14013 -- WHERE debrief_header_id = p_source_id ;
14014 SELECT debrief_line_id
14015   FROM csf_debrief_lines
14016  WHERE debrief_line_id = p_source_id;
14017 
14018 lv_exists_flag  VARCHAR2(1) := 'N';
14019 
14020 --DEBUG
14021 l_ERRM VARCHAR2(100);
14022 
14023 BEGIN
14024 -- Initialize API return status to success
14025   x_return_status := FND_API.G_RET_STS_SUCCESS;
14026 
14027   --DBMS_OUTPUT.PUT_LINE('p_source_code  = ' || p_source_code);
14028   --DBMS_OUTPUT.PUT_LINE('p_source_id  = ' || p_source_id);
14029   --DBMS_OUTPUT.PUT_LINE('p_org_id  = ' || p_org_id);
14030 
14031   IF p_source_code = 'SR' THEN
14032 
14033     IF  p_source_id IS NOT NULL THEN
14034       FOR v_val_sr_source IN c_val_sr_source(p_source_id) LOOP
14035         lv_exists_flag := 'Y';
14036         x_source_id := p_source_id;
14037       END LOOP;
14038 
14039       IF lv_exists_flag <> 'Y' THEN
14040         --RAISE FND_API.G_EXC_ERROR;
14041         --null;
14042         FND_MESSAGE.Set_Name('CS', 'CS_CHG_INVALID_SOURCE');
14043         FND_MESSAGE.SET_TOKEN('SOURCE_CODE', p_source_code);
14044         FND_MESSAGE.SET_TOKEN('SOURCE_ID', p_source_id);
14045         FND_MSG_PUB.Add;
14046         RAISE FND_API.G_EXC_ERROR;
14047       END IF;
14048 
14049     ELSE
14050       -- source_id cannot be cannot be null
14051       Add_Null_Parameter_Msg(p_api_name, 'p_source_id');
14052       RAISE FND_API.G_EXC_ERROR;
14053     END IF ;
14054 
14055   ELSIF p_source_code = 'DR' THEN
14056     IF  p_source_id  IS NOT NULL  THEN
14057       FOR v_val_dr_source IN c_val_dr_source(p_source_id) LOOP
14058         lv_exists_flag := 'Y';
14059         x_source_id := p_source_id;
14060       END LOOP;
14061 
14062       IF lv_exists_flag <> 'Y' THEN
14063         --RAISE FND_API.G_EXC_ERROR;
14064         --null;
14065         FND_MESSAGE.Set_Name('CS', 'CS_CHG_INVALID_SOURCE');
14066         FND_MESSAGE.SET_TOKEN('SOURCE_CODE', p_source_code);
14067         FND_MESSAGE.SET_TOKEN('SOURCE_ID', p_source_id);
14068         FND_MSG_PUB.Add;
14069         RAISE FND_API.G_EXC_ERROR;
14070       END IF;
14071 
14072     ELSE
14073       -- source_id cannot be cannot be null
14074       Add_Null_Parameter_Msg(p_api_name, 'p_source_id');
14075       RAISE FND_API.G_EXC_ERROR;
14076     END IF ;
14077 
14078   ELSIF p_source_code = 'SD' THEN
14079     IF  p_source_id  IS NOT NULL  THEN
14080       FOR v_val_dr_source IN c_val_sd_source(p_source_id) LOOP
14081         lv_exists_flag := 'Y';
14082         x_source_id := p_source_id;
14083       END LOOP;
14084 
14085       IF lv_exists_flag <> 'Y' THEN
14086         --RAISE FND_API.G_EXC_ERROR;
14087         --null;
14088         FND_MESSAGE.Set_Name('CS', 'CS_CHG_INVALID_SOURCE');
14089         FND_MESSAGE.SET_TOKEN('SOURCE_CODE', p_source_code);
14090         FND_MESSAGE.SET_TOKEN('SOURCE_ID', p_source_id);
14091         FND_MSG_PUB.Add;
14092         RAISE FND_API.G_EXC_ERROR;
14093       END IF;
14094 
14095     ELSE
14096       -- raise error as source_id cannot be cannot be null
14097       Add_Null_Parameter_Msg(p_api_name, 'p_source_id');
14098       RAISE FND_API.G_EXC_ERROR;
14099     END IF ;
14100 
14101   ELSIF p_source_code = 'SD' THEN
14102     IF  p_source_id  IS NOT NULL  THEN
14103       FOR v_val_sd_source IN c_val_sd_source(p_source_id) LOOP
14104 
14105         lv_exists_flag := 'Y';
14106         x_source_id := p_source_id;
14107       END LOOP;
14108 
14109       IF lv_exists_flag <> 'Y' THEN
14110         --RAISE FND_API.G_EXC_ERROR;
14111         --null;
14112         FND_MESSAGE.Set_Name('CS', 'CS_CHG_INVALID_SOURCE');
14113         FND_MESSAGE.SET_TOKEN('SOURCE_CODE', p_source_code);
14114         FND_MESSAGE.SET_TOKEN('SOURCE_ID', p_source_id);
14115         FND_MSG_PUB.Add;
14116         RAISE FND_API.G_EXC_ERROR;
14117       END IF;
14118     ELSE
14119       -- cannot be null
14120       Add_Null_Parameter_Msg(p_api_name, 'p_source_id');
14121       RAISE FND_API.G_EXC_ERROR;
14122     END IF ;
14123 
14124   ELSE
14125     --Invalid source code passed. Raise an exception
14126     Add_Invalid_Argument_Msg(
14127       p_token_an => p_api_name,
14128       p_token_v  => p_source_code,
14129       p_token_p  => 'p_source_code');
14130 
14131     RAISE FND_API.G_EXC_ERROR;
14132   END IF ;
14133 
14134   EXCEPTION
14135 
14136   WHEN FND_API.G_EXC_ERROR THEN
14137     x_return_status := FND_API.G_RET_STS_ERROR;
14138     fnd_msg_pub.count_and_get(
14139       p_count => x_msg_count
14140      ,p_data  => x_msg_data);
14141 
14142   WHEN NO_DATA_FOUND THEN
14143     x_return_status := FND_API.G_RET_STS_ERROR;
14144     IF  p_source_id IS NOT NULL THEN
14145       Add_Invalid_Argument_Msg(p_token_an => p_api_name,
14146         p_token_v  => p_source_id,
14147         p_token_p  => 'p_source_id');
14148     END IF ;
14149 
14150   WHEN OTHERS THEN
14151     --l_ERRM := SQLERRM;
14152     --DBMS_OUTPUT.PUT_LINE('Others Validate Source ' ||l_errm);
14153     --x_return_status := FND_API.G_RET_STS_ERROR ;
14154     x_return_status := FND_API.G_RET_STS_ERROR;
14155     FND_MESSAGE.Set_Name('CS', 'CS_CHG_INVALID_SOURCE');
14156     FND_MESSAGE.SET_TOKEN('SOURCE_CODE', p_source_code);
14157     FND_MESSAGE.SET_TOKEN('SOURCE_ID', p_source_id);
14158     FND_MSG_PUB.Add;
14159     fnd_msg_pub.count_and_get(
14160       p_count => x_msg_count
14161      ,p_data  => x_msg_data);
14162 
14163 END  Validate_Source;
14164 
14165 --===========================================================
14166 -- Get Site Id
14167 --==========================================================
14168 
14169 PROCEDURE GET_SITE_FOR_PARTY(P_API_NAME          IN         VARCHAR2,
14170                              P_SITE_USE_ID       IN         NUMBER,
14171                              P_PARTY_ID          IN         NUMBER,
14172                              P_VAL_MODE          IN         VARCHAR2,
14173                              X_SITE_ID           OUT NOCOPY NUMBER,
14174                              X_RETURN_STATUS     OUT NOCOPY VARCHAR2) IS
14175 
14176 CURSOR c_bill_to_party_site(P_SITE_USE_ID IN NUMBER,
14177                             P_PARTY_ID    IN NUMBER) IS
14178 SELECT site_use.party_site_id
14179   FROM  HZ_PARTY_SITE_USES site_use,
14180         HZ_PARTY_SITES site,
14181         HZ_PARTIES party
14182  WHERE  site_use.party_site_use_id = p_site_use_id
14183    AND  party.party_id = p_party_id
14184    AND  nvl(site_use.status,'A') = 'A'
14185    AND  site_use.site_use_type = 'BILL_TO'
14186    AND  site_use.party_site_id = site.party_site_id
14187    AND  site.party_id   = party.party_id;
14188 
14189 CURSOR c_ship_to_party_site(p_site_use_id IN NUMBER,
14190                             p_party_id    IN NUMBER) IS
14191 SELECT site_use.party_site_id
14192   FROM  HZ_PARTY_SITE_USES site_use,
14193         HZ_PARTY_SITES site,
14194         HZ_PARTIES party
14195  WHERE  site_use.party_site_use_id = p_site_use_id
14196    AND  party.party_id = p_party_id
14197    AND  nvl(site_use.status,'A') = 'A'
14198    AND  site_use.site_use_type = 'SHIP_TO'
14199    AND  site_use.party_site_id = site.party_site_id
14200    AND  site.party_id   = party.party_id;
14201 
14202 lv_exists_flag VARCHAR2(1) := 'N';
14203 BEGIN
14204 
14205    x_return_status :=  FND_API.G_RET_STS_SUCCESS;
14206    IF p_val_mode = 'BILL_TO' THEN
14207      FOR v_bill_to_party_site IN c_bill_to_party_site(p_site_use_id, p_party_id) LOOP
14208        lv_exists_flag := 'Y';
14209        x_site_id := v_bill_to_party_site.party_site_id;
14210      END LOOP;
14211    ELSE
14212       --p_val_mode = 'SHIP_TO'
14213       FOR v_ship_to_party_site IN c_ship_to_party_site(p_site_use_id, p_party_id) LOOP
14214        lv_exists_flag := 'Y';
14215        x_site_id := v_ship_to_party_site.party_site_id;
14216      END LOOP;
14217    END IF;
14218 
14219    IF lv_exists_flag = 'N' THEN
14220      --RAISE FND_API.G_EXC_ERROR;
14221      --null;
14222      FND_MESSAGE.Set_Name('CS', 'CS_CHG_NO_SITE_FOUND');
14223      FND_MESSAGE.SET_TOKEN('PARTY_ID', p_party_id);
14224      FND_MESSAGE.SET_TOKEN('SITE_USE_ID', p_site_use_id);
14225      FND_MSG_PUB.Add;
14226      RAISE FND_API.G_EXC_ERROR;
14227    END IF;
14228 
14229   EXCEPTION
14230 
14231   WHEN FND_API.G_EXC_ERROR THEN
14232     x_return_status := FND_API.G_RET_STS_ERROR;
14233 
14234   WHEN OTHERS THEN
14235     x_return_status := FND_API.G_RET_STS_ERROR;
14236     FND_MESSAGE.Set_Name('CS', 'CS_CHG_NO_SITE_FOUND');
14237     FND_MESSAGE.SET_TOKEN('PARTY_ID', p_party_id);
14238     FND_MESSAGE.SET_TOKEN('SITE_USE_ID', p_site_use_id);
14239     FND_MSG_PUB.Add;
14240 
14241 END get_site_for_party;
14242 
14243 
14244 --============================================================
14245 -- Get Price List for Contract
14246 --============================================================
14247 PROCEDURE GET_CONTRACT_PRICE_LIST(
14248                 p_api_name               IN         VARCHAR2,
14249                 p_business_process_id    IN         NUMBER,
14250                 p_request_date           IN         DATE,
14251                 p_contract_line_id       IN         NUMBER,
14252                 --p_coverage_id            IN         NUMBER,
14253                 x_price_list_id          OUT NOCOPY NUMBER,
14254                 x_currency_code          OUT NOCOPY VARCHAR2,
14255                 x_msg_data               OUT NOCOPY VARCHAR2,
14256                 x_msg_count              OUT NOCOPY NUMBER,
14257                 x_return_status          OUT NOCOPY VARCHAR2) IS
14258 
14259 
14260 
14261 --Added to get the currency_code for the price list header id
14262 --Fixed Bug # 3546804
14263 Cursor get_currency_code(p_price_list_id NUMBER) IS
14264   select currency_code
14265     from qp_price_lists_v
14266    where price_list_id = p_price_list_id;
14267 
14268 --Added to get the currency_code for the price list header id
14269 --Fixed Bug # 3546804
14270 l_pricing_tbl      OKS_CON_COVERAGE_PUB.pricing_tbl_type ;
14271 l_index           BINARY_INTEGER;
14272 
14273 
14274 
14275 BEGIN
14276 
14277   x_return_status := FND_API.G_RET_STS_SUCCESS;
14278 
14279   --Changed the functionality to resolve bug # 3546804
14280 
14281   IF p_business_process_id IS NOT NULL AND
14282      p_request_date IS NOT NULL AND
14283      p_contract_line_id IS NOT NULL THEN
14284 
14285 
14286        --Call the OKC API
14287        OKS_CON_COVERAGE_PUB.get_bp_pricelist
14288                          (p_api_version         => 1.0
14289                          ,p_init_msg_list       => 'T'
14290                          ,p_Contract_line_id    => p_contract_line_id
14291                          ,p_business_process_id => p_business_process_id
14292                          ,p_request_date        => p_request_date
14293                          ,x_return_status       => x_return_status
14294                          ,x_msg_count           => x_msg_count
14295                          ,x_msg_data            => x_msg_data
14296                          ,x_pricing_tbl         => l_pricing_tbl);
14297 
14298         l_index := l_pricing_tbl.FIRST;
14299 
14300         FOR l_temp IN 1..l_pricing_tbl.COUNT LOOP
14301           --get the Business Process Price List ID
14302           x_price_list_id := l_pricing_tbl(l_index).BP_Price_list_id;
14303 
14304           --get the currency_code for the same
14305           OPEN get_currency_code(x_price_list_id);
14306           FETCH get_currency_code INTO x_currency_code;
14307           CLOSE get_currency_code;
14308 
14309           EXIT WHEN l_index = l_pricing_tbl.FIRST ;
14310         END LOOP;
14311   ELSE
14312     -- p_business_process_id or p_request_date is null
14313     -- default the contract price list and currency code to null
14314     -- as this cannot be derived
14315     x_price_list_id := null;
14316     x_currency_code := null;
14317   END IF;
14318 
14319   EXCEPTION
14320 
14321   WHEN OTHERS THEN
14322     x_return_status := FND_API.G_RET_STS_ERROR;
14323     FND_MESSAGE.SET_NAME('CS', 'CS_CHG_UNEXPECTED_EXEC_ERRORS');
14324      FND_MESSAGE.SET_TOKEN('ROUTINE', p_api_name);
14325      FND_MESSAGE.SET_TOKEN('SQLERRM', sqlerrm);
14326      FND_MSG_PUB.ADD;
14327      fnd_msg_pub.count_and_get(
14328             p_count => x_msg_count
14329            ,p_data  => x_msg_data);
14330 
14331 END get_contract_price_list;
14332 
14333 --===========================================================
14334 -- Get Currency Code for Price List
14335 --===========================================================
14336 
14337 PROCEDURE  GET_CURRENCY_CODE(
14338                 p_api_name        IN         VARCHAR2,
14339                 p_price_list_id   IN         NUMBER ,
14340                 x_currency_code   OUT NOCOPY VARCHAR2,
14341                 x_msg_data        OUT NOCOPY VARCHAR2,
14342                 x_msg_count       OUT NOCOPY NUMBER,
14343                 x_return_status   OUT NOCOPY VARCHAR2)
14344 IS
14345 
14346 Cursor c_currency_code(p_price_list_id NUMBER) IS
14347 SELECT currency_code
14348 FROM   qp_price_lists_v
14349 WHERE  price_list_id = p_price_list_id;
14350 
14351 lv_exists_flag VARCHAR2(1) := 'N';
14352 BEGIN
14353   x_return_status := FND_API.G_RET_STS_SUCCESS;
14354 
14355   IF p_price_list_id IS NOT NULL THEN
14356     FOR v_currency_code IN c_currency_code(p_price_list_id) LOOP
14357       --assign currency_code to out record
14358       x_currency_code := v_currency_code.currency_code;
14359       lv_exists_flag := 'Y';
14360     END LOOP;
14361 
14362     IF lv_exists_flag <> 'Y' THEN
14363       --RAISE FND_API.G_EXC_ERROR;
14364       --null;
14365       FND_MESSAGE.Set_Name('CS', 'CS_CHG_GET_CURRENCY_FAILED');
14366       FND_MESSAGE.SET_TOKEN('PRICE_LIST_ID', p_price_list_id);
14367       FND_MSG_PUB.Add;
14368       RAISE FND_API.G_EXC_ERROR;
14369     END IF;
14370   ELSE
14371     --price list id is null
14372     -- this should never happen
14373     --RAISE FND_API.G_EXC_ERROR;
14374     --null;
14375     Add_Null_Parameter_Msg(p_api_name, 'p_price_list_id');
14376     RAISE FND_API.G_EXC_ERROR;
14377   END IF;
14378 
14379   EXCEPTION
14380 
14381   WHEN FND_API.G_EXC_ERROR THEN
14382     x_return_status := FND_API.G_RET_STS_ERROR;
14383     fnd_msg_pub.count_and_get(
14384       p_count => x_msg_count
14385      ,p_data  => x_msg_data);
14386 
14387   WHEN OTHERS THEN
14388     x_return_status := FND_API.G_RET_STS_ERROR;
14389     FND_MESSAGE.Set_Name('CS', 'CS_CHG_GET_CURRENCY_FAILED');
14390     FND_MESSAGE.SET_TOKEN('PRICE_LIST_ID', p_price_list_id);
14391     FND_MSG_PUB.Add;
14392     fnd_msg_pub.count_and_get(
14393       p_count => x_msg_count
14394      ,p_data  => x_msg_data);
14395 
14396 END get_currency_code;
14397 
14398 --============================================================
14399 -- Get_Conversion_Rate - To get the conversion rate
14400 --=============================================================
14401 
14402  PROCEDURE  Get_Conversion_Rate
14403                    ( p_api_name       IN VARCHAR2,
14404                      p_from_currency  IN  VARCHAR2,
14405                      p_to_currency    IN  VARCHAR2,
14406                      x_denominator    OUT NOCOPY NUMBER,
14407                      x_numerator      OUT NOCOPY NUMBER,
14408                      x_rate           OUT NOCOPY NUMBER,
14409                      x_return_status  OUT NOCOPY VARCHAR) IS
14410 
14411   l_api_name  VARCHAR2(80)                   :=  'CS_Charge_Details_PVT.Get_Conversion_Rate';
14412   l_api_name_full  CONSTANT  VARCHAR2(61)    := G_PKG_NAME || '.' || l_api_name ;
14413   l_log_module     CONSTANT VARCHAR2(255)    := 'cs.plsql.' || l_api_name_full || '.';
14414   l_conversion_type VARCHAR2(30) :=   FND_PROFILE.VALUE('CS_CHG_DEFAULT_CONVERSION_TYPE');
14415   l_max_roll_days   NUMBER       :=   to_number(FND_PROFILE.VALUE('CS_CHG_MAX_ROLL_DAYS'));
14416   lx_numerator       NUMBER;
14417   lx_denominator     NUMBER;
14418   lx_rate            NUMBER;
14419 
14420   BEGIN
14421 
14422     -- Initialize Return Status to SUCCESS
14423     x_return_status := FND_API.G_RET_STS_SUCCESS;
14424 
14425     --DBMS_OUTPUT.PUT_LINE('Conversion Type is '||l_conversion_type);
14426     --DBMS_OUTPUT.PUT_LINE('l_max_roll_days '||l_max_roll_days);
14427 
14428       IF FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level
14429       THEN
14430 	FND_LOG.String
14431 	( FND_LOG.level_procedure , L_LOG_MODULE || ''
14432 	, 'The Value of profile CS_CHG_DEFAULT_CONVERSION_TYPE :' || l_conversion_type
14433 	);
14434 	FND_LOG.String
14435 	( FND_LOG.level_procedure , L_LOG_MODULE || ''
14436 	, 'The Value of profile CS_CHG_MAX_ROLL_DAYS :' || l_max_roll_days
14437 	);
14438       END IF;
14439 
14440    IF p_from_currency IS NULL THEN
14441      -- return error
14442      FND_MESSAGE.SET_NAME('CS', 'CS_CHG_UNDEFINED_CONV_CURRENCY');
14443      FND_MESSAGE.SET_TOKEN('API_NAME', p_api_name);
14444      FND_MESSAGE.SET_TOKEN('FROM_CURRENCY', p_from_currency);
14445      FND_MESSAGE.SET_TOKEN('TO_CURRENCY', p_to_currency);
14446      FND_MSG_PUB.add;
14447      RAISE FND_API.g_exc_error;
14448    END IF;
14449 
14450    IF p_to_currency IS NULL THEN
14451      -- return error
14452      FND_MESSAGE.SET_NAME('CS', 'CS_CHG_UNDEFINED_CONV_CURRENCY');
14453      FND_MESSAGE.SET_TOKEN('API_NAME', p_api_name);
14454      FND_MESSAGE.SET_TOKEN('FROM_CURRENCY', p_from_currency);
14455      FND_MESSAGE.SET_TOKEN('TO_CURRENCY', p_to_currency);
14456      FND_MSG_PUB.add;
14457      RAISE FND_API.g_exc_error;
14458    END IF;
14459 
14460    IF ((l_conversion_type IS NULL) OR
14461        (l_max_roll_days IS NULL)) THEN
14462      -- return error
14463      FND_MESSAGE.SET_NAME('CS', 'CS_CHG_UNDEFINED_CONV_PROFILES');
14464      FND_MESSAGE.SET_TOKEN('API_NAME', p_api_name);
14465      FND_MESSAGE.SET_TOKEN('PROFILE1', 'CS_CHG_DEFAULT_CONVERSION_TYPE');
14466      FND_MESSAGE.SET_TOKEN('PROFILE2', 'CS_CHG_MAX_ROLL_DAYS');
14467      FND_MSG_PUB.add;
14468      RAISE FND_API.g_exc_error;
14469    END IF;
14470 
14471 
14472    IF  ((l_conversion_type IS NOT NULL) AND
14473         (l_max_roll_days IS NOT NULL)) THEN
14474             gl_currency_api.get_closest_triangulation_rate (
14475                 x_from_currency      => p_from_currency,
14476                 x_to_currency        => p_to_currency,
14477                 x_conversion_date    => SYSDATE,
14478                 x_conversion_type    => l_conversion_type,
14479                 x_max_roll_days      => l_max_roll_days,
14480                 x_denominator        => lx_denominator,
14481                 x_numerator          => lx_numerator,
14482                 x_rate               => lx_rate );
14483 
14484      IF lx_rate IS NULL THEN
14485        --RAISE FND_API.g_exc_error;
14486        FND_MESSAGE.SET_NAME('CS', 'CS_CHG_CONV_RATE_NOT_FOUND');
14487        FND_MESSAGE.SET_TOKEN('API_NAME', p_api_name);
14488        FND_MESSAGE.SET_TOKEN('FROM_CURRENCY', p_from_currency);
14489        FND_MESSAGE.SET_TOKEN('TO_CURRENCY', p_to_currency);
14490        FND_MESSAGE.SET_TOKEN('CONV_DATE', sysdate);
14491        FND_MSG_PUB.add;
14492        RAISE FND_API.g_exc_error;
14493      ELSE
14494        x_denominator := lx_denominator;
14495        x_numerator   := lx_numerator;
14496        x_rate        := lx_rate;
14497      END IF;
14498   END IF;
14499 
14500   EXCEPTION
14501 
14502     WHEN FND_API.g_exc_error THEN
14503       x_return_status := fnd_api.g_ret_sts_error;
14504 
14505     WHEN OTHERS THEN
14506       x_return_status := FND_API.G_RET_STS_ERROR;
14507       FND_MESSAGE.SET_NAME('CS', 'CS_CHG_CONV_RATE_NOT_FOUND');
14508       FND_MESSAGE.SET_TOKEN('API_NAME', p_api_name);
14509       FND_MESSAGE.SET_TOKEN('FROM_CURRENCY', p_from_currency);
14510       FND_MESSAGE.SET_TOKEN('TO_CURRENCY', p_to_currency);
14511       FND_MESSAGE.SET_TOKEN('CONV_DATE', sysdate);
14512       FND_MSG_PUB.add;
14513 
14514 END Get_Conversion_Rate;
14515 
14516 --============================================================
14517 -- Get Contracts - Contracts information for Contract Service ID
14518 --============================================================
14519 
14520 PROCEDURE GET_CONTRACT(
14521                   p_api_name               IN VARCHAR2,
14522                   p_contract_SR_ID         IN NUMBER,
14523                   p_incident_date          IN DATE,
14524                   p_creation_date          IN DATE,
14525                   p_customer_id            IN NUMBER,
14526                   p_cust_account_id        IN NUMBER,
14527                   p_cust_product_id        IN NUMBER,
14528                   p_system_id              IN NUMBER DEFAULT NULL,   -- Fix bug
14529                   p_inventory_item_id      IN NUMBER DEFAULT NULL,   -- Fix bug
14530                   p_business_process_id    IN NUMBER,
14531                   x_contract_id            OUT NOCOPY NUMBER,
14532                   x_po_number              OUT NOCOPY VARCHAR2,
14533                   x_return_status          OUT NOCOPY VARCHAR2,
14534                   x_msg_count              OUT NOCOPY NUMBER,
14535                   x_msg_data               OUT NOCOPY VARCHAR2) IS
14536 
14537 --Changed to Fix Bug # 3419211
14538 Cursor Con_Coverage(p_service_line_id number,p_business_process_id number) IS
14539  SELECT     cov.contract_id
14540             --cov.coverage_line_id,
14541             --cov.coverage_name,
14542             --ent.txn_group_id
14543    FROM     oks_ent_line_details_v cov,
14544             oks_ent_txn_groups_v ent
14545   WHERE     cov.service_line_id = p_service_line_id
14546     AND     cov.coverage_line_id = ent.coverage_id
14547     AND     ent.business_process_id = p_business_process_id;
14548 
14549  TYPE T_CHCONCOVTAB IS TABLE OF Con_Coverage%rowtype
14550      INDEX BY BINARY_INTEGER;
14551 
14552  CHCONCOVTAB T_CHCONCOVTAB;
14553 
14554 
14555 
14556 l_count          NUMBER := 0;
14557 l_record_count   NUMBER := 0;
14558 k                NUMBER := 0;
14559 l_ent_contracts OKS_ENTITLEMENTS_PUB.GET_CONTOP_TBL;
14560 l_request_date   DATE;
14561 
14562 l_Service_PO_required VARCHAR2(30);
14563 l_result  VARCHAR2(1);
14564 l_return_status VARCHAR2(1);
14565 l_service_po VARCHAR2(30);
14566 
14567 
14568 
14569 BEGIN
14570 
14571  --Fixed Bug # 3480770
14572  -- Initiate contract value.
14573  x_contract_id := null;
14574  --x_coverage_id := null;
14575  --x_coverage_txn_group_id := null;
14576  x_po_number := null;
14577 
14578 -- derive the request date which will be passed to the
14579 -- CS_EST_APPLY_Contract_Pkg.Get_Contract_lines API
14580 -- if p_incident_date is null then use p_creation_date
14581 
14582 IF p_incident_date IS NOT NULL THEN
14583   l_request_date := p_incident_date;
14584 ELSE
14585   l_request_date := p_creation_date;
14586 END IF;
14587 
14588 
14589   --Changed to Fix Bug # 3419211
14590   IF p_contract_sr_id IS NOT NULL AND
14591      p_business_process_id IS NOT NULL THEN
14592 
14593       OPEN Con_Coverage(p_contract_sr_id, p_business_process_id);
14594       FETCH Con_Coverage
14595       INTO  CHCONCOVTAB(k);
14596       --Fixed Bug # 3480770
14597       IF Con_Coverage%FOUND THEN
14598         x_contract_id := CHCONCOVTAB(k).contract_id;
14599         --x_coverage_id := CHCONCOVTAB(k).coverage_line_id;
14600         --x_coverage_txn_group_id := CHCONCOVTAB(k).TXN_GROUP_ID;
14601       END IF;
14602       CLOSE Con_Coverage;
14603 
14604 
14605       --DBMS_OUTPUT.PUT_LINE('Calling PO Cursor');
14606 
14607       IF x_contract_id IS NOT NULL THEN
14608         -- call the Contracts API to get the PO NUmber
14609         OKS_ENTITLEMENTS_PVT.Get_Service_PO(
14610           P_Chr_Id               => x_contract_id,
14611           P_Set_ExcepionStack    => 'F',
14612           X_Service_PO           => l_service_po,
14613           X_Service_PO_required  => l_Service_po_required,
14614           X_Result               => l_result,
14615           X_Return_Status        => l_return_status);
14616 
14617         --DBMS_OUTPUT.PUT_LINE('l_return_status'||l_return_status);
14618 
14619         IF l_return_status  = 'S' THEN
14620           x_po_number := l_service_po;
14621         ELSIF l_return_status  IN ('E', 'U') THEN
14622           x_po_number := null;
14623         END IF;
14624       END IF;
14625   ELSE
14626     --RAISE FND_API.G_EXC_ERROR;
14627     --null;
14628     FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CONTRACT_ERROR');
14629     FND_MESSAGE.SET_TOKEN('API_NAME', p_api_name);
14630     FND_MESSAGE.SET_TOKEN('CONTRACT_SERVICE_LINE_ID', p_contract_sr_id);
14631     FND_MESSAGE.SET_TOKEN('BUSINESS_PROCESS_ID', p_business_process_id);
14632     FND_MSG_PUB.add;
14633     RAISE FND_API.g_exc_error;
14634   END IF;
14635 
14636   EXCEPTION
14637 
14638     WHEN FND_API.g_exc_error THEN
14639       x_return_status := fnd_api.g_ret_sts_error;
14640       fnd_msg_pub.count_and_get(
14641         p_count => x_msg_count
14642        ,p_data  => x_msg_data);
14643 
14644 END get_contract;
14645 
14646 --=============================================================
14647 -- Get Charge Detail Record
14648 --=============================================================
14649 
14650 PROCEDURE GET_CHARGE_DETAIL_REC(
14651              P_API_NAME               IN         VARCHAR2,
14652              P_ESTIMATE_DETAIL_ID     IN         NUMBER,
14653              x_CHARGE_DETAIL_REC      OUT NOCOPY CS_ESTIMATE_DETAILS%ROWTYPE ,
14654              x_MSG_DATA               OUT NOCOPY VARCHAR2,
14655              x_MSG_COUNT              OUT NOCOPY NUMBER,
14656              x_RETURN_STATUS          OUT NOCOPY VARCHAR2) IS
14657 BEGIN
14658 
14659   --DBMS_OUTPUT.PUT_LINE('In GET_CHARGE_DETAIL_REC .....');
14660 
14661   -- Initialize the  p_return_status  to TRUE
14662          --p_return_status :=  FND_API.G_RET_STS_SUCCESS ;
14663   x_return_status :=  FND_API.G_RET_STS_SUCCESS ;
14664 
14665                  SELECT *
14666                  INTO x_charge_detail_rec
14667                  FROM CS_ESTIMATE_DETAILS
14668                  WHERE ESTIMATE_DETAIL_ID = p_estimate_detail_id
14669                  FOR UPDATE OF  ESTIMATE_DETAIL_ID NOWAIT ;
14670 
14671  EXCEPTION
14672         WHEN NO_DATA_FOUND THEN
14673          CS_Charge_Details_PVT.Add_Invalid_Argument_Msg(
14674                          p_token_an  =>  p_api_name,
14675                          p_token_v   =>  to_char(p_estimate_detail_id) ,
14676                          p_token_p   =>  'p_estimate_detail_id') ;
14677         fnd_msg_pub.count_and_get(
14678           p_count => x_msg_count
14679          ,p_data  => x_msg_data);
14680 
14681         WHEN RECORD_LOCK_EXCEPTION THEN
14682              --p_return_status := FND_API.G_RET_STS_ERROR ;
14683              x_return_status := FND_API.G_RET_STS_ERROR ;
14684              CS_Charge_Details_PVT.Record_Is_Locked_Msg(
14685                              p_token_an => p_api_name);
14686 
14687     WHEN OTHERS THEN
14688       x_return_status := FND_API.G_RET_STS_ERROR;
14689       FND_MESSAGE.SET_NAME('CS', 'CS_CHG_GET_CHARGE_FAILED');
14690       FND_MESSAGE.SET_TOKEN('API_NAME', p_api_name);
14691       FND_MESSAGE.SET_TOKEN('ESTIMATE_DETAIL_ID', p_estimate_detail_id);
14692       FND_MSG_PUB.add;
14693       fnd_msg_pub.count_and_get(
14694         p_count => x_msg_count
14695        ,p_data  => x_msg_data);
14696 
14697 END;
14698 
14699 
14700 --=============================================================
14701 --Do_Txns_Exist -- Can This be a function instead of a procedure
14702 --============================================================
14703 PROCEDURE Do_Txns_Exist(
14704                p_api_name             IN          VARCHAR2,
14705                p_estimate_detail_id   IN          NUMBER ,
14706                x_order_line_id        OUT NOCOPY  NUMBER,
14707                x_gen_bca_flag         OUT NOCOPY  VARCHAR2,
14708                x_charge_line_type     OUT NOCOPY  VARCHAR2,
14709                x_return_status        OUT NOCOPY  VARCHAR2)  AS
14710 BEGIN
14711       --p_return_status :=  FND_API.G_RET_STS_SUCCESS ;
14712       x_return_status :=  FND_API.G_RET_STS_SUCCESS;
14713         SELECT order_line_id,
14714                GENERATED_BY_BCA_ENGINE_FLAG,
14715                Charge_line_type
14716         INTO   x_order_line_id,
14717                x_gen_bca_flag,
14718                x_charge_line_type
14719         FROM   CS_ESTIMATE_DETAILS
14720         WHERE  estimate_detail_id = p_estimate_detail_id
14721         FOR UPDATE OF ESTIMATE_DETAIL_ID NOWAIT ;
14722 
14723 
14724 EXCEPTION
14725         WHEN NO_DATA_FOUND THEN
14726              --p_return_status :=  FND_API.G_RET_STS_ERROR ;
14727              x_return_status :=  FND_API.G_RET_STS_ERROR ;
14728              Add_Invalid_Argument_Msg(p_token_an => p_api_name,
14729                   p_token_v => to_char(p_estimate_detail_id) ,
14730                   p_token_p => 'estimate_detail_id' ) ;
14731 
14732         WHEN RECORD_LOCK_EXCEPTION THEN
14733              --p_return_status := FND_API.G_RET_STS_ERROR ;
14734              x_return_status := FND_API.G_RET_STS_ERROR ;
14735              Record_Is_Locked_Msg(p_token_an => p_api_name);
14736 
14737         WHEN OTHERS THEN
14738              --p_return_status :=  FND_API.G_RET_STS_ERROR ;
14739              x_return_status :=  FND_API.G_RET_STS_ERROR ;
14740 
14741 END Do_Txns_Exist ;
14742 
14743 
14744 --=================================
14745 -- Validate Org Id
14746 --================================
14747 
14748 PROCEDURE VALIDATE_ORG_ID(
14749                   P_API_NAME       IN VARCHAR2,
14750                   P_ORG_ID         IN NUMBER,
14751                   X_RETURN_STATUS  OUT NOCOPY VARCHAR2,
14752                   X_MSG_COUNT      OUT NOCOPY NUMBER,
14753                   X_MSG_DATA       OUT NOCOPY VARCHAR2)
14754 
14755 IS
14756 
14757 Cursor c_org_id IS
14758   SELECT organization_id
14759     FROM hr_operating_units
14760    WHERE organization_id = p_org_id;
14761 
14762 lv_exists_flag VARCHAR2(1) := 'N';
14763 
14764 BEGIN
14765 
14766   FOR v_org_id IN c_org_id
14767     LOOP
14768       lv_exists_flag := 'Y';
14769     END LOOP;
14770 
14771   IF lv_exists_flag = 'Y' THEN
14772     x_return_status :=  FND_API.G_RET_STS_SUCCESS ;
14773   ELSE
14774     raise NO_DATA_FOUND;
14775   END IF;
14776 
14777 EXCEPTION
14778 
14779   WHEN NO_DATA_FOUND THEN
14780          CS_Charge_Details_PVT.Add_Invalid_Argument_Msg(
14781                          p_token_an  =>  p_api_name,
14782                          p_token_v   =>  to_char(p_org_id) ,
14783                          p_token_p   =>  'p_org_id') ;
14784 
14785          fnd_msg_pub.count_and_get(
14786            p_count => x_msg_count
14787           ,p_data  => x_msg_data);
14788 
14789 
14790   WHEN OTHERS THEN
14791          x_return_status :=  FND_API.G_RET_STS_ERROR ;
14792 
14793 END VALIDATE_ORG_ID;
14794 
14795 
14796 --==================================
14797 -- Add_Invalid_Argument_Msg
14798 --==================================
14799 
14800 PROCEDURE Add_Invalid_Argument_Msg
14801 ( p_token_an	VARCHAR2,
14802   p_token_v	VARCHAR2,
14803   p_token_p	VARCHAR2
14804 )
14805 IS
14806 
14807 BEGIN
14808 
14809   IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
14810     FND_MESSAGE.Set_Name('CS', 'CS_API_ALL_INVALID_ARGUMENT');
14811     FND_MESSAGE.Set_Token('API_NAME', p_token_an);
14812     FND_MESSAGE.Set_Token('VALUE', p_token_v);
14813     FND_MESSAGE.Set_Token('PARAMETER', p_token_p);
14814     FND_MSG_PUB.Add;
14815 
14816   END IF;
14817 
14818 END Add_Invalid_Argument_Msg;
14819 
14820 
14821 --====================================
14822 -- Add_Null_Parameter_Msg
14823 --====================================
14824 
14825 PROCEDURE Add_Null_Parameter_Msg
14826 ( p_token_an	VARCHAR2,
14827   p_token_np	VARCHAR2
14828 )
14829 IS
14830 
14831 BEGIN
14832 
14833   IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
14834 
14835     FND_MESSAGE.Set_Name('CS', 'CS_API_ALL_NULL_PARAMETER');
14836     FND_MESSAGE.Set_Token('API_NAME', p_token_an);
14837     FND_MESSAGE.Set_Token('NULL_PARAM', p_token_np);
14838     FND_MSG_PUB.Add;
14839 
14840   END IF;
14841 
14842 END Add_Null_Parameter_Msg;
14843 
14844 --============================
14845 --Cannot_Delete_Line_Msg
14846 --============================
14847 PROCEDURE Cannot_Delete_Line_Msg
14848 ( p_token_an    IN      VARCHAR2
14849 )
14850 IS
14851 BEGIN
14852     FND_MESSAGE.Set_Name('CS', 'CS_API_CHG_CANT_DELETE_DET');
14853     FND_MESSAGE.Set_Token('API_NAME', p_token_an);
14854     FND_MSG_PUB.Add;
14855 END;
14856 
14857 
14858 --============================
14859 --
14860 --============================
14861 PROCEDURE Cant_Update_Detail_Param_Msg
14862 ( p_token_an            IN      VARCHAR2,
14863   p_token_cn            IN      VARCHAR2,
14864   p_token_v             IN      VARCHAR2
14865 ) IS
14866 BEGIN
14867     FND_MESSAGE.Set_Name('CS', 'CS_API_CHG_CANT_UPD_DET_PARAM');
14868     FND_MESSAGE.Set_Token('API_NAME', p_token_an);
14869     FND_MESSAGE.Set_Token('COLUMN_NAME', p_token_cn);
14870     FND_MESSAGE.Set_Token('VALUE', p_token_v);
14871     FND_MSG_PUB.Add;
14872 END;
14873 
14874 
14875 
14876 --=============================
14877 -- Record_Is_Locked_msg
14878 --=============================
14879 
14880 PROCEDURE Record_Is_Locked_Msg
14881 ( p_token_an	VARCHAR2
14882 )
14883 IS
14884 
14885 BEGIN
14886 
14887     FND_MESSAGE.Set_Name('CS', 'CS_API_ALL_CANT_LOCK_RECORD');
14888     FND_MESSAGE.Set_Token('API_NAME', p_token_an);
14889     FND_MSG_PUB.Add;
14890 END Record_IS_Locked_Msg;
14891 
14892 
14893 PROCEDURE Validate_Who_Info(
14894                  P_API_NAME                  IN            VARCHAR2,
14895                  P_USER_ID                   IN            NUMBER,
14896                  P_LOGIN_ID                  IN            NUMBER,
14897                  X_RETURN_STATUS             OUT NOCOPY    VARCHAR2) IS
14898 
14899   CURSOR c_user IS
14900   SELECT 1
14901   FROM   fnd_user
14902   WHERE  user_id = p_user_id
14903   AND    TRUNC(SYSDATE) <= start_date
14904   AND    NVL(end_date, SYSDATE) >= SYSDATE;
14905 
14906   CURSOR c_login IS
14907   SELECT 1
14908   FROM   fnd_logins
14909   WHERE  login_id = p_login_id
14910   AND    user_id = p_user_id;
14911 
14912   l_dummy  VARCHAR2(1);
14913 
14914 BEGIN
14915 
14916    x_return_status :=  FND_API.G_RET_STS_SUCCESS;
14917 
14918    BEGIN
14919       IF p_user_id = -1 then
14920          SELECT 'x' into l_dummy
14921          FROM    fnd_user
14922          WHERE   user_id = p_user_id;
14923       ELSE
14924          SELECT 'x' into l_dummy
14925          FROM    fnd_user
14926          WHERE   user_id = p_user_id
14927          AND trunc(sysdate) BETWEEN trunc(nvl(start_date, sysdate))
14928          AND trunc(nvl(end_date, sysdate));
14929       END IF;
14930 
14931       EXCEPTION
14932       WHEN NO_DATA_FOUND THEN
14933          x_return_status := FND_API.G_RET_STS_ERROR;
14934          Add_Invalid_Argument_Msg(p_token_an => p_api_name,
14935                                   p_token_v  => TO_CHAR(p_user_id),
14936                                   p_token_p  => 'p_user_id');
14937       return;
14938    END;
14939 
14940    IF p_login_id is not null then
14941    BEGIN
14942       SELECT 'x' into l_dummy
14943       FROM       fnd_logins
14944       WHERE   login_id = p_login_id
14945       AND        user_id  = p_user_id;
14946 
14947       EXCEPTION
14948       WHEN NO_DATA_FOUND THEN
14949          x_return_status := FND_API.G_RET_STS_ERROR;
14950          Add_Invalid_Argument_Msg(p_token_an => p_api_name,
14951                                   p_token_v  => TO_CHAR(p_login_id),
14952                                   p_token_p  => 'p_user_login');
14953    END;
14954    END IF;
14955 
14956 END Validate_Who_Info;
14957 
14958 -- Get line type id.
14959 --Fixed Bug # 3325667 added p_org_id to procedure get_line_type
14960 Procedure Get_Line_Type(p_api_name              IN VARCHAR2,
14961                         p_txn_billing_type_id   IN  NUMBER,
14962                         p_org_id                IN  NUMBER,
14963                         x_line_type_id          OUT NOCOPY  NUMBER,
14964                         x_return_status         OUT NOCOPY VARCHAR2,
14965                         x_msg_count             OUT NOCOPY NUMBER,
14966                         x_msg_data              OUT NOCOPY VARCHAR2) IS
14967 
14968 --Fixed Bug # 3325667 added p_org_id to procedure get_line_type
14969 CURSOR get_line_type_csr IS
14970    select tb.line_type_id
14971    from cs_txn_billing_oetxn_all tb, cs_txn_billing_types tt
14972    where tb.txn_billing_type_id = p_txn_billing_type_id
14973    and tb.txn_billing_type_id = tt.txn_billing_type_id and
14974    tb.org_id = p_org_id;
14975 
14976 BEGIN
14977    --DBMS_OUTPUT.PUT_LINE('p_txn_billing_type_id = ' || p_txn_billing_type_id);
14978 
14979    x_return_status :=  FND_API.G_RET_STS_SUCCESS;
14980    x_line_type_id := null;
14981 
14982    OPEN get_line_type_csr;
14983    FETCH get_line_type_csr
14984    INTO x_line_type_id;
14985    IF get_line_type_csr%NOTFOUND THEN
14986       CLOSE get_line_type_csr;
14987       FND_MESSAGE.SET_NAME('CS', 'CS_CHG_LINE_TYPE_NOT_FOUND');
14988       FND_MESSAGE.SET_TOKEN('TXN_BILLING_TYPE_ID', p_txn_billing_type_id);
14989       FND_MSG_PUB.ADD;
14990       RAISE FND_API.g_exc_error;
14991    END IF;
14992    CLOSE get_line_type_csr;
14993    --DBMS_OUTPUT.PUT_LINE('x_return_status = ' || x_return_status);
14994 
14995    -- Exception Block
14996    EXCEPTION
14997       WHEN FND_API.g_exc_error THEN
14998         x_return_status := fnd_api.g_ret_sts_error;
14999         fnd_msg_pub.count_and_get(
15000           p_count => x_msg_count
15001          ,p_data  => x_msg_data);
15002       WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
15003          x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
15004          fnd_msg_pub.count_and_get(
15005             p_count   => x_msg_count
15006            ,p_data    => x_msg_data);
15007       WHEN OTHERS THEN
15008          x_return_status := FND_API.G_RET_STS_ERROR;
15009          FND_MESSAGE.SET_NAME('CS', 'CS_CHG_UNEXPECTED_EXEC_ERRORS');
15010          FND_MESSAGE.SET_TOKEN('ROUTINE', p_api_name);
15011          FND_MESSAGE.SET_TOKEN('SQLERRM', sqlerrm);
15012          FND_MSG_PUB.ADD;
15013          fnd_msg_pub.count_and_get(
15014             p_count => x_msg_count
15015            ,p_data  => x_msg_data);
15016 
15017 END Get_Line_Type;
15018 
15019 --==================================================
15020 -- GET_CHARGE_FLAGS_FROM_SR
15021 --==================================================
15022 
15023 --Bug Fix for Bug # 3086455
15024 PROCEDURE get_charge_flags_from_sr(p_api_name                IN          VARCHAR2,
15025                                    p_incident_id             IN          NUMBER,
15026                                    x_disallow_new_charge     OUT NOCOPY  VARCHAR2,
15027                                    x_disallow_charge_update  OUT NOCOPY  VARCHAR2,
15028                                    x_msg_data                OUT NOCOPY  VARCHAR2,
15029                                    x_msg_count               OUT NOCOPY  NUMBER,
15030                                    x_return_status           OUT NOCOPY  NUMBER
15031                                    )IS
15032 
15033 cursor c_charge_flags(p_incident_id IN NUMBER)IS
15034 select nvl(csinst.disallow_new_charge, 'N'),
15035        nvl(csinst.disallow_charge_update, 'N')
15036  from cs_incident_statuses csinst,
15037       cs_incidents_all csinall
15038  where csinst.incident_status_id = csinall.incident_status_id
15039  and   csinall.incident_id = p_incident_id;
15040 
15041 
15042 BEGIN
15043 
15044   OPEN c_charge_flags(p_incident_id);
15045    FETCH c_charge_flags
15046    INTO x_disallow_new_charge, x_disallow_charge_update;
15047    IF c_charge_flags%NOTFOUND THEN
15048       CLOSE c_charge_flags;
15049         --Add null argument error
15050         Add_Invalid_Argument_Msg(p_token_an => p_api_name,
15051                                   p_token_v  => TO_CHAR(p_incident_id),
15052                                   p_token_p  => 'p_incident_id');
15053         RAISE FND_API.G_EXC_ERROR;
15054    END IF;
15055    CLOSE c_charge_flags;
15056  END;
15057 
15058 
15059 --========================
15060 --CHARGE FLAG
15061 --========================
15062 
15063 --added by bkanimoz on 15-dec-2007
15064 
15065 PROCEDURE  get_charge_flag_from_sac
15066                             (p_api_name                IN  VARCHAR2,
15067                              p_txn_type_id             IN  NUMBER,
15068                              x_create_charge_flag      OUT NOCOPY  VARCHAR2,
15069 			     x_msg_data                OUT NOCOPY  VARCHAR2,
15070                              x_msg_count               OUT NOCOPY  NUMBER,
15071                              x_return_status           OUT NOCOPY  NUMBER
15072                              )IS
15073 
15074 cursor c_create_charge_flag ( p_txn_type_id IN NUMBER)IS
15075 select nvl(ctt.create_charge_flag, 'Y')
15076 from   cs_transaction_types_b  ctt
15077 where transaction_type_id= p_txn_type_id ;
15078 
15079 
15080 BEGIN
15081 
15082   OPEN c_create_charge_flag(p_txn_type_id);
15083    FETCH c_create_charge_flag
15084    INTO x_create_charge_flag;
15085    IF c_create_charge_flag%NOTFOUND THEN
15086       CLOSE c_create_charge_flag;
15087         --Add null argument error
15088         Add_Invalid_Argument_Msg(p_token_an => p_api_name,
15089                                   p_token_v  => TO_CHAR(p_txn_type_id),
15090                                   p_token_p  => 'p_txn_type_id');
15091         RAISE FND_API.G_EXC_ERROR;
15092    END IF;
15093    CLOSE c_create_charge_flag;
15094 
15095 END;
15096 
15097 
15098 
15099 
15100 --========================
15101 -- VALIDATE_ORDER
15102 --========================
15103 
15104 PROCEDURE Validate_Order(p_api_name              IN VARCHAR2,
15105                          p_order_header_id       IN NUMBER,
15106                          p_org_id                IN NUMBER,
15107                          x_return_status         OUT NOCOPY VARCHAR2,
15108                          x_msg_count             OUT NOCOPY NUMBER,
15109                          x_msg_data              OUT NOCOPY VARCHAR2) IS
15110 
15111 CURSOR order_csr IS
15112    SELECT header_id,
15113           open_flag
15114      FROM OE_ORDER_HEADERS_ALL ooha,
15115           HZ_CUST_ACCOUNTS acct,
15116           HZ_PARTIES hp
15117     WHERE ooha.sold_to_org_id = acct.cust_account_id
15118     AND   acct.party_id       = hp.party_id
15119     AND   ooha.header_id      = p_order_header_id
15120     AND   ooha.org_id         = p_org_id;
15121 
15122 l_order_header_id   NUMBER;
15123 l_open_flag       VARCHAR2(1);
15124 
15125 BEGIN
15126    -- Initialize Return Status to SUCCESS
15127    x_return_status := FND_API.G_RET_STS_SUCCESS;
15128 
15129    OPEN order_csr;
15130    FETCH order_csr
15131    INTO l_order_header_id, l_open_flag;
15132    IF order_csr%NOTFOUND THEN
15133       CLOSE order_csr;
15134         FND_MESSAGE.Set_Name('CS', 'CS_CHG_INVALID_ORDER');
15135         FND_MESSAGE.SET_TOKEN('ORDER_HEADER_ID', p_order_header_id);
15136         FND_MSG_PUB.Add;
15137         RAISE FND_API.G_EXC_ERROR;
15138    END IF;
15139    CLOSE order_csr;
15140 
15141    --Bug Fix for Bug # 3085106
15142 
15143    IF l_open_flag = 'N' THEN
15144      FND_MESSAGE.Set_Name('CS', 'CS_CHG_CANNOT_ADD_TO_ORDER');
15145      FND_MESSAGE.Set_token('API_NAME', p_api_name);
15146      FND_MESSAGE.SET_TOKEN('ORDER_HEADER_ID', p_order_header_id);
15147      FND_MSG_PUB.Add;
15148      RAISE FND_API.G_EXC_ERROR;
15149    END IF;
15150 
15151 
15152    -- Exception Block
15153    EXCEPTION
15154       WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
15155          x_return_status := FND_API.G_RET_STS_ERROR;
15156          fnd_msg_pub.count_and_get(
15157             p_count   => x_msg_count
15158            ,p_data    => x_msg_data);
15159 
15160       WHEN OTHERS THEN
15161          FND_MESSAGE.SET_NAME('CS', 'CS_CHG_UNEXPECTED_EXEC_ERRORS');
15162          FND_MESSAGE.SET_TOKEN('ROUTINE', p_api_name);
15163          FND_MESSAGE.SET_TOKEN('SQLERRM', sqlerrm);
15164          FND_MSG_PUB.ADD;
15165          fnd_msg_pub.count_and_get(
15166             p_count => x_msg_count
15167            ,p_data  => x_msg_data);
15168          x_return_status := FND_API.G_RET_STS_ERROR;
15169 
15170 END Validate_Order;
15171 
15172 --------------------------------------------------------------------------------
15173 --  Procedure Name            :   PURGE_CHG_VALIDATIONS
15174 --
15175 --  Parameters (other than standard ones)
15176 --  IN
15177 --      p_object_type         :   Type of object for which this procedure is
15178 --                                being called. (Here it will be 'SR')
15179 --      p_processing_set_id   :   Id that helps the API in identifying the
15180 --                                set of SRs for which the child objects have
15181 --                                to be deleted.
15182 --
15183 --  Description
15184 --      This procedure identifies the charge lines that are related to an SR
15185 --      and verifies if they can be deleted. The conditions checked during the
15186 --      varification are: if the charge line is 'ACTUAL' and if it does not have
15187 --      an order line id, the line cannot be deleted. In this case, the global
15188 --      temp table is updated with a purge_status as E against that SR which
15189 --      contains such a charge line.
15190 --
15191 --  HISTORY
15192 --
15193 ----------------+------------+--------------------------------------------------
15194 --  DATE        | UPDATED BY | Change Description
15195 ----------------+------------+--------------------------------------------------
15196 --  4-Aug-2005  | varnaray   | Created
15197 --              |            |
15198 ----------------+------------+--------------------------------------------------
15199 PROCEDURE Purge_Chg_Validations
15200 (
15201   p_api_version_number IN  NUMBER := 1.0
15202 , p_init_msg_list      IN  VARCHAR2 := FND_API.G_FALSE
15203 , p_commit             IN  VARCHAR2 := FND_API.G_FALSE
15204 , p_object_type        IN  VARCHAR2
15205 , p_processing_set_id  IN  NUMBER
15206 , x_return_status      OUT NOCOPY  VARCHAR2
15207 , x_msg_count          OUT NOCOPY  NUMBER
15208 , x_msg_data           OUT NOCOPY  VARCHAR2
15209 )
15210 IS
15211 --------------------------------------------------------------------------------
15212 
15213 L_API_VERSION   CONSTANT NUMBER        := 1.0;
15214 L_API_NAME      CONSTANT VARCHAR2(30)  := 'PURGE_CHG_VALIDATIONS';
15215 L_API_NAME_FULL CONSTANT VARCHAR2(61)  := G_PKG_NAME || '.' || L_API_NAME;
15216 L_LOG_MODULE    CONSTANT VARCHAR2(255) := 'cs.plsql.' || L_API_NAME_FULL || '.';
15217 
15218 l_row_count     NUMBER := 0;
15219 
15220 BEGIN
15221   x_return_status := FND_API.G_RET_STS_SUCCESS;
15222 
15223   IF FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level
15224   THEN
15225     FND_LOG.String
15226     (
15227       FND_LOG.level_procedure
15228     , L_LOG_MODULE || 'start'
15229     , 'Inside ' || L_API_NAME_FULL
15230       || ', called with parameters below:'
15231     );
15232     FND_LOG.String
15233     (
15234       FND_LOG.level_procedure
15235     , L_LOG_MODULE || 'param 1'
15236     , 'p_api_version_number:' || p_api_version_number
15237     );
15238     FND_LOG.String
15239     (
15240       FND_LOG.level_procedure
15241     , L_LOG_MODULE || 'param 2'
15242     , 'p_init_msg_list:' || p_init_msg_list
15243     );
15244     FND_LOG.String
15245     (
15246       FND_LOG.level_procedure
15247     , L_LOG_MODULE || 'param 3'
15248     , 'p_commit:' || p_commit
15249     );
15250     FND_LOG.String
15251     (
15252       FND_LOG.level_procedure
15253     , L_LOG_MODULE || 'param 4'
15254     , 'p_object_type:' || p_object_type
15255     );
15256     FND_LOG.String
15257     (
15258       FND_LOG.level_procedure
15259     , L_LOG_MODULE || 'param 5'
15260     , 'p_processing_set_id:' || p_processing_set_id
15261     );
15262   END IF ;
15263 
15264   IF NOT FND_API.Compatible_API_Call
15265   (
15266     L_API_VERSION
15267   , p_api_version_number
15268   , L_API_NAME
15269   , G_PKG_NAME
15270   )
15271   THEN
15272     FND_MSG_PUB.Count_And_Get
15273     (
15274       p_count => x_msg_count
15275     , p_data  => x_msg_data
15276     );
15277     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
15278   END IF ;
15279 
15280   IF FND_API.to_Boolean(p_init_msg_list)
15281   THEN
15282     FND_MSG_PUB.initialize;
15283   END IF ;
15284 
15285   ------------------------------------------------------------------------------
15286   -- Parameter Validations:
15287   ------------------------------------------------------------------------------
15288 
15289   IF NVL(p_object_type, 'X') <> 'SR'
15290   THEN
15291     IF FND_LOG.level_unexpected >= FND_LOG.g_current_runtime_level
15292     THEN
15293       FND_LOG.String
15294       (
15295         FND_LOG.level_unexpected
15296       , L_LOG_MODULE || 'object_type_invalid'
15297       , 'p_object_type has to be SR.'
15298       );
15299     END IF ;
15300 
15301     FND_MESSAGE.Set_Name('CS', 'CS_SR_PARAM_VALUE_ERROR');
15302     FND_MESSAGE.Set_Token('API_NAME', L_API_NAME_FULL);
15303     FND_MESSAGE.Set_Token('PARAM', 'p_object_type');
15304     FND_MESSAGE.Set_Token('CURRVAL', p_object_type);
15305     FND_MSG_PUB.ADD;
15306 
15307     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
15308   END IF;
15309 
15310   ---
15311 
15312   IF p_processing_set_id IS NULL
15313   THEN
15314     IF FND_LOG.level_unexpected >= FND_LOG.g_current_runtime_level
15315     THEN
15316       FND_LOG.String
15317       (
15318         FND_LOG.level_unexpected
15319       , L_LOG_MODULE || 'proc_set_id_invalid'
15320       , 'p_processing_set_id should not be NULL.'
15321       );
15322     END IF ;
15323 
15324     FND_MESSAGE.Set_Name('CS', 'CS_SR_PARAM_VALUE_ERROR');
15325     FND_MESSAGE.Set_Token('API_NAME', L_API_NAME_FULL);
15326     FND_MESSAGE.Set_Token('PARAM', 'p_processing_set_id');
15327     FND_MESSAGE.Set_Token('CURRVAL', NVL(to_char(p_processing_set_id),'NULL'));
15328     FND_MSG_PUB.ADD;
15329 
15330     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
15331   END IF;
15332 
15333   ------------------------------------------------------------------------------
15334   -- Actual Logic starts below:
15335   ------------------------------------------------------------------------------
15336 
15337   IF FND_LOG.level_statement >= FND_LOG.g_current_runtime_level
15338   THEN
15339     FND_LOG.String
15340     (
15341       FND_LOG.level_statement
15342     , L_LOG_MODULE || 'valid_chg_line_start'
15343     , 'validating charge lines against SRs in the global temp table'
15344     );
15345   END IF ;
15346 
15347   -- validate the SRs that are submitted for purge
15348   -- against the charge lines created for them.
15349   -- if the charge lines are ACTUAL and do not have
15350   -- a line id attached to them, then the corresponding
15351   -- SRs cannot be purged.
15352 
15353   UPDATE jtf_object_purge_param_tmp
15354   SET
15355     purge_status        = 'E'
15356   , purge_error_message = 'CS:CS_CHG_LINE_VAL_ERR'
15357   WHERE
15358       object_id IN
15359       (
15360       SELECT
15361           t.object_id
15362       FROM
15363         cs_estimate_details        e
15364       , jtf_object_purge_param_tmp t
15365       WHERE
15366           e.incident_id            = t.object_id
15367       AND e.charge_line_type       = 'ACTUAL'
15368       AND e.order_line_id          IS NULL
15369       AND t.object_type            = 'SR'
15370       AND t.processing_set_id      = p_processing_set_id
15371       AND nvl(t.purge_status, 'S') = 'S'
15372       )
15373   AND nvl(purge_status, 'S') = 'S'
15374   AND object_type            = 'SR'
15375   AND processing_set_id      = p_processing_set_id;
15376 
15377   l_row_count := SQL%ROWCOUNT;
15378 
15379   IF FND_LOG.level_statement >= FND_LOG.g_current_runtime_level
15380   THEN
15381     FND_LOG.String
15382     (
15383       FND_LOG.level_statement
15384     , L_LOG_MODULE || 'valid_chg_line_end'
15385     , 'after validating charge lines against SRs in the global temp table '
15386       || l_row_count || ' rows failed validation'
15387     );
15388   END IF ;
15389 
15390   ---
15391 
15392   IF FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level
15393   THEN
15394     FND_LOG.String
15395     (
15396       FND_LOG.level_procedure
15397     , L_LOG_MODULE || 'end'
15398     , 'Completed work in ' || L_API_NAME_FULL || ' successfully'
15399     );
15400   END IF ;
15401 
15402 EXCEPTION
15403   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
15404     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
15405 
15406     IF FND_LOG.level_unexpected >= FND_LOG.g_current_runtime_level
15407     THEN
15408       FND_LOG.String
15409       (
15410         FND_LOG.level_unexpected
15411       , L_LOG_MODULE || 'unexpected_error'
15412       , 'Inside WHEN FND_API.G_EXC_UNEXPECTED_ERROR of ' || L_API_NAME_FULL
15413       );
15414     END IF ;
15415 
15416 	WHEN OTHERS THEN
15417     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
15418     FND_MESSAGE.Set_Name('CS', 'CS_CHG_LINE_VAL_FAIL');
15419     FND_MESSAGE.Set_Token('API_NAME', L_API_NAME_FULL);
15420     FND_MESSAGE.Set_Token('ERROR', SQLERRM);
15421     FND_MSG_PUB.ADD;
15422 
15423     IF FND_LOG.level_unexpected >= FND_LOG.g_current_runtime_level
15424     THEN
15425       FND_LOG.String
15426       (
15427         FND_LOG.level_unexpected
15428       , L_LOG_MODULE || 'when_others'
15429       , 'Inside WHEN OTHERS of ' || L_API_NAME_FULL || '. Oracle Error was:'
15430       );
15431       FND_LOG.String
15432       (
15433         FND_LOG.level_unexpected
15434       , L_LOG_MODULE || 'when_others'
15435       , SQLERRM
15436       );
15437     END IF ;
15438 END Purge_Chg_Validations;
15439 
15440 --------------------------------------------------------------------------------
15441 --  Procedure Name            :   PURGE_CHARGES
15442 --
15443 --  Parameters (other than standard ones)
15444 --  IN
15445 --      p_object_type         :   Type of object for which this procedure is
15446 --                                being called. (Here it will be 'SR')
15447 --      p_processing_set_id   :   Id that helps the API in identifying the
15448 --                                set of SRs for which the child objects have
15449 --                                to be deleted.
15450 --
15451 --  Description
15452 --      This procedure physically deletes all the charge lines attached to
15453 --      a service request. It reads the list of SRs for which the charge lines
15454 --      have to be deleted from the global temp table, looking only for rows
15455 --      having the purge_status as NULL. Using Set processing, the procedure
15456 --      deletes all the charge lines attached to such SRs.
15457 --
15458 --  HISTORY
15459 --
15460 ----------------+------------+--------------------------------------------------
15461 --  DATE        | UPDATED BY | Change Description
15462 ----------------+------------+--------------------------------------------------
15463 --  4-Aug-2005  | varnaray   | Created
15464 --              |            |
15465 ----------------+------------+--------------------------------------------------
15466 PROCEDURE Purge_Charges
15467 (
15468   p_api_version_number IN  NUMBER := 1.0
15469 , p_init_msg_list      IN  VARCHAR2 := FND_API.G_FALSE
15470 , p_commit             IN  VARCHAR2 := FND_API.G_FALSE
15471 , p_object_type        IN  VARCHAR2
15472 , p_processing_set_id  IN  NUMBER
15473 , x_return_status      OUT NOCOPY  VARCHAR2
15474 , x_msg_count          OUT NOCOPY  NUMBER
15475 , x_msg_data           OUT NOCOPY  VARCHAR2
15476 )
15477 IS
15478 --------------------------------------------------------------------------------
15479 
15480 L_API_VERSION   CONSTANT NUMBER       := 1.0;
15481 L_API_NAME      CONSTANT VARCHAR2(30) := 'PURGE_CHARGES';
15482 L_API_NAME_FULL CONSTANT VARCHAR2(61) := G_PKG_NAME || '.' || L_API_NAME;
15483 L_LOG_MODULE    CONSTANT VARCHAR2(255) := 'cs.plsql.' || L_API_NAME_FULL || '.';
15484 
15485 l_row_count     NUMBER := 0;
15486 
15487 BEGIN
15488   x_return_status := FND_API.G_RET_STS_SUCCESS;
15489 
15490   IF FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level
15491   THEN
15492     FND_LOG.String
15493     (
15494       FND_LOG.level_procedure
15495     , L_LOG_MODULE || 'start'
15496     , 'Inside ' || L_API_NAME_FULL || ', called with parameters below:'
15497     );
15498     FND_LOG.String
15499     (
15500       FND_LOG.level_procedure
15501     , L_LOG_MODULE || 'param 1'
15502     , 'p_api_version_number:' || p_api_version_number
15503     );
15504     FND_LOG.String
15505     (
15506       FND_LOG.level_procedure
15507     , L_LOG_MODULE || 'param 2'
15508     , 'p_init_msg_list:' || p_init_msg_list
15509     );
15510     FND_LOG.String
15511     (
15512       FND_LOG.level_procedure
15513     , L_LOG_MODULE || 'param 3'
15514     , 'p_commit:' || p_commit
15515     );
15516     FND_LOG.String
15517     (
15518       FND_LOG.level_procedure
15519     , L_LOG_MODULE || 'param 4'
15520     , 'p_object_type:' || p_object_type
15521     );
15522     FND_LOG.String
15523     (
15524       FND_LOG.level_procedure
15525     , L_LOG_MODULE || 'param 5'
15526     , 'p_processing_set_id:' || p_processing_set_id
15527     );
15528   END IF ;
15529 
15530   IF NOT FND_API.Compatible_API_Call
15531   (
15532     L_API_VERSION
15533   , p_api_version_number
15534   , L_API_NAME
15535   , G_PKG_NAME
15536   )
15537   THEN
15538     FND_MSG_PUB.Count_And_Get
15539     (
15540       p_count => x_msg_count
15541     , p_data  => x_msg_data
15542     );
15543     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
15544   END IF ;
15545 
15546   IF FND_API.to_Boolean(p_init_msg_list)
15547   THEN
15548     FND_MSG_PUB.initialize;
15549   END IF ;
15550 
15551   ------------------------------------------------------------------------------
15552   -- Parameter Validations:
15553   ------------------------------------------------------------------------------
15554 
15555   IF NVL(p_object_type, 'X') <> 'SR'
15556   THEN
15557     IF FND_LOG.level_unexpected >= FND_LOG.g_current_runtime_level
15558     THEN
15559       FND_LOG.String
15560       (
15561         FND_LOG.level_unexpected
15562       , L_LOG_MODULE || 'object_type_invalid'
15563       , 'p_object_type has to be SR.'
15564       );
15565     END IF ;
15566 
15567     FND_MESSAGE.Set_Name('CS', 'CS_SR_PARAM_VALUE_ERROR');
15568     FND_MESSAGE.Set_Token('API_NAME', L_API_NAME_FULL);
15569     FND_MESSAGE.Set_Token('PARAM', 'p_object_type');
15570     FND_MESSAGE.Set_Token('CURRVAL', p_object_type);
15571     FND_MSG_PUB.ADD;
15572 
15573     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
15574   END IF;
15575 
15576   ---
15577 
15578   IF p_processing_set_id IS NULL
15579   THEN
15580     IF FND_LOG.level_unexpected >= FND_LOG.g_current_runtime_level
15581     THEN
15582       FND_LOG.String
15583       (
15584         FND_LOG.level_unexpected
15585       , L_LOG_MODULE || 'proc_set_id_invalid'
15586       , 'p_processing_set_id should not be NULL.'
15587       );
15588     END IF ;
15589 
15590     FND_MESSAGE.Set_Name('CS', 'CS_SR_PARAM_VALUE_ERROR');
15591     FND_MESSAGE.Set_Token('API_NAME', L_API_NAME_FULL);
15592     FND_MESSAGE.Set_Token('PARAM', 'p_processing_set_id');
15593     FND_MESSAGE.Set_Token('CURRVAL', NVL(to_char(p_processing_set_id),'NULL'));
15594     FND_MSG_PUB.ADD;
15595 
15596     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
15597   END IF;
15598 
15599   ------------------------------------------------------------------------------
15600   -- Actual Logic starts below:
15601   ------------------------------------------------------------------------------
15602 
15603   IF FND_LOG.level_statement >= FND_LOG.g_current_runtime_level
15604   THEN
15605     FND_LOG.String
15606     (
15607       FND_LOG.level_statement
15608     , L_LOG_MODULE || 'del_chg_line_start'
15609     , 'deleting charge lines against SRs in the global temp table'
15610     );
15611   END IF ;
15612 
15613   -- Delete all the estimate lines that correspond to the
15614   -- SRs that are available for purge after validations.
15615 
15616   DELETE /*+ index(e) */ cs_estimate_details e
15617   WHERE
15618     incident_id IN
15619     (
15620     SELECT /*+ no_unnest no_semijoin cardinality(10) */
15621         object_id
15622     FROM
15623         jtf_object_purge_param_tmp
15624     WHERE
15625         processing_set_id = p_processing_set_id
15626     AND object_type = 'SR'
15627     AND NVL(purge_status, 'S') = 'S'
15628     );
15629 
15630   l_row_count := SQL%ROWCOUNT;
15631 
15632   IF FND_LOG.level_statement >= FND_LOG.g_current_runtime_level
15633   THEN
15634     FND_LOG.String
15635     (
15636       FND_LOG.level_statement
15637     , L_LOG_MODULE || 'del_chg_line_end'
15638     , 'after deleting charge lines against SRs in the global temp table'
15639       || l_row_count || ' rows deleted.'
15640     );
15641   END IF ;
15642 
15643   ---
15644 
15645   IF FND_LOG.level_procedure >= FND_LOG.g_current_runtime_level
15646   THEN
15647     FND_LOG.String
15648     (
15649       FND_LOG.level_procedure
15650     , L_LOG_MODULE || 'end'
15651     , 'Completed work in ' || L_API_NAME_FULL || ' successfully'
15652     );
15653   END IF ;
15654 
15655 EXCEPTION
15656   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
15657     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
15658 
15659     IF FND_LOG.level_unexpected >= FND_LOG.g_current_runtime_level
15660     THEN
15661       FND_LOG.String
15662       (
15663         FND_LOG.level_unexpected
15664       , L_LOG_MODULE || 'unexpected_error'
15665       , 'Inside WHEN FND_API.G_EXC_UNEXPECTED_ERROR of ' || L_API_NAME_FULL
15666       );
15667     END IF ;
15668 
15669 	WHEN OTHERS THEN
15670     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
15671     FND_MESSAGE.Set_Name('CS', 'CS_CHG_LINE_DEL_FAIL');
15672     FND_MESSAGE.Set_Token('API_NAME', L_API_NAME_FULL);
15673     FND_MESSAGE.Set_Token('ERROR', SQLERRM);
15674     FND_MSG_PUB.ADD;
15675 
15676     IF FND_LOG.level_unexpected >= FND_LOG.g_current_runtime_level
15677     THEN
15678       FND_LOG.String
15679       (
15680         FND_LOG.level_unexpected
15681       , L_LOG_MODULE || 'when_others'
15682       , 'Inside WHEN OTHERS of ' || L_API_NAME_FULL || '. Oracle Error was:'
15683       );
15684       FND_LOG.String
15685       (
15686         FND_LOG.level_unexpected
15687       , L_LOG_MODULE || 'when_others'
15688       , SQLERRM
15689       );
15690     END IF ;
15691 END Purge_Charges;
15692 --------------------------------------------------------------------------------
15693 
15694 END CS_Charge_Details_PVT;