1 PACKAGE BODY hxc_trans_display_key_utils AS
2 /* $Header: hxctdkut.pkb 120.3 2008/04/15 13:32:51 bbayragi noship $ */
3 --
4 -- Private Functions and Procedures
5 --
6 -- ----------------------------------------------------------------------------
7 -- |-------------------< replace_row_index_in_key >--------------------|
8 -- ----------------------------------------------------------------------------
9 -- {Start Of Comments}
10 --
11 -- Description:
12 -- This function replaces the row index in a translation display key
13 -- with the new value specified. The translation display key should
14 -- have the usual form: layout_component_id|row_index|column_index -
15 -- in this case, this function will replace the row_index part, and
16 -- return the modified translation display key.
17 --
18 -- Prerequisites:
19 -- The function must be passed a valid translation key.
20 --
21 -- In Parameters:
22 -- Name Reqd Type Description
23 -- p_key Y varchar2 String representation of
24 -- display key.
25 -- p_row Y number New row index
26 --
27 -- Post Success:
28 -- The row index portion of the display key is replaced.
29 --
30 -- Post Failure:
31 -- The function will return an undefined display key is sent an
32 -- invalid translation display key format.
33 --
34 -- Access Status:
35 -- Private.
36 --
37 -- {End Of Comments}
38 --
39 function replace_row_index_in_key
40 (p_key in varchar2,
41 p_row in number)
42 return varchar2 is
43 l_new_key hxc_time_building_blocks.translation_display_key%type;
44 begin
45 l_new_key := substrb(p_key,1,instr(p_key,'|'));
46 l_new_key := l_new_key||p_row;
47 l_new_key := l_new_key||substrb(p_key,instr(p_key,'|',-1));
48 return l_new_key;
49 end replace_row_index_in_key;
50 --
51 -- ----------------------------------------------------------------------------
52 -- |----------------------< row_index_from_key >-----------------------|
53 -- ----------------------------------------------------------------------------
54 -- {Start Of Comments}
55 --
56 -- Description:
57 -- This function returns the row index from a translation key. The
58 -- translation key must have the form:
59 -- layout_component_id|row_index|column_index, i.e. as generated by the
60 -- blockHashMapKey middle tier method in the data translator.
61 --
62 -- Prerequisites:
63 -- The function must be passed a valid translation key.
64 --
65 -- In Parameters:
66 -- Name Reqd Type Description
67 -- p_key Y varchar2 String representation of
68 -- display key.
69 --
70 -- Post Success:
71 -- The row index portion of the translation display key is returned
72 -- as a number.
73 --
74 -- Post Failure:
75 -- The function will return -1 if it is unable to determine the row
76 -- index based on the key.
77 --
78 -- Access Status:
79 -- Private.
80 --
81 -- {End Of Comments}
82 --
83 function row_index_from_key
84 (p_key in varchar2)
85 return number is
86 begin
87 return to_number(substrb
88 (substrb(p_key,instr(p_key,'|')+1),
89 1,
90 instr(substrb(p_key,instr(p_key,'|')+1),'|')-1
91 )
92 );
93 exception
94 when others then
95 return -1;
96
97 end row_index_from_key;
98 --
99 -- Public Functions and Procedures --- see package header for documentation.
100 --
101 -- +--------------------------------------------------------------------------+
102 -- |------------------------< missing_rows >--------------------------|
103 -- +--------------------------------------------------------------------------+
104 --
105 FUNCTION missing_rows
106 (p_row_data in translation_row_used)
107 return boolean is
108 l_index pls_integer;
109 l_sum pls_integer;
110 Begin
111 if(p_row_data.count = 0) then
112 return false;
113 end if;
114
115 l_sum := 0;
116 l_index := 1;
117 Loop
118 Exit when not p_row_data.exists(l_index);
119 l_sum := l_sum +1;
120 l_index := l_index + 1;
121 End Loop;
122
123 if(l_sum <> p_row_data.count) then
124 return true;
125 else
126 return false;
127 end if;
128
129 End missing_rows;
130 --
131 -- +--------------------------------------------------------------------------+
132 -- |-----------------------< new_display_key >------------------------|
133 -- +--------------------------------------------------------------------------+
134 --
135 FUNCTION new_display_key
136 (p_existing_display_key in varchar2,
137 p_existing_row_count in number)
138 return varchar2 is
139 l_key hxc_time_building_blocks.translation_display_key%type;
140 l_layout_comp_id hxc_time_building_blocks.translation_display_key%type;
141 l_row_index hxc_time_building_blocks.translation_display_key%type;
142
143 Begin
144 l_layout_comp_id := substrb(p_existing_display_key,1,instr(p_existing_display_key,'|'));
145 l_key := substrb(p_existing_display_key,(instr(p_existing_display_key,'|')+1));
146 l_row_index := substrb(l_key,1,instr(l_key,'|')-1);
147 l_key := substrb(l_key,instr(l_key,'|',-1));
148 l_key := l_layout_comp_id||(to_number(l_row_index)+p_existing_row_count)||l_key;
149 return l_key;
150 End new_display_key;
151 --
152 -- +--------------------------------------------------------------------------+
153 -- |----------------------< remove_empty_rows >-----------------------|
154 -- +--------------------------------------------------------------------------+
155 --
156 PROCEDURE remove_empty_rows
157 (p_row_data in translation_row_used,
158 p_blocks in out NOCOPY hxc_block_table_type) is
159 l_idx pls_integer;
160 l_row_number pls_integer;
161 l_row_idx number;
162 l_new_row_indices translation_row_used;
163 Begin
164 --
165 -- First step is to find out what the row index should be
166 -- and keep that for later use.
167 --
168 l_row_number := 0;
169 l_idx := p_row_data.first;
170 Loop
171 Exit when NOT p_row_data.exists(l_idx);
172 l_row_number := l_row_number + 1;
173 if(l_row_number <> l_idx) then
174 l_new_row_indices(l_idx) := l_row_number;
175 end if;
176 l_idx := p_row_data.next(l_idx);
177 End Loop;
178 --
179 -- Now loop over the block structure, and reset the translation
180 -- keys where appropriate.
181 --
182 l_idx := p_blocks.first;
183 Loop
184 Exit when NOT p_blocks.exists(l_idx);
185 if (hxc_timecard_block_utils.is_detail_block(p_blocks(l_idx))) then
186 l_row_idx := row_index_from_key(p_blocks(l_idx).translation_display_key);
187 if (l_new_row_indices.exists(l_row_idx)) then
188 -- Must replace the row index in the display key
189 p_blocks(l_idx).translation_display_key :=
190 replace_row_index_in_key
191 (p_blocks(l_idx).translation_display_key,
192 l_new_row_indices(l_row_idx)
193 );
194 end if;
195 end if;
196 l_idx := p_blocks.next(l_idx);
197 End Loop;
198
199 End remove_empty_rows;
200 --
201 -- +--------------------------------------------------------------------------+
202 -- |-------------------< reset_column_index_to_zero >-----------------|
203 -- +--------------------------------------------------------------------------+
204 --
205 FUNCTION reset_column_index_to_zero
206 (p_key in varchar2) return varchar2 is
207 Begin
208 return substrb(p_key,1,instr(p_key,c_key_separator,-1))||'0';
209 End reset_column_index_to_zero;
210 --
211 -- +--------------------------------------------------------------------------+
212 -- |------------------------< set_row_data >--------------------------|
213 -- +--------------------------------------------------------------------------+
214 --
215 PROCEDURE set_row_data
216 (p_key in varchar2,
217 p_row_data in out NOCOPY translation_row_used) is
218
219 l_row_index number;
220
221 Begin
222 if((p_key is null) OR (p_key = '')) then
223 null;
224 else
225 l_row_index := row_index_from_key(p_key);
226 if(NOT p_row_data.exists(l_row_index)) then
227 p_row_data(l_row_index) := 1;
228 end if;
229 end if;
230 End set_row_data;
231 --
232 -- +--------------------------------------------------------------------------+
233 -- |---------------------< timecard_row_count >-----------------------|
234 -- +--------------------------------------------------------------------------+
235 --
236 FUNCTION timecard_row_count
237 (p_blocks in hxc_block_table_type)
238 return number is
239 l_index pls_integer;
240 l_row_index number;
241 l_row_count number;
242 Begin
243 l_row_count := 0;
244 l_index := p_blocks.first;
245 Loop
246 Exit when not p_blocks.exists(l_index);
247 if((p_blocks(l_index).scope = hxc_timecard.c_detail_scope)
248 AND
249 (hxc_timecard_block_utils.is_active_block(p_blocks(l_index))))
250 then
251 l_row_index := row_index_from_key(p_blocks(l_index).translation_display_key);
252 if(l_row_index > l_row_count) then
253 l_row_count := l_row_index;
254 end if;
255 end if;
256 l_index := p_blocks.next(l_index);
257 End Loop;
258 return l_row_count;
259 End timecard_row_count;
260
261 -- Added for DA Enhancement
262 -- +--------------------------------------------------------------------------+
263 -- |---------------------< alter_translation_key >-----------------------|
264 -- +--------------------------------------------------------------------------+
265 --
266
267 PROCEDURE alter_translation_key
268 (p_g_deposit_blocks in out nocopy hxc_block_table_type,
269 p_actual_blocks in hxc_block_table_type
270 ) is
271
272 l_actual_blocks hxc_block_table_type;
273 l_idx NUMBER;
274 l_index NUMBER;
275 l_deposit_translation_key VARCHAR2(100);
276 l_actual_translation_key VARCHAR2(100);
277 BEGIN
278
279 l_actual_blocks := p_actual_blocks;
280
281 l_idx := p_g_deposit_blocks.first;
282 LOOP
283 EXIT WHEN NOT p_g_deposit_blocks.exists(l_idx);
284 IF p_g_deposit_blocks(l_idx).scope = hxc_timecard.c_detail_scope
285 AND p_g_deposit_blocks(l_idx).APPROVAL_STATUS = 'SUBMITTED'
286 THEN
287 /* IF p_g_deposit_blocks(l_idx).MEASURE IS NOT NULL
288 OR (p_g_deposit_blocks(l_idx).START_TIME IS NOT NULL
289 AND p_g_deposit_blocks(l_idx).STOP_TIME IS NOT NULL)
290 THEN
291 */ l_index := l_actual_blocks.first;
292 LOOP
293 EXIT WHEN NOT l_actual_blocks.exists(l_index);
294 IF l_actual_blocks(l_index).scope = hxc_timecard.c_detail_scope
295 AND l_actual_blocks(l_index).APPROVAL_STATUS = 'SUBMITTED'
296 THEN
297 IF l_actual_blocks(l_index).TIME_BUILDING_BLOCK_ID = p_g_deposit_blocks(l_idx).TIME_BUILDING_BLOCK_ID THEN
298 l_deposit_translation_key := p_g_deposit_blocks(l_idx).TRANSLATION_DISPLAY_KEY;
299 l_actual_translation_key := l_actual_blocks(l_index).TRANSLATION_DISPLAY_KEY;
300 l_deposit_translation_key := SUBSTR(l_deposit_translation_key,1,INSTR(l_deposit_translation_key,'|')-1)||
301 SUBSTR(l_actual_translation_key,INSTR(l_actual_translation_key,'|'));
302 p_g_deposit_blocks(l_idx).TRANSLATION_DISPLAY_KEY := l_deposit_translation_key;
303 p_g_deposit_blocks(l_idx).DATE_TO := l_actual_blocks(l_index).DATE_TO;
304 END IF;
305 END IF;
306
307 l_index := l_actual_blocks.next(l_index);
308 END LOOP;--EXIT WHEN NOT l_actual_blocks.exists(l_index);
309 -- END IF;--IF p_g_deposit_blocks(l_idx).MEASURE IS NOT NULL
310 END IF;
311 l_idx := p_g_deposit_blocks.next(l_idx);
312 END LOOP;--EXIT WHEN NOT p_g_deposit_blocks.exists(l_idx1);
313
314
315
316 END alter_translation_key;
317
318
319 END hxc_trans_display_key_utils;