DBA Data[Home] [Help]

PACKAGE BODY: APPS.GMI_AUTO_ALLOCATE_PUB

Source


1 PACKAGE BODY GMI_AUTO_ALLOCATE_PUB AS
2 /*  $Header: GMIPALLB.pls 120.0 2005/05/25 16:00:00 appldev noship $  */
3 
4 /*  Global variables */
5 /*  Set package name */
6 /*  ================ */
7 G_PKG_NAME  CONSTANT  VARCHAR2(30):='GMI_AUTO_ALLOCATE_PUB';
8 
9 /* +==========================================================================+
10  | PROCEDURE NAME                                                           |
11  |    Allocate_Inventory                                                    |
12  |                                                                          |
13  | TYPE                                                                     |
14  |    Public                                                                |
15  |                                                                          |
16  |                                                                          |
17  | DESCRIPTION                                                              |
18  |    Auto Allocate Inventory against a sales/shipment line                 |
19  |                                                                          |
20  | PARAMETERS                                                               |
21  |    p_api_version      IN  NUMBER       - Api Version                     |
22  |    p_init_msg_list    IN  VARCHAR2     - Message Initialization Ind.     |
23  |    p_commit           IN  VARCHAR2     - Commit Indicator                |
24  |    p_validation_level IN  VARCHAR2     - Validation Level (Not Used)     |
25  |    p_allocation_rec   IN  gmi_allocation_rec - Allocation requirements   |
26  |    x_reservation_id   OUT NOCOPY NUMBER       - Trans_id from ic_tran_pnd       |
27  |    x_allocated_qty1   OUT NOCOPY NUMBER       - Qty allocated in order_um1      |
28  |    x_allocated_qty1   OUT NOCOPY NUMBER       - Qty allocated in order_um2      |
29  |    x_return_status    OUT NOCOPY VARCHAR2     - Return Status                   |
30  |    x_msg_count        OUT NOCOPY NUMBER       - Number of messages              |
31  |    x_msg_data         OUT NOCOPY VARCHAR2     - Messages in encoded format      |
32  |                                                                          |
33  |                                                                          |
34  | HISTORY                                                                  |
35  | B1731567 - Distinguish co_code associated with cust_no from co_code
36  |            associated with the whse and inventory transactions           |
37  +==========================================================================+
38 */
39 PROCEDURE ALLOCATE_INVENTORY
40 ( p_api_version        IN  NUMBER
41 , p_init_msg_list      IN  VARCHAR2        DEFAULT FND_API.G_FALSE
42 , p_commit             IN  VARCHAR2        DEFAULT FND_API.G_FALSE
43 , p_validation_level   IN  VARCHAR2        DEFAULT FND_API.G_VALID_LEVEL_FULL
44 , p_allocation_rec     IN  gmi_allocation_rec
45 , x_reservation_id     OUT NOCOPY NUMBER
46 , x_allocated_qty1     OUT NOCOPY NUMBER
47 , x_allocated_qty2     OUT NOCOPY NUMBER
48 , x_return_status      OUT NOCOPY VARCHAR2
49 , x_msg_count          OUT NOCOPY NUMBER
50 , x_msg_data           OUT NOCOPY VARCHAR2
51 )
52 IS
53 l_api_name           CONSTANT VARCHAR2 (30) := 'ALLOCATE_INVENTORY';
54 l_api_version        CONSTANT NUMBER        := 1.0;
55 l_allocated_qty1     NUMBER  :=0;
56 l_allocated_qty2     NUMBER  :=0;
57 l_msg_count          NUMBER  :=0;
58 l_msg_data           VARCHAR2(2000);
59 l_return_status      VARCHAR2(1);
60 l_allocation_rec     gmi_allocation_rec;
61 -- HW BUG#:2643440 Need to change out parameter name
62 ll_allocation_rec     gmi_allocation_rec;
63 l_ic_item_mst_rec    ic_item_mst%ROWTYPE;
64 l_ic_item_cpg_rec    ic_item_cpg%ROWTYPE;
65 l_ic_whse_mst_rec    ic_whse_mst%ROWTYPE;
66 l_op_alot_prm_rec    op_alot_prm%ROWTYPE;
67 
68 
69 /* B1731567 - identify co_code associated with whse and orgn_code
70 ================================================================*/
71 CURSOR sy_orgn_mst_c1 is
72 SELECT co_code
73 FROM sy_orgn_mst
74 WHERE orgn_code = l_ic_whse_mst_rec.orgn_code;
75 
76 
77 BEGIN
78 
79   /* Standard Start OF API savepoint
80   =================================*/
81   SAVEPOINT allocate_inventory;
82   oe_debug_pub.add('OPM allocation engine start',1);
83 
84   /*Standard call to check for call compatibility.
85   ==============================================*/
86   IF NOT FND_API.Compatible_API_CALL (  l_api_version
87                                       , p_api_version
88                                       , l_api_name
89                                       , G_PKG_NAME
90                                       )
91   THEN
92     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
93   END IF;
94 
95   /*Initialize message list if p_int_msg_list is set TRUE.
96   ======================================================*/
97   IF FND_API.to_boolean(p_init_msg_list)
98   THEN
99     FND_MSG_PUB.Initialize;
100   END IF;
101 
102   /*Initialize API return status to sucess
103   =======================================*/
104   x_return_status := FND_API.G_RET_STS_SUCCESS;
105 
106   /*Move allocation record to local variable
107   ========================================*/
108   l_allocation_rec := p_allocation_rec;
109 
110   /*Validate input parameters
111   ==========================*/
112   oe_debug_pub.add('OPM allocation engine validate input parms',1);
113 -- HW BUG#: 2643440 pass  ll_allocation_rec as out
114   GMI_VALIDATE_ALLOCATION_PVT.VALIDATE_INPUT_PARMS
115             (p_allocation_rec       => l_allocation_rec,
116              x_ic_item_mst_rec      => l_ic_item_mst_rec,
117              x_ic_whse_mst_rec      => l_ic_whse_mst_rec,
118              x_allocation_rec       => ll_allocation_rec,
119              x_return_status        => l_return_status,
120              x_msg_count            => l_msg_count,
121              x_msg_data             => l_msg_data);
122 
123   /*Return if validation failures detected
124   =======================================*/
125   IF l_return_status = FND_API.G_RET_STS_ERROR
126   THEN
127     RAISE FND_API.G_EXC_ERROR;
128   ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR
129   THEN
130     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
131   END IF;
132 
133   /* Check for existing allocations.
134   Auto Allocation cannot proceed where specific allocations already exist
135   since this could lead to manual allocations being overwritten
136   ======================================================================*/
137   oe_debug_pub.add('OPM allocation engine check for existing txns',1);
138   /*IF GMI_ALLOCATE_INVENTORY_PVT.CHECK_EXISTING_ALLOCATIONS
139             (p_doc_id               => l_allocation_rec.doc_id,
140              p_line_id              => l_allocation_rec.line_id,
141              p_lot_ctl              => l_ic_item_mst_rec.lot_ctl,
142              p_item_loct_ctl        => l_ic_item_mst_rec.loct_ctl,
143              p_whse_loct_ctl        => l_ic_whse_mst_rec.loct_ctl  )
144   THEN
145     oe_debug_pub.add('OPM allocation exit because allocations exist',1);
146     FND_MESSAGE.SET_NAME('GML','GML_CANNOT_AUTO_ALLOC');
147     FND_MESSAGE.SET_TOKEN('ITEM_NO', l_ic_item_mst_rec.item_no);
148     FND_MSG_PUB.Add;
149     RAISE FND_API.G_EXC_ERROR;
150   END IF;*/
151 
152   /* Retrieve allocation rules defined for this item/customer
153   ==========================================================*/
154   oe_debug_pub.add('OPM allocation main - about to fetch allocation parms',1);
155 -- HW BUG#:2643440 chaged l_allocation_rec to ll_allocation_rec
156   GMI_ALLOCATION_RULES_PVT.GET_ALLOCATION_PARMS
157                            ( p_alloc_class   => l_ic_item_mst_rec.alloc_class,
158                              p_org_id        => ll_allocation_rec.org_id,
159                              p_of_cust_id    => ll_allocation_rec.of_cust_id,
160                              p_ship_to_org_id=> ll_allocation_rec.ship_to_org_id,
161                              x_return_status => l_return_status,
162                              x_op_alot_prm   => l_op_alot_prm_rec,
163                              x_msg_count     => l_msg_count,
164                              x_msg_data      => l_msg_data
165                             );
166 
167   /* if no allocation rules found, then Raise Exception and return
168   ===============================================================*/
169   --B1655007 Update exception handling
170   If (l_return_status = FND_API.G_RET_STS_ERROR)
171   THEN
172     FND_MESSAGE.SET_NAME('GML','GML_NO_ALLOCATION_PARMS'); /* NEW */
173     FND_MESSAGE.SET_TOKEN('ALLOC_CLASS', l_ic_item_mst_rec.alloc_class);
174     FND_MSG_PUB.Add;
175     RAISE FND_API.G_EXC_ERROR;
176   ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR
177   THEN
178     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
179   END IF;
180 
181   /* B1731567 - identify co_code associated with whse and orgn_code
182                 it may differ from that associated with the cust_no
183   ================================================================*/
184 -- HW BUG#:2643440 use ll_allocation_rec instead of l_allocation_rec
185   OPEN sy_orgn_mst_c1;
186   FETCH sy_orgn_mst_c1 INTO ll_allocation_rec.co_code;
187 
188   /* Report error if row not located
189   =================================*/
190   IF (sy_orgn_mst_c1%NOTFOUND)
191   THEN
192     CLOSE sy_orgn_mst_c1;
193     FND_MESSAGE.SET_NAME('GMI','IC_API_INVALID_ORGN_CODE');
194     FND_MESSAGE.SET_TOKEN('ORGN_CODE',l_ic_whse_mst_rec.orgn_code);
195     FND_MSG_PUB.Add;
196     RAISE FND_API.G_EXC_ERROR;
197   ELSE
198     CLOSE sy_orgn_mst_c1;
199   END IF;
200 
201   /*Select inventory in accordance with allocation rules
202   =====================================================*/
203   oe_debug_pub.add('OPM allocation engine - now allocate the line',1);
204 -- HW BUG#:2643440 Use  ll_allocation_rec instead of l_allocation_rec
205   GMI_ALLOCATE_INVENTORY_PVT.ALLOCATE_LINE
206                             ( p_allocation_rec => ll_allocation_rec,
207                               p_ic_item_mst => l_ic_item_mst_rec,
208                               p_ic_whse_mst => l_ic_whse_mst_rec,
209                               p_op_alot_prm => l_op_alot_prm_rec,
210                               x_allocated_qty1 => l_allocated_qty1,
211                               x_allocated_qty2 => l_allocated_qty2,
212                               x_return_status  => l_return_status,
213                               x_msg_count      => l_msg_count,
214                               x_msg_data       => l_msg_data
215                             );
216 
217   If (l_return_status = FND_API.G_RET_STS_ERROR)
218   THEN
219     RAISE FND_API.G_EXC_ERROR;
220   ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR
221   THEN
222     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
223   END IF;
224 
225   oe_debug_pub.add('OPM allocation engine - final primary allocation is  '|| l_allocated_qty1);
226   x_allocated_qty1 := l_allocated_qty1;
227   x_allocated_qty2 := l_allocated_qty2;
228 
229 /* EXCEPTION HANDLING
230 ====================*/
231 
232 EXCEPTION
233     WHEN FND_API.G_EXC_ERROR THEN
234       ROLLBACK TO allocate_inventory;
235     /* dbms_output.put_line('ERROR - rollback'); */
236       x_return_status := FND_API.G_RET_STS_ERROR;
237       FND_MSG_PUB.Count_AND_GET (  p_encoded => FND_API.G_FALSE
238                                  , p_count => x_msg_count
239                                  , p_data  => x_msg_data
240                                 );
241 
242     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
243       ROLLBACK TO allocate_inventory;
244     /* dbms_output.put_line('UNEXPECTED ERROR - rollback'); */
245       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
246       FND_MSG_PUB.Count_AND_GET (  p_encoded=> FND_API.G_FALSE
247                                  , p_count => x_msg_count
248                                  , p_data  => x_msg_data
249                                 );
250     WHEN OTHERS THEN
251       ROLLBACK TO allocate_inventory;
252     /* dbms_output.put_line('UNTRAPPED ERROR - rollback'); */
253       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
254 
255       FND_MSG_PUB.Add_Exc_Msg (  G_PKG_NAME
256                                , l_api_name
257                               );
258 
259       FND_MSG_PUB.Count_AND_GET (  p_encoded=> FND_API.G_FALSE
260                                  , p_count => x_msg_count
261                                  , p_data  => x_msg_data
262                                 );
263 
264 END ALLOCATE_INVENTORY;
265 END GMI_AUTO_ALLOCATE_PUB;