DBA Data[Home] [Help]

PACKAGE BODY: APPS.AR_BR_CANCEL_UNPAID_API_PUB

Source


1 PACKAGE BODY AR_BR_CANCEL_UNPAID_API_PUB AS
2 /* $Header: ARBRUOCB.pls 120.6 2004/04/07 21:53:53 anukumar ship $*/
3 /*#
4 * Unpaid Bill API sets the status for each unpaid bill receivable to
5 * Unpaid or Canceled based on the Cancel Bill Receivable Flag value.
6 * It validates the BR number and status and calls the accounting engine
7 * to perform the appropriate accounting.
8 * @rep:scope public
9 * @rep:lifecycle active
10 * @rep:displayname Unpaid Bill API
11 * @rep:category BUSINESS_ENTITY AR_BILLS_RECEIVABLE
12 */
13 
14 
15 PG_DEBUG varchar2(1) := NVL(FND_PROFILE.value('AFLOG_ENABLED'), 'N');
16 
17 /*#
18  * This procedure is the main procedure for the Unpaid Bill API.
22  * @param p_validation_level Validation level
19  * @param p_api_version API version
20  * @param p_init_msg_list Initialization of the message list
21  * @param p_commit Commit
23  * @param p_customer_trx_id  Bill Receivable transaction ID
24  * @param p_cancel_flag      Cancel Bill Receivable flag
25  * @param p_reason     Reason
26  * @param p_gl_date   GL date
27  * @param p_comments   Comments
28  * @rep:scope public
29  * @rep:lifecycle active
30  * @rep:displayname Set Bill Receivable  as Canceled or Unpaid
31   */
32 
33 
34 PROCEDURE CANCEL_OR_UNPAID(
35     x_return_status    OUT NOCOPY VARCHAR2,
36     x_msg_count        OUT NOCOPY NUMBER,
37     x_msg_data         OUT NOCOPY VARCHAR2,
38     p_api_version      IN  NUMBER,
39     p_init_msg_list    IN  VARCHAR2 default FND_API.G_FALSE,
40     p_commit           IN  VARCHAR2 default FND_API.G_FALSE,
41     p_validation_level IN  NUMBER   default FND_API.G_VALID_LEVEL_FULL,
42 
43     p_customer_trx_id  IN  NUMBER,
44     p_cancel_flag      IN  VARCHAR2,
45     p_reason           IN  VARCHAR2,
46     p_gl_date          IN  DATE,
47     p_comments         IN  VARCHAR2,
48     p_org_id           IN  NUMBER default null,
49     x_bill_status      OUT NOCOPY VARCHAR2
50 
51 )
52 
53 IS
54 
55 unpaid_br_error     EXCEPTION;
56 cancel_br_error     EXCEPTION;
57 no_setup_error      EXCEPTION;
58 invalid_flag        EXCEPTION;
59 l_error_code        NUMBER;
60 l_error_msg         VARCHAR2(255);
61 l_org_return_status VARCHAR2(1);
62 l_org_id                           NUMBER;
63 BEGIN
64 
65 
66 
67    GL_MC_CURRENCY_PKG.g_ar_upgrade_mode := TRUE;
68 
69    SAVEPOINT BR_B4;
70 
71 
72 
73 /* SSA change */
74        l_org_id            := p_org_id;
75        l_org_return_status := FND_API.G_RET_STS_SUCCESS;
76        ar_mo_cache_utils.set_org_context_in_api(p_org_id =>l_org_id,
77                                                 p_return_status =>l_org_return_status);
78  IF l_org_return_status <> FND_API.G_RET_STS_SUCCESS THEN
79        x_return_status := FND_API.G_RET_STS_ERROR;
80            FND_MSG_PUB.Count_And_Get(p_encoded => FND_API.G_FALSE,
81                                      p_count => x_msg_count,
82                                      p_data  => x_msg_data);
83  ELSE
84  IF p_cancel_flag ='N' then
85         /*======================================+
86         |                                       |
87         |   Update BR to UNPAID                 |
88         |                                       |
89         +=======================================*/
90   IF PG_DEBUG in ('Y', 'C') THEN
91      arp_standard.debug('CANCEL_OR_UNPAID: ' || '>>> Calling AR_BILLS_MAINTAIN_PUB.unpaid_br');
92   END IF;
93         AR_BILLS_MAINTAIN_PUB.unpaid_BR (
94 
95                 p_api_version           =>  1.0         ,
96                 x_return_status         =>  x_return_status     ,
97                 x_msg_count             =>  x_msg_count         ,
98                 x_msg_data              =>  x_msg_data          ,
99 
100                 p_customer_trx_id       =>  p_customer_trx_id   ,
101                 p_unpaid_date           =>  SYSDATE             ,
102                 p_unpaid_gl_date        =>  p_gl_date           ,
103                 p_unpaid_comments       =>  p_comments          ,
104                 p_unpaid_reason         =>  p_reason            ,
105                 p_status                =>  x_bill_status      );
106 
107        IF (x_return_status <> 'S') then
108           IF PG_DEBUG in ('Y', 'C') THEN
109              arp_standard.debug('CANCEL_OR_UNPAID: ' || '>>>>>>>>>> PROBLEM DURING BR unpaid');
110           END IF;
111           IF      (x_msg_count > 1) then
112             x_msg_data := FND_MSG_PUB.Get(FND_MSG_PUB.G_NEXT,FND_API.G_FALSE);
113           END IF;
114 
115           IF PG_DEBUG in ('Y', 'C') THEN
116              arp_standard.debug('CANCEL_OR_UNPAID: ' || 'x_msg_data : '|| x_msg_data);
117           END IF;
118           RAISE unpaid_br_error;
119        END IF;
120   IF PG_DEBUG in ('Y', 'C') THEN
121      arp_standard.debug('CANCEL_OR_UNPAID: ' || '>>> Finished UNPAID CALL, new status '||x_bill_status);
122      arp_standard.debug('CANCEL_OR_UNPAID: ' || '>>> Successfully Unpaid');
123   END IF;
124 
125 ELSIF p_cancel_flag ='Y'then
126         /*======================================+
127         |                                       |
128         |   Update BR to CANCELLED              |
129         |                                       |
130         +=======================================*/
131   IF p_reason IS NOT NULL then
132     IF PG_DEBUG in ('Y', 'C') THEN
133        arp_standard.debug('CANCEL_OR_UNPAID: ' || '>>> WARNING >>> Cancel_BR requires no reason, Bill '||p_customer_trx_id||' reason not used.');
134     END IF;
135   END IF;
136   IF PG_DEBUG in ('Y', 'C') THEN
137      arp_standard.debug('CANCEL_OR_UNPAID: ' || '>>> Calling AR_BILLS_MAINTAIN_PUB.cancel_br');
138   END IF;
139        AR_BILLS_MAINTAIN_PUB.Cancel_BR (
140 
141                 p_api_version           =>  1.0         ,
142                 x_return_status         =>  x_return_status     ,
143                 x_msg_count             =>  x_msg_count         ,
144                 x_msg_data              =>  x_msg_data          ,
145 
146                 p_customer_trx_id       =>  p_customer_trx_id   ,
147                 p_cancel_date           =>  SYSDATE             ,
148                 p_cancel_gl_date        =>  p_gl_date           ,
149                 p_cancel_comments       =>  p_comments          ,
150                 p_status                =>  x_bill_status      );
151 
152        IF (x_return_status <> 'S') then
153           IF PG_DEBUG in ('Y', 'C') THEN
157             x_msg_data := FND_MSG_PUB.Get(FND_MSG_PUB.G_NEXT,FND_API.G_FALSE);
154              arp_standard.debug('CANCEL_OR_UNPAID: ' || '>>>>>>>>>> PROBLEM DURING BR Cancel');
155           END IF;
156           IF      (x_msg_count > 1) then
158           END IF;
159 
160           IF PG_DEBUG in ('Y', 'C') THEN
161              arp_standard.debug('CANCEL_OR_UNPAID: ' || 'x_msg_data : '|| x_msg_data);
162           END IF;
163           RAISE cancel_br_error;
164        END IF;
165 
166   IF PG_DEBUG in ('Y', 'C') THEN
167      arp_standard.debug('CANCEL_OR_UNPAID: ' || '>>> Successfully Cancelled');
168   END IF;
169  ELSE
170   RAISE invalid_flag;
171  END IF;
172 
173  IF PG_DEBUG in ('Y', 'C') THEN
174     arp_standard.debug('------ END OF  AR_BR_CANCEL_UNPAID_PKG.Cancel_or_unpaid -------');
175     arp_standard.debug('CANCEL_OR_UNPAID: ' || 'RETURN STATUS      : ' || x_return_status);
176     arp_standard.debug('CANCEL_OR_UNPAID: ' || 'BR IDENTIFIER      : ' || p_customer_trx_id);
177     arp_standard.debug('CANCEL_OR_UNPAID: ' || 'STATUS             : ' || x_bill_status);
178  END IF;
179 END IF;
180 
181 EXCEPTION
182    WHEN unpaid_BR_ERROR THEN
183        x_return_status := FND_API.G_RET_STS_ERROR;
184        IF PG_DEBUG in ('Y', 'C') THEN
185           arp_standard.debug('>>>>> CANCEL_OR_UNPAID, Unpaid BR EXCEPTION - ROLLBACK, return_status ='||x_return_status);
186        END IF;
187        Rollback to BR_B4;
188        app_exception.raise_exception;
189 
190    WHEN cancel_BR_ERROR THEN
191        x_return_status := FND_API.G_RET_STS_ERROR;
192        IF PG_DEBUG in ('Y', 'C') THEN
193           arp_standard.debug('>>>>> CANCEL_OR_UNPAID, Cancel BR EXCEPTION - ROLLBACK, return_status ='||x_return_status);
194        END IF;
195        Rollback to BR_B4;
196        app_exception.raise_exception;
197 
198    WHEN invalid_flag THEN
199       x_return_status := FND_API.G_RET_STS_ERROR;
200       IF PG_DEBUG in ('Y', 'C') THEN
201          arp_standard.debug('>>>>> CANCEL_OR_UNPAID, Invalid value for p_cancel_flag - ROLLBACK');
202       END IF;
203       Rollback to BR_B4;
204       app_exception.raise_exception;
205 
206    WHEN no_setup_error THEN
207       IF PG_DEBUG in ('Y', 'C') THEN
208          arp_standard.debug('>>>>> CANCEL_OR_UNPAID, Setup of org id not correctly performed');
209       END IF;
210       app_exception.raise_exception;
211 
212    WHEN OTHERS THEN
213       x_return_status := FND_API.G_RET_STS_ERROR;
214       IF PG_DEBUG in ('Y', 'C') THEN
215          arp_standard.debug('>>>>> CANCEL_OR_UNPAID, Others EXCEPTION - ROLLBACK, return_status ='||x_return_status);
216       END IF;
217       Rollback to BR_B4;
218       l_error_code := SQLCODE;
219       l_error_msg  := substr(SQLERRM,1,255);
220       IF PG_DEBUG in ('Y', 'C') THEN
221          arp_standard.debug('CANCEL_OR_UNPAID: ' || '>>> Code: '||l_error_code||' Msg: '||l_error_msg);
222       END IF;
223       app_exception.raise_exception;
224 
225 
226 END CANCEL_OR_UNPAID;
227 
228 end AR_BR_CANCEL_UNPAID_API_PUB;
229