DBA Data[Home] [Help]

PACKAGE BODY: APPS.PQH_WKS_INS

Source


1 Package Body pqh_wks_ins as
2 /* $Header: pqwksrhi.pkb 120.0 2005/05/29 03:01:44 appldev noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33)	:= '  pqh_wks_ins.';  -- Global package name
9 --
10 -- ----------------------------------------------------------------------------
11 -- |------------------------------< insert_dml >------------------------------|
12 -- ----------------------------------------------------------------------------
13 -- {Start Of Comments}
14 --
15 -- Description:
16 --   This procedure controls the actual dml insert logic. The processing of
17 --   this procedure are as follows:
18 --   1) Initialise the object_version_number to 1 if the object_version_number
19 --      is defined as an attribute for this entity.
20 --   2) To insert the row into the schema.
21 --   3) To trap any constraint violations that may have occurred.
22 --   4) To raise any other errors.
23 --
24 -- Prerequisites:
25 --   This is an internal private procedure which must be called from the ins
26 --   procedure and must have all mandatory attributes set (except the
27 --   object_version_number which is initialised within this procedure).
28 --
29 -- In Parameters:
30 --   A Pl/Sql record structre.
31 --
32 -- Post Success:
33 --   The specified row will be inserted into the schema.
34 --
35 -- Post Failure:
36 --   If a check, unique or parent integrity constraint violation is raised the
37 --   constraint_error procedure will be called.
38 --
39 -- Developer Implementation Notes:
40 --   None.
41 --
42 -- Access Status:
43 --   Internal Row Handler Use Only.
44 --
45 -- {End Of Comments}
46 -- ----------------------------------------------------------------------------
47 Procedure insert_dml(p_rec in out nocopy pqh_wks_shd.g_rec_type) is
48 --
49   l_proc  varchar2(72) := g_package||'insert_dml';
50 --
51 Begin
52   hr_utility.set_location('Entering:'||l_proc, 5);
53   p_rec.object_version_number := 1;  -- Initialise the object version
54   --
55   --
56   -- Insert the row into: pqh_worksheets
57   --
58   insert into pqh_worksheets
59   (	worksheet_id,
60 	budget_id,
61 	worksheet_name,
62 	version_number,
63 	action_date,
64 	date_from,
65 	date_to,
66 	worksheet_mode_cd,
67 	transaction_status,
68 	object_version_number,
69 	budget_version_id,
70 	propagation_method,
71         wf_transaction_category_id
72   )
73   Values
74   (	p_rec.worksheet_id,
75 	p_rec.budget_id,
76 	p_rec.worksheet_name,
77 	p_rec.version_number,
78 	p_rec.action_date,
79 	p_rec.date_from,
80 	p_rec.date_to,
81 	p_rec.worksheet_mode_cd,
82 	p_rec.transaction_status,
83 	p_rec.object_version_number,
84 	p_rec.budget_version_id,
85 	p_rec.propagation_method,
86         p_rec.wf_transaction_category_id
87   );
88   --
89   --
90   hr_utility.set_location(' Leaving:'||l_proc, 10);
91 Exception
92   When hr_api.check_integrity_violated Then
93     -- A check constraint has been violated
94     pqh_wks_shd.constraint_error
95       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
96   When hr_api.parent_integrity_violated Then
97     -- Parent integrity has been violated
98     pqh_wks_shd.constraint_error
99       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
100   When hr_api.unique_integrity_violated Then
101     -- Unique integrity has been violated
102     pqh_wks_shd.constraint_error
103       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
104   When Others Then
105     Raise;
106 End insert_dml;
107 --
108 -- ----------------------------------------------------------------------------
109 -- |------------------------------< pre_insert >------------------------------|
110 -- ----------------------------------------------------------------------------
111 -- {Start Of Comments}
112 --
113 -- Description:
114 --   This private procedure contains any processing which is required before
115 --   the insert dml. Presently, if the entity has a corresponding primary
116 --   key which is maintained by an associating sequence, the primary key for
117 --   the entity will be populated with the next sequence value in
118 --   preparation for the insert dml.
119 --
120 -- Prerequisites:
121 --   This is an internal procedure which is called from the ins procedure.
122 --
123 -- In Parameters:
124 --   A Pl/Sql record structre.
125 --
126 -- Post Success:
127 --   Processing continues.
128 --
129 -- Post Failure:
130 --   If an error has occurred, an error message and exception will be raised
131 --   but not handled.
132 --
133 -- Developer Implementation Notes:
134 --   Any pre-processing required before the insert dml is issued should be
135 --   coded within this procedure. As stated above, a good example is the
136 --   generation of a primary key number via a corresponding sequence.
137 --   It is important to note that any 3rd party maintenance should be reviewed
138 --   before placing in this procedure.
139 --
140 -- Access Status:
141 --   Internal Row Handler Use Only.
142 --
143 -- {End Of Comments}
144 -- ----------------------------------------------------------------------------
145 Procedure pre_insert(p_rec  in out nocopy pqh_wks_shd.g_rec_type) is
146 --
147   l_proc  varchar2(72) := g_package||'pre_insert';
148 --
149   Cursor C_Sel1 is select pqh_worksheets_s.nextval from sys.dual;
150 --
151 Begin
152   hr_utility.set_location('Entering:'||l_proc, 5);
153   --
154   --
155   -- Select the next sequence number
156   --
157   Open C_Sel1;
158   Fetch C_Sel1 Into p_rec.worksheet_id;
159   Close C_Sel1;
160   --
161   hr_utility.set_location(' Leaving:'||l_proc, 10);
162 End pre_insert;
163 --
164 -- ----------------------------------------------------------------------------
165 -- |-----------------------------< post_insert >------------------------------|
166 -- ----------------------------------------------------------------------------
167 -- {Start Of Comments}
168 --
169 -- Description:
170 --   This private procedure contains any processing which is required after the
171 --   insert dml.
172 --
173 -- Prerequisites:
174 --   This is an internal procedure which is called from the ins procedure.
175 --
176 -- In Parameters:
177 --   A Pl/Sql record structre.
178 --
179 -- Post Success:
180 --   Processing continues.
181 --
182 -- Post Failure:
183 --   If an error has occurred, an error message and exception will be raised
184 --   but not handled.
185 --
186 -- Developer Implementation Notes:
187 --   Any post-processing required after the insert dml is issued should be
188 --   coded within this procedure. It is important to note that any 3rd party
189 --   maintenance should be reviewed before placing in this procedure.
190 --
191 -- Access Status:
192 --   Internal Row Handler Use Only.
193 --
194 -- {End Of Comments}
195 -- ----------------------------------------------------------------------------
196 Procedure post_insert(
197 p_effective_date in date,p_rec in pqh_wks_shd.g_rec_type) is
198 --
199   l_proc  varchar2(72) := g_package||'post_insert';
200 --
201 
202  l_budgets_rec   pqh_budgets%ROWTYPE;
203 
204  cursor csr_budget(p_budget_id IN number) is
205  select *
206  from pqh_budgets
207  where budget_id = p_budget_id
208    and nvl(status,'X') <> 'FROZEN';
209 
210  l_object_version_number   number(9);
211 
212 --
213 Begin
214   hr_utility.set_location('Entering:'||l_proc, 5);
215 --
216   --
217   -- Start of API User Hook for post_insert.
218   --
219   begin
220     --
221   /*
222      Set the budget status to FROZEN . When budget is forzen, user cannot change UOM in budget
223    */
224     --
225       OPEN csr_budget(p_budget_id =>  p_rec.budget_id);
226         LOOP
227           FETCH csr_budget INTO l_budgets_rec;
228           EXIT WHEN csr_budget%NOTFOUND;
229 
230              hr_utility.set_location('Budget Status :'||l_budgets_rec.status, 6);
231 
232              -- call update API of budget to update the budget status to frozen
233 
234                l_object_version_number := l_budgets_rec.object_version_number;
235 
236                pqh_budgets_api.update_budget
237                (
238                 p_budget_id               => l_budgets_rec.budget_id,
239                 p_object_version_number   => l_object_version_number,
240                 p_status                  => 'FROZEN',
241                 p_effective_date          => sysdate
242                );
243         END LOOP;
244       CLOSE csr_budget;
245 
246 
247     --
248     pqh_wks_rki.after_insert
249       (
250   p_worksheet_id                  =>p_rec.worksheet_id
251  ,p_budget_id                     =>p_rec.budget_id
252  ,p_worksheet_name                =>p_rec.worksheet_name
253  ,p_version_number                =>p_rec.version_number
254  ,p_action_date                   =>p_rec.action_date
255  ,p_date_from                     =>p_rec.date_from
256  ,p_date_to                       =>p_rec.date_to
257  ,p_worksheet_mode_cd             =>p_rec.worksheet_mode_cd
258  ,p_transaction_status                        =>p_rec.transaction_status
259  ,p_object_version_number         =>p_rec.object_version_number
260  ,p_budget_version_id             =>p_rec.budget_version_id
261  ,p_propagation_method            =>p_rec.propagation_method
262  ,p_effective_date                =>p_effective_date
263  ,p_wf_transaction_category_id    =>p_rec.wf_transaction_category_id
264       );
265     --
266   exception
267     --
268     when hr_api.cannot_find_prog_unit then
269       --
270       hr_api.cannot_find_prog_unit_error
271         (p_module_name => 'pqh_worksheets'
272         ,p_hook_type   => 'AI');
273       --
274   end;
275   --
276   -- End of API User Hook for post_insert.
277   --
278   --
279   hr_utility.set_location(' Leaving:'||l_proc, 10);
280 End post_insert;
281 --
282 -- ----------------------------------------------------------------------------
283 -- |---------------------------------< ins >----------------------------------|
284 -- ----------------------------------------------------------------------------
285 Procedure ins
286   (
287   p_effective_date in date,
288   p_rec        in out nocopy pqh_wks_shd.g_rec_type
289   ) is
290 --
291   l_proc  varchar2(72) := g_package||'ins';
292 --
293 Begin
294   hr_utility.set_location('Entering:'||l_proc, 5);
295   --
296   -- Call the supporting insert validate operations
297   --
298   pqh_wks_bus.insert_validate(p_rec
299   ,p_effective_date);
300   --
301   -- Call the supporting pre-insert operation
302   --
303   pre_insert(p_rec);
304   --
305   -- Insert the row
306   --
307   insert_dml(p_rec);
308   --
309   -- Call the supporting post-insert operation
310   --
311   post_insert(
312 p_effective_date,p_rec);
313 end ins;
314 --
315 -- ----------------------------------------------------------------------------
316 -- |---------------------------------< ins >----------------------------------|
317 -- ----------------------------------------------------------------------------
318 Procedure ins
319   (
320   p_effective_date in date,
321   p_worksheet_id                 out nocopy number,
322   p_budget_id                    in number,
323   p_worksheet_name               in varchar2,
324   p_version_number               in number,
325   p_action_date                  in date,
326   p_date_from                    in date             default null,
327   p_date_to                      in date             default null,
328   p_worksheet_mode_cd            in varchar2         default null,
329   p_transaction_status                       in varchar2         default null,
330   p_object_version_number        out nocopy number,
331   p_budget_version_id            in number,
332   p_propagation_method           in varchar2         default null,
333   p_wf_transaction_category_id   in number
334   ) is
335 --
336   l_rec	  pqh_wks_shd.g_rec_type;
337   l_proc  varchar2(72) := g_package||'ins';
338 --
339 Begin
340   hr_utility.set_location('Entering:'||l_proc, 5);
341   --
342   -- Call conversion function to turn arguments into the
343   -- p_rec structure.
344   --
345   l_rec :=
346   pqh_wks_shd.convert_args
347   (
348   null,
349   p_budget_id,
350   p_worksheet_name,
351   p_version_number,
352   p_action_date,
353   p_date_from,
354   p_date_to,
355   p_worksheet_mode_cd,
356   p_transaction_status,
357   null,
358   p_budget_version_id,
359   p_propagation_method,
360   p_wf_transaction_category_id
361   );
362   --
363   -- Having converted the arguments into the pqh_wks_rec
364   -- plsql record structure we call the corresponding record business process.
365   --
366   ins(
367     p_effective_date,l_rec);
368   --
369   -- As the primary key argument(s)
370   -- are specified as an OUT's we must set these values.
371   --
372   p_worksheet_id := l_rec.worksheet_id;
373   p_object_version_number := l_rec.object_version_number;
374   --
375   hr_utility.set_location(' Leaving:'||l_proc, 10);
376 End ins;
377 --
378 end pqh_wks_ins;