DBA Data[Home] [Help]

PACKAGE BODY: APPS.CS_EST_APPLY_CONTRACT_PKG

Source


1 package body CS_Est_Apply_Contract_PKG  as
2 /* $Header: csxchcob.pls 120.2.12020000.2 2012/07/05 05:42:16 gasankar ship $ */
3 /*******************************************************************************
4 	--
5 	--Private global variables and functions
6 	--
7 *******************************************************************************/
8 
9 
10 PROCEDURE Apply_Contract (
11   p_coverage_id	  IN  NUMBER,
12   p_coverage_txn_group_id IN  NUMBER,
13   p_txn_billing_type_id   IN  NUMBER,
14   p_business_process_id   IN  NUMBER,
15   p_request_date          IN  DATE,
16   p_amount                IN  NUMBER,
17   p_discount_amount       OUT NOCOPY     NUMBER,
18   X_RETURN_STATUS         OUT NOCOPY     VARCHAR2,
19   X_MSG_COUNT             OUT NOCOPY     NUMBER,
20   X_MSG_DATA              OUT NOCOPY     VARCHAR2) IS
21 
22   l_contracts_in_tbl    OKS_CON_COVERAGE_PUB.ser_tbl_type ;
23   l_contracts_out_tbl   OKS_CON_COVERAGE_PUB.cov_tbl_type ;
24 
25   j 			NUMBER := 0;
26 
27   l_return_status      VARCHAR2(1);
28   l_msg_data           VARCHAR2(2000) ;
29   l_msg_count          NUMBER ;
30 
31   x_discount_price    NUMBER;
32   e_contracts_warning  EXCEPTION;
33 
34 
35 BEGIN
36 
37      l_contracts_in_tbl(1).contract_line_id    := P_coverage_id;
38      l_contracts_in_tbl(1).txn_group_id        := null;
39      l_contracts_in_tbl(1).billing_type_id     := P_txn_billing_type_id;
40      l_contracts_in_tbl(1).business_process_id := P_business_process_id;
41      l_contracts_in_tbl(1).request_date        := P_request_date;
42      l_contracts_in_tbl(1).charge_amount       := P_Amount;
43 
44     IF  l_contracts_in_tbl(1).contract_line_id IS NOT NULL
45     and l_contracts_in_tbl(1).billing_type_id IS NOT NULL
46     and l_contracts_in_tbl(1).business_process_id IS NOT NULL
47     and l_contracts_in_tbl(1).request_date IS NOT NULL
48     and l_contracts_in_tbl(1).charge_amount IS NOT NULL THEN
49 
50 	OKS_CON_COVERAGE_PUB.APPLY_CONTRACT_COVERAGE (
51                         P_API_VERSION             =>  1.0,
52                         P_INIT_MSG_LIST           =>  'T',
53                         P_EST_amt_TBL             =>  l_contracts_in_tbl,
54                         X_RETURN_STATUS           =>  l_return_status,
55                         X_MSG_COUNT               =>  l_msg_count,
56                         X_MSG_DATA                =>  l_msg_data,
57                         X_est_DISCounted_amt_TBL  =>  l_contracts_out_tbl);
58 
59         IF  l_return_status = FND_API.G_RET_STS_SUCCESS THEN
60 
61 	    FOR k in 1..l_contracts_out_tbl.count LOOP
62 
63 		IF l_contracts_out_tbl(1).discounted_amount IS NULL THEN
64 		p_discount_amount := l_contracts_in_tbl(1).charge_amount;
65 		ELSE
66                 p_discount_amount := l_contracts_out_tbl(1).discounted_amount;
67 
68                 x_return_status := l_return_status;
69                 END IF;
70             END LOOP;
71 
72 
73        ELSIF  l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
74               x_msg_data  := l_msg_data;
75               x_msg_count := l_msg_count;
76               x_return_status  := l_return_status;
77 
78       END IF;
79 
80 END IF;
81 
82       EXCEPTION
83 
84         WHEN e_contracts_warning THEN
85             -- x_result_flag := 'F' ;
86             FND_MESSAGE.Set_Name('CS', 'CS_CHG_APPLY_CONTRACT_WARNING');
87             FND_MESSAGE.Set_Token('REASON', l_msg_data);
88             app_exception.raise_exception ;
89 
90         WHEN OTHERS  THEN
91             -- x_result_flag := 'F' ;
92             FND_MESSAGE.Set_Name('CS', 'CS_CHG_APPLY_CONTRACT_WARNING');
93             FND_MESSAGE.Set_Token('REASON', 'Apply Contracts Failed.');
94             app_exception.raise_exception ;
95 
96 END Apply_Contract ;
97 --
98 --
99 PROCEDURE Update_Estimate_Details (
100 		  p_Estimate_Detail_Id  IN  NUMBER,
101 		  p_discount_price      IN  NUMBER) IS
102 BEGIN
103 	  	 UPDATE CS_ESTIMATE_DETAILS
104 		 SET    after_warranty_cost  = p_discount_price
105 	      WHERE Estimate_Detail_Id = p_estimate_detail_id;
106 
107 	 EXCEPTION
108       WHEN NO_DATA_FOUND THEN
109       Raise  No_Data_Found;
110 
111 END  Update_Estimate_Details;
112 --
113 --
114 PROCEDURE GET_CONTRACT_LINES(
115    P_API_VERSION		IN      NUMBER ,
116    P_INIT_MSG_LIST		IN      VARCHAR2,
117    P_CUSTOMER_ID		IN      NUMBER,
118    P_CUSTOMER_ACCOUNT_ID	IN	   NUMBER,
119    P_SERVICE_LINE_ID		IN	   NUMBER DEFAULT NULL,
120    P_CUSTOMER_PRODUCT_ID	IN      NUMBER DEFAULT NULL,
121    p_system_id			IN  number default null, -- Fix bug 3040124
122    p_inventory_item_id		IN  number default null, -- Fix bug 3040124
123    p_site_id		        IN  number default null, -- Fix bug 11877944
124    P_REQUEST_DATE		IN      DATE,
125    P_BUSINESS_PROCESS_ID	IN      NUMBER DEFAULT NULL,
126    P_CALC_RESPTIME_FLAG		IN      VARCHAR2 DEFAULT NULL,
127    P_VALIDATE_FLAG		IN      VARCHAR2,
128    X_ENT_CONTRACTS		OUT NOCOPY     ENT_CONTRACT_TAB,
129    -- X_ENT_COVERAGE		OUT NOCOPY     CONTTAB,
130    X_RETURN_STATUS		OUT NOCOPY     VARCHAR2,
131    X_MSG_COUNT			OUT NOCOPY     NUMBER,
132    X_MSG_DATA			OUT NOCOPY     VARCHAR2) IS
133 
134    l_return_status      varchar2(1);
135    l_api_name           varchar2(30) := 'GET_CONTRACT_LINES';
136    l_inp_rec            OKS_ENTITLEMENTS_PUB.get_contin_rec;
137    G_PKG_NAME           CONSTANT VARCHAR2(30) := 'CS_Est_Apply_Contract_PKG';
138 
139    L_CONTTAB CONTTAB;
140    l_rec_count  number;
141    i  number := 0;
142    j  number := 0;
143 
144 BEGIN
145 
146    SAVEPOINT Get_contract_lines;
147 
148    -- Since the Entitlements API expects input parameters as a record
149    -- copy all the input parameter values into a record before passing
150    -- it to the API
151 
152    l_inp_rec.party_id := p_customer_id;
153    l_inp_rec.cust_acct_id := p_customer_account_id;
154    l_inp_rec.service_line_id := p_service_line_id;
155    l_inp_rec.system_id := p_system_id;  -- Fix bug 3040124
156    l_inp_rec.item_id := p_inventory_item_id;  -- Fix bug 3040124
157    l_inp_rec.site_id := p_site_id;  -- Fix bug 11877944
161    l_inp_rec.calc_resptime_flag := p_calc_resptime_flag;
158    l_inp_rec.product_id := p_customer_product_id;
159    l_inp_rec.request_date := p_request_date;
160    l_inp_rec.business_process_id := p_business_process_id;
162    l_inp_rec.validate_flag := p_validate_flag;
163 
164    --If Validate_flag is 'Y' then only the valid contracts as of
165    -- 'request_date' are returned. If the validate_flag is 'N' then
166    -- all the contract lines - valid and invalid- are returned.
167    -- Charges is passing validate flag as 'Y'.
168 
169    OKS_ENTITLEMENTS_PUB.GET_CONTRACTS(
170       p_api_version => p_api_version,
171       p_init_msg_list => p_init_msg_list,
172       p_inp_rec => l_inp_rec,
173       x_return_status => l_return_status,
174       x_msg_count => x_msg_count,
175       x_msg_data => x_msg_data,
176       x_ent_contracts => x_ent_contracts);
177 
178    IF (l_return_status = FND_API.G_RET_STS_ERROR ) THEN
179       RAISE FND_API.G_EXC_ERROR ;
180    ELSIF ( l_return_status = FND_API.G_RET_STS_UNEXP_ERROR ) THEN
181       RAISE FND_API.G_EXC_UNEXPECTED_ERROR ;
182    END IF ;
183    x_return_status := l_return_status;
184 
185    EXCEPTION
186       WHEN FND_API.G_EXC_ERROR THEN
187          ROLLBACK TO  Get_contract_lines;
188          x_return_status := FND_API.G_RET_STS_ERROR ;
189          FND_MSG_PUB.COUNT_AND_GET (p_count =>x_msg_count ,
190                                     p_data => x_msg_data ,
191                                     p_encoded => fnd_api.g_false );
192 
193       WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
194          ROLLBACK TO  Get_contract_lines;
195          x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
196          FND_MSG_PUB.COUNT_AND_GET (p_count =>x_msg_count ,
197                                     p_data => x_msg_data ,
198                                     p_encoded => fnd_api.g_false );
199 
200       WHEN OTHERS THEN
201          ROLLBACK TO  Get_contract_lines;
202          x_return_status := FND_API.G_RET_STS_unexp_error ;
203          IF fnd_msg_pub.check_msg_level ( fnd_msg_pub.g_msg_lvl_unexp_error ) THEN
204             fnd_msg_pub.add_exc_msg(g_pkg_name, l_api_name ) ;
205          END IF;
206          fnd_msg_pub.count_and_get ( p_count =>x_msg_count ,p_data => x_msg_data ,p_encoded => fnd_api.g_false );
207 
208 END Get_Contract_Lines;
209 
210 END  CS_Est_Apply_Contract_PKG;