DBA Data[Home] [Help]

PACKAGE BODY: APPS.ICX_REQ_ACCT_DIST

Source


1 PACKAGE BODY icx_req_acct_dist AS
2 /* $Header: ICXRQADB.pls 115.5 99/07/17 03:22:32 porting ship $ */
3 
4 
5 PROCEDURE get_default_account (v_cart_id IN NUMBER,
6                                v_cart_line_id IN NUMBER,
7                                v_emp_id IN NUMBER,
8                                v_oo_id IN NUMBER,
9                                v_item_id IN VARCHAR2,
10                                v_account_id OUT NUMBER,
11                                v_account_num OUT VARCHAR2
12 
13 ) IS
14 
15  CURSOR line_default_account(v_cart_id number,v_cart_line_id number,
16                              v_item_id number, v_emp_id number,
17                              v_oo_id number) IS
18         SELECT  hecv.default_code_combination_id employee_default_account_id,
19                 msi.expense_account
20         FROM    hr_employees_current_v hecv,
21                 mtl_system_items msi,
22                 icx_shopping_carts isc,
23                 icx_shopping_cart_lines iscl
24         WHERE   msi.INVENTORY_ITEM_ID (+) = iscl.ITEM_ID
25         AND     nvl(msi.ORGANIZATION_ID,
26                     nvl(isc.DESTINATION_ORGANIZATION_ID,
27                         iscl.DESTINATION_ORGANIZATION_ID)) =
28                 nvl(isc.DESTINATION_ORGANIZATION_ID,
29                     iscl.DESTINATION_ORGANIZATION_ID)
30         AND     hecv.EMPLOYEE_ID = v_emp_id
31         AND     iscl.cart_id = v_cart_id
32         AND     iscl.cart_line_id = v_cart_line_id
33         AND     nvl(isc.org_id, -9999) = nvl(v_oo_id, -9999)
34         AND     nvl(iscl.org_id, -9999) = nvl(v_oo_id, -9999);
35 
36       CURSOR chart_account_id IS
37       SELECT CHART_OF_ACCOUNTS_ID
38       FROM gl_sets_of_books,
39            financials_system_parameters fsp
40       WHERE gl_sets_of_books.SET_OF_BOOKS_ID = fsp.set_of_books_id;
41 
42 
43 BEGIN
44  null;
45 
46 EXCEPTION
47   WHEN OTHERS THEN
48     -- htp.p('Error in display acct distributions ' || substr(SQLERRM, 1, 512));
49     icx_util.add_error(substr(SQLERRM, 12, 512));
50 
51 END get_default_account;
52 
53 ------------------------------------------------------
54 PROCEDURE display_acct_distributions (p_cart_line_id IN NUMBER,
55                                       p_cart_id IN NUMBER,
56                                       p_show_more_lines IN NUMBER DEFAULT NULL,
57                           icx_charge_acct_seg1 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
58                           icx_charge_acct_seg2 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
59                           icx_charge_acct_seg3 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
60                           icx_charge_acct_seg4 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
61                           icx_charge_acct_seg5 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
62                           icx_charge_acct_seg6 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
63                           icx_charge_acct_seg7 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
64                           icx_charge_acct_seg8 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
65                           icx_charge_acct_seg9 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
66                           icx_charge_acct_seg10 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
67                           icx_charge_acct_seg11 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
68                           icx_charge_acct_seg12 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
69                           icx_charge_acct_seg13 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
70                           icx_charge_acct_seg14 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
71                           icx_charge_acct_seg15 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
72                           icx_charge_acct_seg16 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
73                           icx_charge_acct_seg17 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
74                           icx_charge_acct_seg18 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
75                           icx_charge_acct_seg19 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
76                           icx_charge_acct_seg20 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
77                           icx_charge_acct_seg21 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
78                           icx_charge_acct_seg22 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
79                           icx_charge_acct_seg23 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
80                           icx_charge_acct_seg24 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
81                           icx_charge_acct_seg25 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
82                           icx_charge_acct_seg26 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
83                           icx_charge_acct_seg27 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
84                           icx_charge_acct_seg28 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
85                           icx_charge_acct_seg29 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
86                           icx_charge_acct_seg30 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
87                           icx_charge_account_num IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
88                           icx_percentage IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
89                           icx_amount IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
90                           icx_distribution_num IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
91                           icx_distribution_id IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
92                           v_error_text IN VARCHAR2 DEFAULT NULL
93                                      ) IS
94 
95 v_cart_line_id      NUMBER := NULL;
96 v_cart_id           NUMBER := NULL;
97 v_title             VARCHAR2(80) := NULL;
98 v_prompts           icx_util.g_prompts_table;
99 v_encrypted_where   NUMBER := NULL;
100 v_where_clause      VARCHAR2(1000) := NULL;
101 v_web_user_id       NUMBER := NULL;
102 v_responsibility_id NUMBER := NULL;
103 v_language_code     VARCHAR2(30) := NULL;
104 v_dcd_name          VARCHAR2(200) := NULL;
105 v_multirow_color varchar2(30) := NULL;
106 v_rows_returned     NUMBER := NULL;
107 v_extended_price     NUMBER := NULL;
108 v_percentage_value   NUMBER := NULL;
109 
110 -- total number of lines displayed intially and the increment is 5
111 -- this value is hard coded
112 v_fixed_line_count     NUMBER := 5;
113 v_total_lines_entered  NUMBER := 5;
114 v_display_lines        NUMBER := NULL;
115 v_value		varchar2(240) := NULL;
116 
117 l_values        icx_util.char240_table;
118 l_pos           NUMBER := 0 ;
119 
120 
121 -- the following variable hold the charge account values
122 -- these will be used as hidden variables in the FORM
123 v_charge_account_seg1  VARCHAR2(240) := NULL;
124 v_charge_account_seg2  VARCHAR2(240) := NULL;
125 v_charge_account_seg3  VARCHAR2(240) := NULL;
126 v_charge_account_seg4  VARCHAR2(240) := NULL;
127 v_charge_account_seg5  VARCHAR2(240) := NULL;
128 v_charge_account_seg6  VARCHAR2(240) := NULL;
129 v_charge_account_seg7  VARCHAR2(240) := NULL;
130 v_charge_account_seg8  VARCHAR2(240) := NULL;
131 v_charge_account_seg9  VARCHAR2(240) := NULL;
132 v_charge_account_seg10  VARCHAR2(240) := NULL;
133 v_charge_account_seg11  VARCHAR2(240) := NULL;
134 v_charge_account_seg12  VARCHAR2(240) := NULL;
135 v_charge_account_seg13  VARCHAR2(240) := NULL;
136 v_charge_account_seg14  VARCHAR2(240) := NULL;
137 v_charge_account_seg15  VARCHAR2(240) := NULL;
138 v_charge_account_seg16  VARCHAR2(240) := NULL;
139 v_charge_account_seg17  VARCHAR2(240) := NULL;
140 v_charge_account_seg18  VARCHAR2(240) := NULL;
141 v_charge_account_seg19  VARCHAR2(240) := NULL;
142 v_charge_account_seg20  VARCHAR2(240) := NULL;
143 v_charge_account_seg21  VARCHAR2(240) := NULL;
144 v_charge_account_seg22  VARCHAR2(240) := NULL;
145 v_charge_account_seg23  VARCHAR2(240) := NULL;
146 v_charge_account_seg24  VARCHAR2(240) := NULL;
147 v_charge_account_seg25  VARCHAR2(240) := NULL;
148 v_charge_account_seg26  VARCHAR2(240) := NULL;
149 v_charge_account_seg27  VARCHAR2(240) := NULL;
150 v_charge_account_seg28  VARCHAR2(240) := NULL;
151 v_charge_account_seg29  VARCHAR2(240) := NULL;
152 v_charge_account_seg30  VARCHAR2(240) := NULL;
153 v_charge_account_num  VARCHAR2(240) := NULL;
154 
155 v_distribution_header_region VARCHAR2(50) := NULL;
156 v_distribution_lines_region  VARCHAR2(50) := NULL;
157 
158 v_display_first varchar2(1000) := NULL;
159 
160 BEGIN
161 
162  IF icx_sec.validateSession('ICX_REQS') THEN
163 
164    v_dcd_name := owa_util.get_cgi_env('SCRIPT_NAME');
165    v_language_code := icx_sec.getID(icx_sec.PV_LANGUAGE_CODE);
166    v_web_user_id := icx_sec.getID(icx_sec.PV_WEB_USER_ID);
167    v_responsibility_id  := icx_sec.getID(icx_sec.PV_RESPONSIBILITY_ID);
168 
169    v_cart_id :=  icx_call.decrypt2(p_cart_id);
170    -- v_cart_line_id :=  icx_call.decrypt2(p_cart_line_id);
171    -- cart line id is not encrypted from my order page
172    v_cart_line_id :=  p_cart_line_id;
173 
174    v_total_lines_entered := icx_percentage.COUNT;
175 
176    -- Initialise header and line regions
177    v_distribution_header_region := 'ICX_CART_LINE_ACCOUNT_HEADER_R';
178    v_distribution_lines_region  := 'ICX_CART_LINE_DISTRIBUTIONS_R';
179 
180    v_multirow_color := icx_util.get_color('TABLE_DATA_MULTIROW');
181 
182    icx_util.getPrompts(601, v_distribution_header_region, v_title, v_prompts);
183    icx_util.error_page_setup;
184 
185    -- v_encrypted_where := p_where;
186 
187    v_where_clause := 'CART_ID =' || v_cart_id || 'AND CART_LINE_ID =' || v_cart_line_id;
188 
189    htp.htmlOpen;
190    htp.headOpen;
191    icx_util.copyright;
192    js.scriptOpen;
193 
194    htp.p('function submit() {
195              // document.ACCOUNT_DISTRIBUTION.cart_id.value = parent.parent.cartId;
196              // parent.frames[0].document.ACCOUNT_DISTRIBUTION.submit();
197              document.ACCOUNT_DISTRIBUTION.p_user_action.value ="APPLY";
198              document.ACCOUNT_DISTRIBUTION.submit();
199           }');
200 
201    htp.p('function apply_to_all() {
202              document.ACCOUNT_DISTRIBUTION.p_user_action.value ="APPLY_TO_ALL";
203              // parent.frames[0].document.ACCOUNT_DISTRIBUTION.submit();
204              document.ACCOUNT_DISTRIBUTION.submit();
205           }');
206 
207    htp.p('function show_more_lines() {
208              document.ACCOUNT_DISTRIBUTION.p_user_action.value ="MORE_LINES";
209              // parent.frames[0].document.ACCOUNT_DISTRIBUTION.submit();
210              document.ACCOUNT_DISTRIBUTION.submit();
211           }');
212 
213    htp.p('function cancel_account() {
214              document.ACCOUNT_DISTRIBUTION.p_user_action.value ="CANCEL";
215              parent.parent.account_dist="";
216              top.switchFrames("my_order");
217           }');
218 
219    fnd_message.set_name('ICX','ICX_NOT_NUMBER');
220    htp.p('function checkNumber(input) {
221           var msg = input.value + " '||icx_util.replace_quotes(fnd_message.get)||'";
222 
223           var str = input.value;
224           for (var i = 0; i < str.length; i++) {
225               var ch = str.substring(i, i + 1);
226               if ((ch < "0" || "9" < ch) && ch != ".") {
227                  alert(msg);
228                  return false;
229               }
230            }
231            return true;
232           }
233          ');
234 
235    -- Round the decimal part to 'roundDigits' digits
236 --    htp.p('function roundDecimals (input, roundDigits) {
237 --           var integerPart = input.value;
238 --           var decimalPart;
239 --           var tempVal;
240 --           integerPart = Math.floor(integerPart);
241 --           // added this if condition, bug#585186
242 --           if (roundDigits == 5)  {
243 --           tempVal = "" + Math.round(input.value * 100000);
244 --           }
245 --           else {
246 --           tempVal = "" + Math.round(input.value * 100);
247 --           }
248 --           decimalPart = tempVal.substring(tempVal.length - roundDigits, tempVal.length);
249 
250 --           // return(integerPart+"."+decimalPart);
254 --         ');
251 --           input.value = integerPart+"."+decimalPart;
252 
253 --           }
255    -- Round the decimal part to 'roundDigits' digits
256 --    htp.p('function roundDecimalsValue (input, roundDigits) {
257 --           var integerPart = input;
258 --           var decimalPart;
259 --           var tempVal;
260 --           integerPart = Math.floor(integerPart);
261 --           // added this if condition, bug#585186
262 --           if (roundDigits == 5) {
263 --             tempVal = "" + Math.round(input * 100000);
264 --           }
265 --           else {
266 --             tempVal = "" + Math.round(input * 100);
267 --           }
268 --           decimalPart = tempVal.substring(tempVal.length - roundDigits, tempVal.length);
269 
270 --           return(integerPart+"."+decimalPart);
271 
272 --           }
273 	    --         ');
274 
275 
276 	    --MC: made the following changes for bug # 700664:
277 -- 	    changed set_percent as follows:
278 -- 	      after setting the ICX_PERCENT column, also checks to see if
279 -- 	      the amount totals to the extended price.  If so, adjust the
280 -- 	      last percent field that has just been set so that percent
281 -- 	      totals to 100%.
282 -- 	      Vice versa for set_amount.
283 -- 	      also changed roundDecimals and roundDecimalsValue s.t b/c it
284 -- 	      was bahaving strangely in some cases.
285 
286 	    --added for bug # 700664:
287 	    htp.p('
288 		  function roundDecimals (input, roundDigits)
289 		  {
290 		  var tmp= roundDecimalsValue(input.value, roundDigits);
291 		  input.value= tmp;
292 		  }
293 		  ');
294 
295 	    --added for bug # 700664:
296 	    htp.p('
297 		  function roundDecimalsValue (input, roundDigits) {
298 		  var str= "" + Math.round(eval(input) * Math.pow(10, roundDigits));
299 		  while (str.length <= roundDigits)
300 		  {
301 		  str= "0"+str;
302 		  }
303 		  var decpoint= str.length- roundDigits;
304 		  return str.substring(0, decpoint) + "." + str.substring(decpoint, str.length);
305 		  }');
306 
307 
308    htp.p('function get_forward_pos(start_pos) {
309           var end_pos=0;
310           if (document.ACCOUNT_DISTRIBUTION.elements[start_pos].name == "ICX_AMOUNT") {
311 	     var name2 = "ICX_PERCENTAGE";
312           } else {
313              var name2 = "ICX_AMOUNT";
314           }
315           for (var i=start_pos; i < document.ACCOUNT_DISTRIBUTION.elements.length; i++) {
316              if (document.ACCOUNT_DISTRIBUTION.elements[i].name == name2) {
317                 end_pos=i;
318                     break;
319                 }
320          }
324            if (document.ACCOUNT_DISTRIBUTION.elements[0].name !=  name2) {
321          if (end_pos != 0) {
322             return end_pos;
323          } else {
325               return -1;
326            } else {
327 	      return 0;
328            }
329          }
330         }');
331 
332    htp.p('function get_backward_pos(start_pos) {
333           var end_pos=0;
334           if (document.ACCOUNT_DISTRIBUTION.elements[start_pos].name == "ICX_AMOUNT") {
335              var name1 = "ICX_PERCENTAGE";
336           } else {
337              var name1 = "ICX_AMOUNT";
338           }
339 
340           var i=start_pos;
341           while(i >= 0) {
342 	      if (document.ACCOUNT_DISTRIBUTION.elements[i].name == name1) {
343                   end_pos=i;
344                   break;
345               } else {
346                 i = i - 1;
347                 end_pos = i;
348               }
349           }
350              return end_pos;
351 
352           }');
353 
354 
355          htp.p('function set_percent(pos,qty,value1,direction) {
356                if(direction == 0) {
357                   var npos = get_forward_pos(pos);
358                } else {
359                   var npos = get_backward_pos(pos);
360                }
361                if (npos >= 0) {
362                 //  document.ACCOUNT_DISTRIBUTION.elements[npos].value=qty * 100 / value1;
363                 var tempValue = qty * 100 / value1;
364                 document.ACCOUNT_DISTRIBUTION.elements[npos].value=roundDecimalsValue(tempValue, 5);
365 
366                 if (get_total_percent()  !=100 &&
367                     get_total_amount() == value1)
368                 {
369                   var newTempValue= (100-get_total_percent())+
370                        parseFloat(document.ACCOUNT_DISTRIBUTION.elements[npos].value);
371                   document.ACCOUNT_DISTRIBUTION.elements[npos].value=
372                        roundDecimalsValue(newTempValue, 5);
373                 }
374 
375                }
376 	   }');
377 
378          htp.p('function set_amount(pos,per,extended,direction) {
379                 if(direction == 0) {
380                    var npos = get_forward_pos(pos);
381                 } else {
382 		   var npos = get_backward_pos(pos);
383                 }
384                 if (npos >=0) {
385                    // document.ACCOUNT_DISTRIBUTION.elements[npos].value=extended * per / 100;
386                    var tempValue = extended * per /100;
387                    document.ACCOUNT_DISTRIBUTION.elements[npos].value=roundDecimalsValue(tempValue, 2);
388 
389                 if (get_total_percent()  ==100 &&
390                     get_total_amount() !=extended)
391                 {
392                   var newTempValue= (extended-get_total_amount())+
393                        parseFloat(document.ACCOUNT_DISTRIBUTION.elements[npos].value);
394                    document.ACCOUNT_DISTRIBUTION.elements[npos].value=
395                        roundDecimalsValue(newTempValue, 2);
396                 }
400          }');
397 
398 
399               }
401 
402 	       htp.p('function get_total_amount()
403 		     {
404 		      var amt=0;
405 		      for(var i=0;
406 			  i<document.forms.ACCOUNT_DISTRIBUTION.ICX_AMOUNT.length;
407 			  i++)
408 		      {
409 		       var tmp=
410 		        parseFloat(document.forms.ACCOUNT_DISTRIBUTION.ICX_AMOUNT[i].value);
411 		       if (!isNaN(tmp))
412 		        amt= amt + tmp;
413 		      }
414 		      return amt;
415 		     }');
416 
417 		     htp.p('function get_total_percent()
418 			    {
419 			     var pct=0;
420 			     for(var i=0;
421 				 i<document.forms.ACCOUNT_DISTRIBUTION.ICX_PERCENTAGE.length;
422 				 i++)
423 			     {
424 			      var tmp=
425 			        parseFloat(document.forms.ACCOUNT_DISTRIBUTION.ICX_PERCENTAGE[i].value);
426 			      if (!isNaN(tmp))
427 			         pct= pct + tmp;
428 			      }
429 			      return pct;
430 			    } ');
431 
432    js.scriptClose;
433    htp.title(v_title);
434    htp.headClose;
435 
436    htp.bodyOpen('','BGCOLOR="#CCFFFF" onLoad="top.winOpen(''nav'', ''my_order'')"');
437 
438    htp.header(3, v_title);
439 
440    htp.p('<FORM ACTION="' || v_dcd_name || '/icx_req_acct_dist.submit_accounts"  NAME="ACCOUNT_DISTRIBUTION" METHOD="POST">');
441 
442    htp.formHidden('p_cart_id', p_cart_id);
443    htp.formHidden('p_cart_line_id', icx_call.encrypt2(p_cart_line_id));
444    htp.formHidden('p_user_action', '');
445 
446    l_pos := l_pos + 3;
447 
448    -- call error display procedure
449    display_account_errors(v_cart_id, v_cart_line_id);
450 
451    IF v_error_text IS NOT NULL THEN
452      /* Changed to new font, to be in consistent with other errors
453      FND_MESSAGE.SET_NAME('ICX','ICX_ERROR');
454      htp.p(htf.bold(FND_MESSAGE.GET));
455      htp.br;
456      htp.p(htf.bold(v_error_text));
457      htp.br;
458      htp.br;
459      */
460      htp.p('<TABLE BORDER=5>');
461      htp.p('<TR><TD>' || v_error_text || '</TD></TR>');
462      htp.p('</TABLE>');
463      htp.br;
464    END IF;  /* IF v_error_text */
465 
466    ak_query_pkg.exec_query(P_PARENT_REGION_APPL_ID => 601,
467                            P_PARENT_REGION_CODE    => v_distribution_header_region,
468                            P_RESPONSIBILITY_ID     => v_responsibility_id,
469                            P_USER_ID               => v_web_user_id,
470                            P_WHERE_CLAUSE          => v_where_clause,
471                            P_RETURN_PARENTS        => 'T',
472                            P_RETURN_CHILDREN       => 'F');
473 
474 
475    -- debug, turn on to dump the results table after the ak query
476    -- icx_on_utilities2.printPLSQLtables;
477 
481 
478    display_account_header(v_extended_price);
479 
480    /* Display account distribution lines */
482 
483    /* p_show_more_lines holds the number of number of lines displayed.
484       If show more lines button is pressed then the total number of lines
485       to be displayed will be lines displayed + the fixed line count.
486    */
487    IF p_show_more_lines IS NOT NULL THEN
488 
489     /* If show more lines is clicked then get only the structure, no data
490       from AK. Set P_RETURN_PARENTS => 'F'   */
491     ak_query_pkg.exec_query(P_PARENT_REGION_APPL_ID => 601,
492                             P_PARENT_REGION_CODE    => v_distribution_lines_region,
493                             P_RESPONSIBILITY_ID     => v_responsibility_id,
494                             P_USER_ID               => v_web_user_id,
495                             P_WHERE_CLAUSE          => v_where_clause,
496                             P_RETURN_PARENTS        => 'F',
497                             P_RETURN_CHILDREN       => 'F');
498 
499     print_lines_header;
500 
501     -- determine if amount is ahead of quantity or quantity is ahead of amount
502     v_display_first := NULL;
503     for j IN 0..ak_query_pkg.g_items_table.LAST LOOP
504         if ak_query_pkg.g_items_table(j).attribute_code = 'ICX_PERCENTAGE' and
505            v_display_first is NULL then
506            v_display_first := 'ICX_PERCENTAGE';
507            exit;
508         elsif ak_query_pkg.g_items_table(j).attribute_code = 'ICX_AMOUNT' and
509 	   v_display_first is NULL then
510            v_display_first := 'ICX_AMOUNT';
511            exit;
512         end if;
513     end loop;
514 
515     IF v_error_text IS NULL THEN
516       v_display_lines := p_show_more_lines + v_fixed_line_count;
517     ELSE
518       v_display_lines := p_show_more_lines;
519     END IF; /* IF v_error_text */
520 
521     FOR r IN 1 .. v_display_lines LOOP
522 
523       htp.p('<TR BGColor="#'||v_multirow_color||'">');
524 
525       FOR i IN 0 .. ak_query_pkg.g_items_table.LAST LOOP
526       -- FOR i IN 1 .. ak_query_pkg.g_items_table.LAST LOOP
527 
528         v_value := NULL;
529 
530         IF ak_query_pkg.g_items_table(i).node_display_flag = 'Y'
531         AND ak_query_pkg.g_items_table(i).secured_column = 'F'
532         AND ak_query_pkg.g_items_table(i).item_style = 'HIDDEN' THEN
533 
534           -- The condition icx_distribution_id.count >= r is required to
535           -- prevent a memory out of bound value.
536           -- The hidden values are returned only for those displayed in the
537           -- browser. So if one distribution id is displayed as hidden value
538           -- the count will be 1. If 5 distribution ids are displayed as hidden
539           -- distribution count will be 5.
540           IF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_DISTRIBUTION_ID'  AND (icx_distribution_id.COUNT >= r) THEN
541 
542             v_value := icx_distribution_id(r);
543             htp.formHidden(cname => ak_query_pkg.g_items_table(i).attribute_code , cvalue => v_value);
544             l_pos := l_pos + 1;
545 
549 	IF ak_query_pkg.g_items_table(i).node_display_flag = 'Y'
546           END IF;  /* ICX_DISTRIBUTION_ID */
547         END IF;  /* item_style = 'HIDDEN' */
548 
550         AND ak_query_pkg.g_items_table(i).secured_column = 'F'
551         AND ak_query_pkg.g_items_table(i).item_style <> 'HIDDEN' THEN
552 
553 
554             IF r <= v_total_lines_entered THEN
555               IF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG1' THEN
556               v_value := icx_charge_acct_seg1(r);
557               ----------------------------------------------------------------
558               -- Note:
559               -- Get the display only segment value to populate the
560               -- hidden fields later. This is done for all the charge accounts.
561               -- Just get the value for only one as this the same for all the
562               -- attributes which are turned to display only.
563               -- v_charge_account_seg1 := icx_charge_acct_seg1(1);
564               -- This is done repeatedly in this loop rather than in a different
565               -- loop to avoid performance degradation. (avoding another loop!)
566               ----------------------------------------------------------------
567               v_charge_account_seg1 := icx_charge_acct_seg1(1);
568               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG2' THEN
569               v_value := icx_charge_acct_seg2(r);
570               v_charge_account_seg2 := icx_charge_acct_seg2(1);
571               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG3' THEN
572               v_value := icx_charge_acct_seg3(r);
573               v_charge_account_seg3 := icx_charge_acct_seg3(1);
574               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG4' THEN
575               v_value := icx_charge_acct_seg4(r);
576               v_charge_account_seg4 := icx_charge_acct_seg4(1);
577               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG5' THEN
578               v_value := icx_charge_acct_seg5(r);
579               v_charge_account_seg5 := icx_charge_acct_seg5(1);
580               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG6' THEN
581               v_value := icx_charge_acct_seg6(r);
582               v_charge_account_seg6 := icx_charge_acct_seg6(1);
583               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG7' THEN
584               v_value := icx_charge_acct_seg7(r);
585               v_charge_account_seg7 := icx_charge_acct_seg7(1);
586               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG8' THEN
587               v_value := icx_charge_acct_seg8(r);
588               v_charge_account_seg8 := icx_charge_acct_seg8(1);
589               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG9' THEN
590               v_value := icx_charge_acct_seg9(r);
591               v_charge_account_seg9 := icx_charge_acct_seg9(1);
592               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG10' THEN
593               v_value := icx_charge_acct_seg10(r);
594               v_charge_account_seg10 := icx_charge_acct_seg10(1);
595               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG11' THEN
596               v_value := icx_charge_acct_seg11(r);
597               v_charge_account_seg11 := icx_charge_acct_seg11(1);
601               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG13' THEN
598               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG12' THEN
599               v_value := icx_charge_acct_seg12(r);
600               v_charge_account_seg12 := icx_charge_acct_seg12(1);
602               v_value := icx_charge_acct_seg13(r);
603               v_charge_account_seg13 := icx_charge_acct_seg13(1);
604               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG14' THEN
605               v_value := icx_charge_acct_seg14(r);
606               v_charge_account_seg14 := icx_charge_acct_seg14(1);
607               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG15' THEN
608               v_value := icx_charge_acct_seg15(r);
609               v_charge_account_seg15 := icx_charge_acct_seg15(1);
610               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG16' THEN
611               v_value := icx_charge_acct_seg16(r);
612               v_charge_account_seg16 := icx_charge_acct_seg16(1);
613               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG17' THEN
614               v_value := icx_charge_acct_seg17(r);
615               v_charge_account_seg17 := icx_charge_acct_seg17(1);
616               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG18' THEN
617               v_value := icx_charge_acct_seg18(r);
618               v_charge_account_seg18 := icx_charge_acct_seg18(1);
619               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG19' THEN
620               v_value := icx_charge_acct_seg19(r);
621               v_charge_account_seg19 := icx_charge_acct_seg19(1);
622               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG20' THEN
623               v_value := icx_charge_acct_seg20(r);
624               v_charge_account_seg20 := icx_charge_acct_seg20(1);
625               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG21' THEN
626               v_value := icx_charge_acct_seg21(r);
627               v_charge_account_seg21 := icx_charge_acct_seg21(1);
628               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG22' THEN
629               v_value := icx_charge_acct_seg22(r);
630               v_charge_account_seg22 := icx_charge_acct_seg22(1);
631               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG23' THEN
632               v_value := icx_charge_acct_seg23(r);
633               v_charge_account_seg23 := icx_charge_acct_seg23(1);
634               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG24' THEN
635               v_value := icx_charge_acct_seg24(r);
636               v_charge_account_seg24 := icx_charge_acct_seg24(1);
637               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG25' THEN
638               v_value := icx_charge_acct_seg25(r);
639               v_charge_account_seg25 := icx_charge_acct_seg25(1);
640               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG26' THEN
641               v_value := icx_charge_acct_seg26(r);
642               v_charge_account_seg26 := icx_charge_acct_seg26(1);
643               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG27' THEN
647               v_value := icx_charge_acct_seg28(r);
644               v_value := icx_charge_acct_seg27(r);
645               v_charge_account_seg27 := icx_charge_acct_seg27(1);
646               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG28' THEN
648               v_charge_account_seg28 := icx_charge_acct_seg28(1);
649               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG29' THEN
650               v_value := icx_charge_acct_seg29(r);
651               v_charge_account_seg29 := icx_charge_acct_seg29(1);
652               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG30' THEN
653               v_value := icx_charge_acct_seg30(r);
654               v_charge_account_seg30 := icx_charge_acct_seg30(1);
655               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_NUM' THEN
656               v_value := icx_charge_account_num(r);
657               v_charge_account_num := icx_charge_account_num(1);
658               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_PERCENTAGE' THEN
659               v_value := icx_percentage(r);
660               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_AMOUNT' THEN
661               v_value := icx_amount(r);
662               ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_DISTRIBUTION_NUM' THEN
663               v_value := icx_distribution_num(r);
664               END IF; /* ak_query_pkg. ... ICX_ ... */
665             ELSE
666               v_value := NULL;
667             END IF;  /* i < v_total_lines_entered */
668 
669             IF ak_query_pkg.g_items_table(i).update_flag = 'Y' THEN
670 		 IF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_PERCENTAGE'  THEN
671                     IF v_display_first = ak_query_pkg.g_items_table(i).attribute_code THEN
672                        htp.tableData(cvalue => '<INPUT TYPE="TEXT" NAME = ' || ak_query_pkg.g_items_table(i).attribute_code || ' SIZE=' || ak_query_pkg.g_items_table(i).display_value_length || ' VALUE = "'|| v_value
673 ||'" onChange=''if(!checkNumber(this)) { this.focus();this.value="";} else {roundDecimals(this, 5); set_amount(' || to_char(l_pos) || ',this.value,' || v_extended_price || ',0);}''>', crowspan => 1);
674                     ELSE
675                        htp.tableData(cvalue => '<INPUT TYPE="TEXT" NAME = ' || ak_query_pkg.g_items_table(i).attribute_code || ' SIZE=' || ak_query_pkg.g_items_table(i).display_value_length || ' VALUE = "'|| v_value
676 ||'" onChange=''if(!checkNumber(this)) { this.focus(); this.value="";} else {roundDecimals(this, 5); set_amount(' || to_char(l_pos) || ',this.value,' || v_extended_price || ',1);}''>', crowspan => 1);
677                     END IF;
678 
679                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_AMOUNT' THEN
680                     IF v_display_first = ak_query_pkg.g_items_table(i).attribute_code THEN
681                        htp.tableData(cvalue => '<INPUT TYPE="TEXT" NAME = ' || ak_query_pkg.g_items_table(i).attribute_code || ' SIZE=' || ak_query_pkg.g_items_table(i).display_value_length || ' VALUE = "'|| v_value
682 ||'" onChange='' if (!checkNumber(this)) { this.focus(); this.value="";} else {roundDecimals(this, 2); set_percent(' || to_char(l_pos) || ',this.value,' || v_extended_price || ',0);}''>', crowspan => 1);
686                     END IF;
683                     ELSE
684                        htp.tableData(cvalue => '<INPUT TYPE="TEXT" NAME = ' || ak_query_pkg.g_items_table(i).attribute_code || ' SIZE=' || ak_query_pkg.g_items_table(i).display_value_length || ' VALUE = "'||
685 v_value ||'" onChange='' if (!checkNumber(this)) { this.focus(); this.value="";} else {roundDecimals(this, 2); set_percent(' || to_char(l_pos) || ',this.value,' || v_extended_price || ',1);}''>', crowspan => 1);
687                ELSE
688                     htp.tableData(cvalue => '<INPUT TYPE="TEXT" NAME = ' || ak_query_pkg.g_items_table(i).attribute_code || ' SIZE=' || ak_query_pkg.g_items_table(i).display_value_length || ' VALUE = "'|| v_value
689 ||'">', crowspan => 1);
690                END IF;
691 
692                l_pos := l_pos + 1;
693             ELSE
694                -- Print for display only; pass that as a hidden value
695 
696                IF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG1'  THEN
697                 v_value := v_charge_account_seg1;
698                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG2'  THEN
699                 v_value := v_charge_account_seg2;
700                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG3'  THEN
701                 v_value := v_charge_account_seg3;
702                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG4'  THEN
703                 v_value := v_charge_account_seg4;
704                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG5'  THEN
705                 v_value := v_charge_account_seg5;
706                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG6'  THEN
707                 v_value := v_charge_account_seg6;
708                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG7'  THEN
709                 v_value := v_charge_account_seg7;
710                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG8'  THEN
711                 v_value := v_charge_account_seg8;
712                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG9'  THEN
713                 v_value := v_charge_account_seg9;
714                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG10'  THEN
715                 v_value := v_charge_account_seg10;
716                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG11'  THEN
717                 v_value := v_charge_account_seg11;
718                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG12'  THEN
719                 v_value := v_charge_account_seg12;
720                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG13'  THEN
721                 v_value := v_charge_account_seg13;
722                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG14'  THEN
723                 v_value := v_charge_account_seg14;
724                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG15'  THEN
725                 v_value := v_charge_account_seg15;
729                 v_value := v_charge_account_seg17;
726                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG16'  THEN
727                 v_value := v_charge_account_seg16;
728                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG17'  THEN
730                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG18'  THEN
731                 v_value := v_charge_account_seg18;
732                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG19'  THEN
733                 v_value := v_charge_account_seg19;
734                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG20'  THEN
735                 v_value := v_charge_account_seg20;
736                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG21'  THEN
737                 v_value := v_charge_account_seg21;
738                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG22'  THEN
739                 v_value := v_charge_account_seg22;
740                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG23'  THEN
741                 v_value := v_charge_account_seg23;
742                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG24'  THEN
743                 v_value := v_charge_account_seg24;
744                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG25'  THEN
745                 v_value := v_charge_account_seg25;
746                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG26'  THEN
747                 v_value := v_charge_account_seg26;
748                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG27'  THEN
749                 v_value := v_charge_account_seg27;
750                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG28'  THEN
751                 v_value := v_charge_account_seg28;
752                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG29'  THEN
753                 v_value := v_charge_account_seg29;
754                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG30'  THEN
755                 v_value := v_charge_account_seg30;
756                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCOUNT_NUM'  THEN
757                 v_value := v_charge_account_num;
758                END IF; /* ak.. attribute_code = 'ICX_...' */
759 
760                htp.formHidden(cname => ak_query_pkg.g_items_table(i).attribute_code , cvalue => v_value);
761                l_pos := l_pos + 1;
762 
763                IF v_value IS NULL THEN
764                  htp.tableData(cvalue => ' ', crowspan => 1);
768 
765                ELSE
766                 htp.tableData(cvalue => v_value, crowspan => 1);
767                END IF; /* IF v_value */
769             END IF; /* update_flag = 'Y' */
770 
771         END IF; /* node_display_flag = 'Y' */
772 
773       END LOOP; /* FOR i in items_table */
774 
775       htp.tableRowClose;
776 
777     END LOOP; /* FOR 1 .. v_display_lines */
778 
779    ELSE
780     /* get the data from AK */
781     ak_query_pkg.exec_query(P_PARENT_REGION_APPL_ID => 601,
782                             P_PARENT_REGION_CODE    => v_distribution_lines_region,
783                             P_RESPONSIBILITY_ID     => v_responsibility_id,
784                             P_USER_ID               => v_web_user_id,
785                             P_WHERE_CLAUSE          => v_where_clause,
786                             P_RETURN_PARENTS        => 'T',
787                             P_RETURN_CHILDREN       => 'F');
788 
789     -- to debug, uncomment the following dump the results table after
790     -- the ak query
791     -- icx_on_utilities2.printPLSQLtables;
792 
793     print_lines_header;
794 
795     v_rows_returned := ak_query_pkg.g_results_table.count;
796 
797     IF (v_rows_returned >= v_fixed_line_count) THEN
798         v_display_lines := v_rows_returned + v_fixed_line_count;
799     ELSE
800         v_display_lines := v_fixed_line_count;
801     END IF; /* if ak_query_pkg.g_result_table.count ... */
802 
803     -- determine if amount is ahead of quantity or quantity is ahead of amount
804     v_display_first := NULL;
805 
806     FOR j IN 0..ak_query_pkg.g_items_table.LAST LOOP
807         IF ak_query_pkg.g_items_table(j).attribute_code = 'ICX_PERCENTAGE' AND
808            v_display_first is NULL THEN
809            v_display_first := 'ICX_PERCENTAGE';
810            EXIT;
811         ELSIF ak_query_pkg.g_items_table(j).attribute_code = 'ICX_AMOUNT' AND
812            v_display_first is NULL THEN
813            v_display_first := 'ICX_AMOUNT';
814            EXIT;
815         END IF;
819      FOR r IN 0..ak_query_pkg.g_results_table.LAST LOOP
816     END LOOP;
817 
818     IF v_rows_returned > 0 THEN
820 
821       icx_util.transfer_Row_To_Column(ak_query_pkg.g_results_table(r),l_values);
822 
823       htp.p('<TR BGColor="#'||v_multirow_color||'">');
824 
825       FOR i IN 0..ak_query_pkg.g_items_table.LAST LOOP
826 
827         IF ak_query_pkg.g_items_table(i).node_display_flag = 'Y'
828         AND ak_query_pkg.g_items_table(i).secured_column = 'F'
829         AND ak_query_pkg.g_items_table(i).item_style = 'HIDDEN' THEN
830 
831            htp.formHidden(cname => ak_query_pkg.g_items_table(i).attribute_code , cvalue => replace(l_values(ak_query_pkg.g_items_table(i).value_id),'"','"'));
832            l_pos := l_pos + 1;
833         END IF;
834 
835 	IF ak_query_pkg.g_items_table(i).node_display_flag = 'Y'
836         AND ak_query_pkg.g_items_table(i).secured_column = 'F'
837         AND ak_query_pkg.g_items_table(i).item_style <> 'HIDDEN' THEN
838 
839             IF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_PERCENTAGE'
840               THEN
841               v_percentage_value := l_values(ak_query_pkg.g_items_table(i).value_id);
842             END IF; /* ICX_PERCENTAGE */
843 
844             IF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_AMOUNT'
845             THEN
846               /* aahmad 1/28/98: Changed from ROUND to TO_CHAR.  Bug no. 585194 */
847               /* v_value :=  ROUND(v_extended_price * (v_percentage_value/100), 2); */
848               v_value := TO_CHAR(v_extended_price * (v_percentage_value/100), 'FM99999999999999999999999999999999999990D00');
849             ELSE
850               v_value := l_values(ak_query_pkg.g_items_table(i).value_id);
851             END IF;
852 
853             IF ak_query_pkg.g_items_table(i).update_flag = 'Y' THEN
854 		 if ak_query_pkg.g_items_table(i).attribute_code = 'ICX_PERCENTAGE'  then
855                     if v_display_first = ak_query_pkg.g_items_table(i).attribute_code then
856                        htp.tableData(cvalue => '<INPUT TYPE="TEXT" NAME = ' || ak_query_pkg.g_items_table(i).attribute_code || ' SIZE=' || ak_query_pkg.g_items_table(i).display_value_length || ' VALUE = "'|| v_value
857 ||'" onChange=''if(!checkNumber(this)) { this.focus();this.value="";} else {roundDecimals(this, 5); set_amount(' || to_char(l_pos) || ',this.value,' || v_extended_price || ',0);}''>', crowspan => 1);
858                     else
859                        htp.tableData(cvalue => '<INPUT TYPE="TEXT" NAME = ' || ak_query_pkg.g_items_table(i).attribute_code || ' SIZE=' || ak_query_pkg.g_items_table(i).display_value_length || ' VALUE = "'||
860 v_value ||'" onChange=''if(!checkNumber(this)) { this.focus();this.value="";} else {roundDecimals(this, 5); set_amount(' || to_char(l_pos) || ',this.value,' || v_extended_price || ',1);}''>', crowspan => 1);
861                     end if;
862                elsif ak_query_pkg.g_items_table(i).attribute_code = 'ICX_AMOUNT' then
863                     if v_display_first = ak_query_pkg.g_items_table(i).attribute_code then
864                        htp.tableData(cvalue => '<INPUT TYPE="TEXT" NAME = ' || ak_query_pkg.g_items_table(i).attribute_code || ' SIZE=' || ak_query_pkg.g_items_table(i).display_value_length || ' VALUE = "'|| v_value
865 ||'" onChange='' if (!checkNumber(this)) { this.focus(); this.value="";} else {roundDecimals(this, 2); set_percent(' || to_char(l_pos) || ',this.value,' || v_extended_price || ',0);}''>', crowspan => 1);
866                     else
867                        htp.tableData(cvalue => '<INPUT TYPE="TEXT" NAME = ' || ak_query_pkg.g_items_table(i).attribute_code || ' SIZE=' || ak_query_pkg.g_items_table(i).display_value_length || ' VALUE = "'|| v_value
871                   htp.tableData(cvalue => '<INPUT TYPE="TEXT" NAME = ' || ak_query_pkg.g_items_table(i).attribute_code || ' SIZE=' || ak_query_pkg.g_items_table(i).display_value_length ||
868 ||'" onChange='' if (!checkNumber(this)) { this.focus(); this.value="";} else {roundDecimals(this, 2); set_percent(' || to_char(l_pos) || ',this.value,' || v_extended_price || ',1);}''>', crowspan => 1);
869                     end if;
870                else
872 ' VALUE = "'|| replace(v_value,'"','"') ||'">', crowspan => 1);
873                end if;
874 
875                l_pos := l_pos + 1;
876 
877             ELSE
878                htp.formHidden(cname => ak_query_pkg.g_items_table(i).attribute_code , cvalue => replace(l_values(ak_query_pkg.g_items_table(i).value_id),'"','"'));
879                l_pos := l_pos + 1;
880                -- Print as display only pass that data as hidden
881                htp.tableData(cvalue => replace(l_values(ak_query_pkg.g_items_table(i).value_id),'"','"'), crowspan => 1);
882 
883                -- capture the value to be used as hidden fields later for
884                -- blank lines
885                IF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG1'  THEN
886                v_charge_account_seg1 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
887                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG2'  THEN
888                v_charge_account_seg2 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
889                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG3'  THEN
890                v_charge_account_seg3 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
891                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG4'  THEN
892                v_charge_account_seg4 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
893                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG5'  THEN
894                v_charge_account_seg5 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
895                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG6'  THEN
896                v_charge_account_seg6 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
897                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG7'  THEN
898                v_charge_account_seg7 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
899                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG8'  THEN
900                v_charge_account_seg8 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
901                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG9'  THEN
902                v_charge_account_seg9 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
903                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG10'  THEN
904                v_charge_account_seg10 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
905                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG11'  THEN
906                v_charge_account_seg11 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
907                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG12'  THEN
908                v_charge_account_seg12 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
909                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG13'  THEN
910                v_charge_account_seg13 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
911                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG14'  THEN
912                v_charge_account_seg14 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
913                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG15'  THEN
914                v_charge_account_seg16 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
918                v_charge_account_seg17 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
915                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG16'  THEN
916                v_charge_account_seg16 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
917                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG17'  THEN
919                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG18'  THEN
920                v_charge_account_seg18 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
921                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG19'  THEN
922                v_charge_account_seg19 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
923                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG20'  THEN
924                v_charge_account_seg20 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
925                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG21'  THEN
926                v_charge_account_seg21 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
927                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG22'  THEN
928                v_charge_account_seg22 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
929                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG23'  THEN
930                v_charge_account_seg23 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
931                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG24'  THEN
932                v_charge_account_seg24 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
933                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG25'  THEN
934                v_charge_account_seg25 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
935                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG26'  THEN
936                v_charge_account_seg26 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
937                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG27'  THEN
938                v_charge_account_seg27 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
939                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG28'  THEN
940                v_charge_account_seg28 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
941                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG29'  THEN
942                v_charge_account_seg29 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
943                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG30'  THEN
944                v_charge_account_seg30 :=  l_values(ak_query_pkg.g_items_table(i).value_id);
945 
946                END IF; /* ak.. attribute_code = 'ICX_...' */
947 
948             END IF; /* update_flag = 'Y' */
949 
950         END IF; /* node_dispaly_flag = 'Y' */
951 
955 
952       END LOOP; /* FOR i in items_table */
953 
954       htp.tablerowClose;
956      END LOOP; /* FOR r in ... */
957 
958     END IF; /* IF v_rows_returned > 1 */
959 
960     /* Show  few more lines (v_fixed_line_count) as blank lines for entry */
961     FOR r IN v_rows_returned + 1 .. v_display_lines LOOP
962 
963       htp.p('<TR BGColor="#'||v_multirow_color||'">');
964 
965       FOR i IN 0..ak_query_pkg.g_items_table.LAST LOOP
966 
967 	IF ak_query_pkg.g_items_table(i).node_display_flag = 'Y'
968         AND ak_query_pkg.g_items_table(i).secured_column = 'F'
969         AND ak_query_pkg.g_items_table(i).item_style <> 'HIDDEN' THEN
970 
971             v_value := NULL;
972 
973             IF ak_query_pkg.g_items_table(i).update_flag = 'Y' THEN
974 		 if ak_query_pkg.g_items_table(i).attribute_code = 'ICX_PERCENTAGE'  then
975 
976                     if v_display_first = ak_query_pkg.g_items_table(i).attribute_code then
977 
978 
979                        htp.tableData(cvalue => '<INPUT TYPE="TEXT" NAME = ' || ak_query_pkg.g_items_table(i).attribute_code || ' SIZE=' || ak_query_pkg.g_items_table(i).display_value_length || ' VALUE = "'||
980 v_value ||'" onChange=''if(!checkNumber(this)) { this.focus();this.value="";} else {roundDecimals(this, 5); set_amount(' || to_char(l_pos) || ',this.value,' || v_extended_price || ',0);}''>', crowspan => 1);
981 
982                     else
983 
984                        htp.tableData(cvalue => '<INPUT TYPE="TEXT" NAME = ' || ak_query_pkg.g_items_table(i).attribute_code || ' SIZE=' || ak_query_pkg.g_items_table(i).display_value_length || ' VALUE = "'||
985 v_value ||'" onChange=''if(!checkNumber(this)) { this.focus();this.value="";} else {roundDecimals(this, 5); set_amount(' || to_char(l_pos) || ',this.value,' || v_extended_price || ',1);}''>', crowspan => 1);
986 
987 
988                     end if;
989 
990                elsif ak_query_pkg.g_items_table(i).attribute_code = 'ICX_AMOUNT' then
991 
995 v_value ||'" onChange='' if (!checkNumber(this)) { this.focus(); this.value="";} else {roundDecimals(this, 2); set_percent(' || to_char(l_pos) || ',this.value,' || v_extended_price || ',0);}''>', crowspan => 1);
992                     if v_display_first = ak_query_pkg.g_items_table(i).attribute_code then
993 
994                        htp.tableData(cvalue => '<INPUT TYPE="TEXT" NAME = ' || ak_query_pkg.g_items_table(i).attribute_code || ' SIZE=' || ak_query_pkg.g_items_table(i).display_value_length || ' VALUE = "'||
996 
997 
998                     else
999 
1000 
1001 
1002                        htp.tableData(cvalue => '<INPUT TYPE="TEXT" NAME = ' || ak_query_pkg.g_items_table(i).attribute_code || ' SIZE=' || ak_query_pkg.g_items_table(i).display_value_length || ' VALUE = "'||
1003 v_value ||'" onChange='' if (!checkNumber(this)) { this.focus(); this.value="";} else {roundDecimals(this, 2); set_percent(' || to_char(l_pos) || ',this.value,' || v_extended_price || ',1);}''>', crowspan => 1);
1004 
1005 
1006                     end if;
1007 
1008                else
1009                -- htp.tableData(cvalue => '<INPUT TYPE="TEXT" NAME = ' || ak_query_pkg.g_items_table(i).attribute_code || ' SIZE=' || ak_query_pkg.g_items_table(i).display_value_length ||
1010 -- ' MAXLENGTH=' || ak_query_pkg.g_items_table(i).attribute_value_length || ' VALUE = "">', crowspan => 1);
1011                -- htp.tableData(cvalue => '<INPUT TYPE="TEXT" NAME = ' || ak_query_pkg.g_items_table(i).attribute_code ||
1012 -- ' SIZE=' || ak_query_pkg.g_items_table(i).display_value_length || ' VALUE = "'|| v_value ||'">', crowspan => 1);
1013                  htp.tableData(cvalue => '<INPUT TYPE="TEXT" NAME = ' || ak_query_pkg.g_items_table(i).attribute_code
1014 || ' SIZE=' || ak_query_pkg.g_items_table(i).display_value_length ||'>', crowspan => 1);
1015                end if;
1016 
1017                l_pos := l_pos + 1;
1018             ELSE
1019                -- Print for display only; pass that as a hidden value
1020 
1021                IF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG1'  THEN
1022                 v_value := v_charge_account_seg1;
1023                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG2'  THEN
1024                 v_value := v_charge_account_seg2;
1025                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG3'  THEN
1026                 v_value := v_charge_account_seg3;
1027                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG4'  THEN
1028                 v_value := v_charge_account_seg4;
1029                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG5'  THEN
1030                 v_value := v_charge_account_seg5;
1031                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG6'  THEN
1032                 v_value := v_charge_account_seg6;
1033                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG7'  THEN
1034                 v_value := v_charge_account_seg7;
1035                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG8'  THEN
1036                 v_value := v_charge_account_seg8;
1037                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG9'  THEN
1038                 v_value := v_charge_account_seg9;
1039                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG10'  THEN
1040                 v_value := v_charge_account_seg10;
1044                 v_value := v_charge_account_seg12;
1041                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG11'  THEN
1042                 v_value := v_charge_account_seg11;
1043                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG12'  THEN
1045                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG13'  THEN
1046                 v_value := v_charge_account_seg13;
1047                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG14'  THEN
1048                 v_value := v_charge_account_seg14;
1049                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG15'  THEN
1050                 v_value := v_charge_account_seg15;
1051                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG16'  THEN
1052                 v_value := v_charge_account_seg16;
1053                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG17'  THEN
1054                 v_value := v_charge_account_seg17;
1055                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG18'  THEN
1056                 v_value := v_charge_account_seg18;
1057                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG19'  THEN
1058                 v_value := v_charge_account_seg19;
1059                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG20'  THEN
1060                 v_value := v_charge_account_seg20;
1061                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG21'  THEN
1062                 v_value := v_charge_account_seg21;
1063                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG22'  THEN
1064                 v_value := v_charge_account_seg22;
1065                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG23'  THEN
1066                 v_value := v_charge_account_seg23;
1067                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG24'  THEN
1068                 v_value := v_charge_account_seg24;
1069                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG25'  THEN
1070                 v_value := v_charge_account_seg25;
1071                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG26'  THEN
1072                 v_value := v_charge_account_seg26;
1073                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG27'  THEN
1074                 v_value := v_charge_account_seg27;
1075                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG28'  THEN
1076                 v_value := v_charge_account_seg28;
1077                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG29'  THEN
1078                 v_value := v_charge_account_seg29;
1079                ELSIF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_CHARGE_ACCT_SEG30'  THEN
1080                 v_value := v_charge_account_seg30;
1081                END IF; /* ak.. attribute_code = 'ICX_...' */
1082 
1086                IF v_value IS NULL THEN
1083                htp.formHidden(cname => ak_query_pkg.g_items_table(i).attribute_code , cvalue => v_value);
1084                l_pos := l_pos + 1;
1085 
1087                  htp.tableData(cvalue => ' ', crowspan => 1);
1088                ELSE
1089                 htp.tableData(cvalue => v_value, crowspan => 1);
1090                END IF; /* IF v_value */
1091 
1092             END IF; /* update_flag = 'Y' */
1093 
1094         END IF; /* node_display_flag = 'Y' */
1095 
1096       END LOOP; /* FOR i in items_table */
1097 
1098       htp.tableRowClose;
1099 
1100     END LOOP; /* FOR v_rows_returned + 1 */
1101 
1102    END IF; /*  IF p_show_more_lines */
1103 
1104 
1108   l_pos := l_pos + 1;
1105   htp.tableClose;
1106 
1107   htp.formHidden('p_show_more_lines', v_display_lines);
1109 
1110   htp.br;
1111   htp.br;
1112 
1113   htp.formClose;
1114   htp.bodyClose;
1115   htp.htmlClose;
1116 
1117  END IF;  /* validate session */
1118 
1119 EXCEPTION
1120   WHEN OTHERS THEN
1121     -- htp.p('Error in display acct distributions ' || substr(SQLERRM, 1, 512));
1122     icx_util.add_error(substr(SQLERRM, 12, 512));
1123     icx_util.error_page_print;
1124 
1125 END display_acct_distributions;
1126 
1127 
1128 ------------------------------------------------------
1129 PROCEDURE display_account_header (v_extended_price OUT NUMBER) IS
1130 
1131 y_table             icx_util.char240_table;
1132 
1133 v_shopper_id        NUMBER := NULL;
1134 v_shopper_name      VARCHAR2(250) := NULL;
1138 v_org_code          VARCHAR2(30) := NULL;
1135 v_location_id       NUMBER := NULL;
1136 v_location_code     VARCHAR2(240) := NULL;
1137 v_org_id            NUMBER := NULL;
1139 v_currency          VARCHAR2(30) := NULL;
1140 v_precision         NUMBER := NULL;
1141 v_money_fmt_mask    VARCHAR2(32) := NULL;
1142 v_ext_amount        NUMBER := NULL;
1143 
1144 BEGIN
1145 
1146  IF icx_sec.validateSession('ICX_REQS') THEN
1147 
1148   v_shopper_id := icx_sec.getID(icx_sec.PV_INT_CONTACT_ID);
1149   ICX_REQ_NAVIGATION.shopper_info(v_shopper_id, v_shopper_name, v_location_id, v_location_code, v_org_id, v_org_code);
1150   ICX_REQ_NAVIGATION.get_currency(v_org_id, v_currency, v_precision, v_money_fmt_mask);
1151   v_money_fmt_mask := fnd_currency.safe_get_format_mask(v_currency, 30);
1152 
1153   htp.tableOpen('BORDER=0');
1154 
1155   icx_util.transfer_Row_To_Column( ak_query_pkg.g_results_table(ak_query_pkg.g_results_table.FIRST),y_table);
1156 
1157   FOR i IN ak_query_pkg.g_items_table.FIRST  ..  ak_query_pkg.g_items_table.LAST LOOP
1158 
1159   IF  ak_query_pkg.g_items_table(i).node_display_flag = 'Y'
1160       AND ak_query_pkg.g_items_table(i).secured_column = 'F'
1161       AND ak_query_pkg.g_items_table(i).item_style <> 'HIDDEN' THEN
1162 
1163     htp.tableRowOpen;
1164 
1165     htp.tableData(cvalue => ak_query_pkg.g_items_table(i).attribute_label_long, calign => 'RIGHT', cattributes=>'VALIGN=CENTER');
1166 
1167     /* Leave a blank space between the prompt and the value */
1168     htp.tableData(cvalue => ' ');
1169 
1170     htp.p('<TD border=1 bgcolor=#FFFFFF>');
1171     htp.p('<B>');
1172     IF ak_query_pkg.g_items_table(i).italic = 'Y' THEN
1173        htp.p('<I>');
1174     END IF;
1175 
1176     /* Format ext. price before displaying */
1177     IF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_EXT_PRICE' THEN
1178       v_ext_amount := y_table(ak_query_pkg.g_items_table(i).value_id);
1179       htp.p(TO_CHAR(v_ext_amount, v_money_fmt_mask));
1180     ELSE
1181       htp.p(y_table(ak_query_pkg.g_items_table(i).value_id));
1182     END IF; /* ICX_EXT_PRICE */
1183 
1184        -- htp.tableData(cvalue => icx_on_utilities.formatText(y_table(ak_query_pkg.g_items_table(i).value_id),ak_query_pkg.g_items_table(i).bold,ak_query_pkg.g_items_table(i).italic),
1185 -- calign => ak_query_pkg.g_items_table(i).horizontal_alignment, cattributes => 'VALIGN="'||ak_query_pkg.g_items_table(i).vertical_alignment||'"');
1186 
1187     IF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_EXT_PRICE'
1188         THEN
1189        v_extended_price := y_table(ak_query_pkg.g_items_table(i).value_id);
1190     END IF; /* ICX_EXT_PRICE */
1191 
1195     htp.p('</B>');
1192     IF ak_query_pkg.g_items_table(i).italic = 'Y' THEN
1193        htp.p('</I>');
1194     END IF;
1196     htp.p('</TD>');
1197 
1198 
1199     htp.tableRowClose;
1200 
1201   END IF; /* aK_query... display_flag = 'Y' */
1202 
1203   END LOOP; /* for i in ... */
1204 
1205   htp.tableClose;
1206   htp.br;
1207 
1208  END IF;  /* validate session */
1209 
1210 EXCEPTION
1211   WHEN OTHERS THEN
1212     -- htp.p('Error in display acct header ' || substr(SQLERRM, 1, 512));
1213     icx_util.add_error(substr(SQLERRM, 12, 512));
1214     icx_util.error_page_print;
1215 
1216 END display_account_header;
1217 
1218 
1219 ------------------------------------------------------
1220 PROCEDURE print_lines_header IS
1221 
1222 v_table_attribute VARCHAR2(50) := NULL;
1223 
1224 BEGIN
1225 
1226  IF icx_sec.validateSession('ICX_REQS') THEN
1227 
1228   htp.p('<TABLE BORDER=5 bgcolor=''#F8F8F8''>');
1229   htp.p('<TR bgcolor=''#D8D8D8''>');
1230 
1231   v_table_attribute := ' COLSPAN=1';
1232 
1233   FOR i IN ak_query_pkg.g_items_table.FIRST  ..  ak_query_pkg.g_items_table.LAST LOOP
1234    IF (ak_query_pkg.g_items_table(i).item_style <> 'HIDDEN' AND
1235        ak_query_pkg.g_items_table(i).node_display_flag = 'Y' AND
1236        ak_query_pkg.g_items_table(i).secured_column <> 'T')  THEN
1237 
1238      htp.p( '<TD' || v_table_attribute || ' ALIGN="CENTER" >' || ak_query_pkg.g_items_table(i).attribute_label_long  || '</TD>' );
1239 
1240     END IF; /* if ak_query_pkg ... <> HIDDEN */
1241 
1242   END LOOP; /* FOR in ak_query_pkg ... */
1243 
1244   -- Leave a thin blank line border between the header and the table rows
1245   htp.p('</TR><TR></TR><TR></TR><TR></TR>');
1246 
1247  END IF;  /* validate session */
1251     -- htp.p('Error in print lines header ' || substr(SQLERRM, 1, 512));
1248 
1249 EXCEPTION
1250   WHEN OTHERS THEN
1252     icx_util.add_error(substr(SQLERRM, 12, 512));
1253     icx_util.error_page_print;
1254 
1255 END print_lines_header;
1256 
1257 
1258 ------------------------------------------------------
1259 PROCEDURE print_action_buttons IS
1260 
1261 v_order_button_text VARCHAR2(50) := NULL;
1262 v_language_code VARCHAR2(30) := NULL;
1263 
1264 BEGIN
1265 
1266  IF icx_sec.validateSession('ICX_REQS') THEN
1267    v_language_code := icx_sec.getID(icx_sec.PV_LANGUAGE_CODE);
1268 
1269    htp.htmlOpen;
1270    htp.headOpen;
1271    htp.headClose;
1272 
1273    htp.bodyOpen('','BGCOLOR="#CCFFFF" onLoad="parent.parent.winOpen(''nav'',''my_order'');"');
1274 
1275    htp.tableOpen('border=0');
1276    htp.tableRowOpen;
1277 
1278            -- Show more lines button
1279            htp.p('<TD>');
1280            FND_MESSAGE.SET_NAME('ICX','ICX_SHOW_MORE_LINES');
1281            v_order_button_text := FND_MESSAGE.GET;
1282            icx_util.DynamicButton(P_ButtonText      => v_order_button_text,
1283                                   P_ImageFileName   => 'FNDBSBMT.gif',
1284                                   P_OnMouseOverText => v_order_button_text,
1285                                   P_HyperTextCall   => 'javascript:parent.frames[0].show_more_lines()',
1286                                   P_LanguageCode    => v_language_code,
1287                                   P_JavaScriptFlag  => FALSE);
1288            htp.p('</TD>');
1289 
1290            -- Apply to all lines
1291            htp.p('<TD>');
1292            FND_MESSAGE.SET_NAME('ICX','ICX_APPLY_TO_ALL_LINES');
1293            v_order_button_text := FND_MESSAGE.GET;
1294            icx_util.DynamicButton(P_ButtonText      => v_order_button_text,
1295                                   P_ImageFileName   => 'FNDBSBMT.gif',
1296                                   P_OnMouseOverText => v_order_button_text,
1297                                   -- P_HyperTextCall   => 'javascript:submit()',
1298                                   P_HyperTextCall   => 'javascript:parent.frames[0].apply_to_all()',
1299                                   P_LanguageCode    => v_language_code,
1300                                   P_JavaScriptFlag  => FALSE);
1301            htp.p('</TD>');
1302 
1303            -- Cancel button
1304            htp.p('<TD>');
1305            FND_MESSAGE.SET_NAME('ICX','ICX_CANCEL');
1306            v_order_button_text := FND_MESSAGE.GET;
1307            icx_util.DynamicButton(P_ButtonText      => v_order_button_text,
1308                                   P_ImageFileName   => 'FNDBCNCL.gif',
1309                                   P_OnMouseOverText => v_order_button_text,
1310                                   -- P_HyperTextCall   => 'javascript:cancel_account()',
1311                                   P_HyperTextCall   => 'javascript:parent.frames[0].cancel_account()',
1312                                   P_LanguageCode    => v_language_code,
1313                                   P_JavaScriptFlag  => FALSE);
1317            htp.p('<TD>');
1314            htp.p('</TD>');
1315 
1316            -- Apply button
1318            FND_MESSAGE.SET_NAME('ICX','ICX_APPLY_CHANGES');
1319            v_order_button_text := FND_MESSAGE.GET;
1320            icx_util.DynamicButton(P_ButtonText      => v_order_button_text,
1321                                   P_ImageFileName   => 'FNDBAPLY.gif',
1322                                   P_OnMouseOverText => v_order_button_text,
1323                                   P_HyperTextCall   => 'javascript:parent.frames[0].submit()',
1324                                   P_LanguageCode    => v_language_code,
1325                                   P_JavaScriptFlag  => FALSE);
1326            htp.p('</TD>');
1327 
1328    htp.tableRowClose;
1329    htp.tableClose;
1330 
1331    htp.bodyClose;
1332    htp.htmlClose;
1333 
1334  END IF; /* validate session */
1335 
1336 
1337 EXCEPTION
1338   WHEN OTHERS THEN
1339     -- htp.p('Error in print action buttons ' || substr(SQLERRM, 1, 512));
1340     icx_util.add_error(substr(SQLERRM, 12, 512));
1341     icx_util.error_page_print;
1342 
1343 END print_action_buttons;
1344 
1345 ------------------------------------------------------
1346 PROCEDURE submit_accounts(p_cart_id IN NUMBER,
1347                           p_cart_line_id IN NUMBER,
1348                           p_user_action IN VARCHAR2 DEFAULT NULL,
1349                           p_show_more_lines IN NUMBER DEFAULT NULL,
1350                           icx_charge_acct_seg1 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1351                           icx_charge_acct_seg2 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1352                           icx_charge_acct_seg3 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1353                           icx_charge_acct_seg4 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1354                           icx_charge_acct_seg5 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1355                           icx_charge_acct_seg6 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1356                           icx_charge_acct_seg7 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1357                           icx_charge_acct_seg8 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1358                           icx_charge_acct_seg9 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1359                           icx_charge_acct_seg10 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1360                           icx_charge_acct_seg11 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1361                           icx_charge_acct_seg12 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1362                           icx_charge_acct_seg13 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1366                           icx_charge_acct_seg17 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1363                           icx_charge_acct_seg14 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1364                           icx_charge_acct_seg15 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1365                           icx_charge_acct_seg16 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1367                           icx_charge_acct_seg18 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1368                           icx_charge_acct_seg19 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1369                           icx_charge_acct_seg20 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1370                           icx_charge_acct_seg21 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1371                           icx_charge_acct_seg22 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1372                           icx_charge_acct_seg23 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1373                           icx_charge_acct_seg24 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1374                           icx_charge_acct_seg25 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1375                           icx_charge_acct_seg26 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1376                           icx_charge_acct_seg27 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1377                           icx_charge_acct_seg28 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1378                           icx_charge_acct_seg29 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1379                           icx_charge_acct_seg30 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1380                           icx_charge_account_num IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1381                           icx_percentage IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1382                           icx_amount IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1383                           icx_distribution_num IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1384                           icx_distribution_id IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty
1385          ) IS
1386 
1387 v_cart_id          NUMBER := NULL;
1388 v_cart_line_id     NUMBER := NULL;
1389 v_error_count      NUMBER := NULL;
1390 v_error_text       VARCHAR2(200) := NULL;
1391 
1392  CURSOR  distribution_errors(l_cart_id NUMBER, l_cart_line_id NUMBER)  IS
1393       SELECT COUNT(distribution_num)
1394       FROM  icx_req_cart_errors
1395       WHERE cart_id = l_cart_id
1396       AND   cart_line_id = l_cart_line_id
1397       AND   distribution_num IS NOT NULL;
1398 
1399 BEGIN
1400 
1401     v_cart_id := icx_call.decrypt2(p_cart_id);
1402     v_cart_line_id := icx_call.decrypt2(p_cart_line_id);
1403 
1404     IF p_user_action = 'MORE_LINES' THEN
1405 
1406       -- Call display function with p_more_lines to display more lines
1407       display_acct_distributions (icx_call.decrypt2(p_cart_line_id) ,
1408                                   p_cart_id ,
1409                                   p_show_more_lines ,
1410                                   icx_charge_acct_seg1,
1411                                   icx_charge_acct_seg2,
1412                                   icx_charge_acct_seg3,
1413                                   icx_charge_acct_seg4,
1414                                   icx_charge_acct_seg5,
1415                                   icx_charge_acct_seg6,
1416                                   icx_charge_acct_seg7,
1417                                   icx_charge_acct_seg8,
1418                                   icx_charge_acct_seg9,
1419                                   icx_charge_acct_seg10,
1420                                   icx_charge_acct_seg11,
1421                                   icx_charge_acct_seg12,
1422                                   icx_charge_acct_seg13,
1423                                   icx_charge_acct_seg14,
1424                                   icx_charge_acct_seg15,
1425                                   icx_charge_acct_seg16,
1426                                   icx_charge_acct_seg17,
1430                                   icx_charge_acct_seg21,
1427                                   icx_charge_acct_seg18,
1428                                   icx_charge_acct_seg19,
1429                                   icx_charge_acct_seg20,
1431                                   icx_charge_acct_seg22,
1432                                   icx_charge_acct_seg23,
1433                                   icx_charge_acct_seg24,
1434                                   icx_charge_acct_seg25,
1435                                   icx_charge_acct_seg26,
1436                                   icx_charge_acct_seg27,
1437                                   icx_charge_acct_seg28,
1438                                   icx_charge_acct_seg29,
1439                                   icx_charge_acct_seg30,
1440                                   icx_charge_account_num,
1441                                   icx_percentage,
1442                                   icx_amount,
1443                                   icx_distribution_num,
1444                                   icx_distribution_id);
1445 
1446        RETURN;
1447     END IF;  /* if p_user_action = 'MORE_LINES' */
1448 
1449     IF p_user_action = 'APPLY' THEN
1450        apply_account_distributions(v_cart_id ,
1451                                   v_cart_line_id ,
1452                                   icx_charge_acct_seg1,
1453                                   icx_charge_acct_seg2,
1454                                   icx_charge_acct_seg3,
1455                                   icx_charge_acct_seg4,
1456                                   icx_charge_acct_seg5,
1457                                   icx_charge_acct_seg6,
1458                                   icx_charge_acct_seg7,
1459                                   icx_charge_acct_seg8,
1460                                   icx_charge_acct_seg9,
1461                                   icx_charge_acct_seg10,
1462                                   icx_charge_acct_seg11,
1463                                   icx_charge_acct_seg12,
1464                                   icx_charge_acct_seg13,
1465                                   icx_charge_acct_seg14,
1469                                   icx_charge_acct_seg18,
1466                                   icx_charge_acct_seg15,
1467                                   icx_charge_acct_seg16,
1468                                   icx_charge_acct_seg17,
1470                                   icx_charge_acct_seg19,
1471                                   icx_charge_acct_seg20,
1472                                   icx_charge_acct_seg21,
1473                                   icx_charge_acct_seg22,
1474                                   icx_charge_acct_seg23,
1475                                   icx_charge_acct_seg24,
1476                                   icx_charge_acct_seg25,
1477                                   icx_charge_acct_seg26,
1478                                   icx_charge_acct_seg27,
1479                                   icx_charge_acct_seg28,
1480                                   icx_charge_acct_seg29,
1481                                   icx_charge_acct_seg30,
1482                                   icx_charge_account_num,
1483                                   icx_percentage,
1484                                   icx_amount,
1485                                   icx_distribution_num,
1486                                   icx_distribution_id,
1487                                   v_error_text);
1488 
1489       -- Query the error table for this line where distribution_num is not null
1490       open distribution_errors (v_cart_id, v_cart_line_id);
1491       fetch distribution_errors into v_error_count;
1492       close distribution_errors;
1493 
1494       IF  ((NVL(v_error_count, 0)) > 0) OR (v_error_text IS NOT NULL) THEN
1495         -- call distributions display page to display errors
1496       display_acct_distributions (icx_call.decrypt2(p_cart_line_id) ,
1497                                   p_cart_id ,
1498                                   p_show_more_lines,
1499                                   icx_charge_acct_seg1,
1500                                   icx_charge_acct_seg2,
1501                                   icx_charge_acct_seg3,
1502                                   icx_charge_acct_seg4,
1503                                   icx_charge_acct_seg5,
1504                                   icx_charge_acct_seg6,
1505                                   icx_charge_acct_seg7,
1506                                   icx_charge_acct_seg8,
1507                                   icx_charge_acct_seg9,
1508                                   icx_charge_acct_seg10,
1509                                   icx_charge_acct_seg11,
1510                                   icx_charge_acct_seg12,
1511                                   icx_charge_acct_seg13,
1512                                   icx_charge_acct_seg14,
1513                                   icx_charge_acct_seg15,
1514                                   icx_charge_acct_seg16,
1515                                   icx_charge_acct_seg17,
1516                                   icx_charge_acct_seg18,
1517                                   icx_charge_acct_seg19,
1518                                   icx_charge_acct_seg20,
1519                                   icx_charge_acct_seg21,
1520                                   icx_charge_acct_seg22,
1524                                   icx_charge_acct_seg26,
1521                                   icx_charge_acct_seg23,
1522                                   icx_charge_acct_seg24,
1523                                   icx_charge_acct_seg25,
1525                                   icx_charge_acct_seg27,
1526                                   icx_charge_acct_seg28,
1527                                   icx_charge_acct_seg29,
1528                                   icx_charge_acct_seg30,
1529                                   icx_charge_account_num,
1530                                   icx_percentage,
1531                                   icx_amount,
1532                                   icx_distribution_num,
1533                                   icx_distribution_id,
1534                                   v_error_text);
1535 
1536       ELSE
1537         -- return to my_order tab
1538         js.scriptOpen;
1539         htp.p('parent.parent.account_dist="";');
1540         htp.p('parent.parent.cartLineId=' || v_cart_line_id || ';');
1541         htp.p('top.switchFrames("my_order");');
1542         js.scriptClose;
1543         RETURN;
1544 
1545       END IF; /* v_error_count */
1546 
1547     END IF; /* p_user_action = 'APPLY' */
1548 
1549     IF p_user_action = 'APPLY_TO_ALL' THEN
1550 
1551        /* First apply the existing screen data. This is need to be done as
1552           the user may not have pressed the apply button, before calling
1553           apply to all lines. This is an implicit apply followed by an apply to
1554           all lines.
1555         */
1556        apply_account_distributions(v_cart_id ,
1557                                   v_cart_line_id ,
1558                                   icx_charge_acct_seg1,
1559                                   icx_charge_acct_seg2,
1560                                   icx_charge_acct_seg3,
1561                                   icx_charge_acct_seg4,
1562                                   icx_charge_acct_seg5,
1563                                   icx_charge_acct_seg6,
1564                                   icx_charge_acct_seg7,
1565                                   icx_charge_acct_seg8,
1566                                   icx_charge_acct_seg9,
1567                                   icx_charge_acct_seg10,
1568                                   icx_charge_acct_seg11,
1569                                   icx_charge_acct_seg12,
1570                                   icx_charge_acct_seg13,
1571                                   icx_charge_acct_seg14,
1572                                   icx_charge_acct_seg15,
1573                                   icx_charge_acct_seg16,
1574                                   icx_charge_acct_seg17,
1575                                   icx_charge_acct_seg18,
1576                                   icx_charge_acct_seg19,
1577                                   icx_charge_acct_seg20,
1581                                   icx_charge_acct_seg24,
1578                                   icx_charge_acct_seg21,
1579                                   icx_charge_acct_seg22,
1580                                   icx_charge_acct_seg23,
1582                                   icx_charge_acct_seg25,
1583                                   icx_charge_acct_seg26,
1584                                   icx_charge_acct_seg27,
1585                                   icx_charge_acct_seg28,
1586                                   icx_charge_acct_seg29,
1587                                   icx_charge_acct_seg30,
1588                                   icx_charge_account_num,
1589                                   icx_percentage,
1590                                   icx_amount,
1591                                   icx_distribution_num,
1592                                   icx_distribution_id,
1593                                   v_error_text);
1594 
1595        -- Check for errors after apply. This is to prevent bad data
1596        -- getting into distibutions. Display the error message back with the
1597        -- data entered by the user.
1598 
1599        -- Query the error table for this line where distribution_num is not null
1600        open distribution_errors (v_cart_id, v_cart_line_id);
1601        fetch distribution_errors into v_error_count;
1602        close distribution_errors;
1603 
1604        IF  ((NVL(v_error_count, 0)) > 0) OR (v_error_text IS NOT NULL) THEN
1605          -- call distributions display page to display errors
1606        display_acct_distributions (icx_call.decrypt2(p_cart_line_id) ,
1607                                   p_cart_id ,
1608                                   p_show_more_lines,
1609                                   icx_charge_acct_seg1,
1610                                   icx_charge_acct_seg2,
1611                                   icx_charge_acct_seg3,
1612                                   icx_charge_acct_seg4,
1613                                   icx_charge_acct_seg5,
1614                                   icx_charge_acct_seg6,
1615                                   icx_charge_acct_seg7,
1616                                   icx_charge_acct_seg8,
1617                                   icx_charge_acct_seg9,
1618                                   icx_charge_acct_seg10,
1619                                   icx_charge_acct_seg11,
1620                                   icx_charge_acct_seg12,
1621                                   icx_charge_acct_seg13,
1622                                   icx_charge_acct_seg14,
1623                                   icx_charge_acct_seg15,
1627                                   icx_charge_acct_seg19,
1624                                   icx_charge_acct_seg16,
1625                                   icx_charge_acct_seg17,
1626                                   icx_charge_acct_seg18,
1628                                   icx_charge_acct_seg20,
1629                                   icx_charge_acct_seg21,
1630                                   icx_charge_acct_seg22,
1631                                   icx_charge_acct_seg23,
1632                                   icx_charge_acct_seg24,
1633                                   icx_charge_acct_seg25,
1634                                   icx_charge_acct_seg26,
1635                                   icx_charge_acct_seg27,
1636                                   icx_charge_acct_seg28,
1637                                   icx_charge_acct_seg29,
1638                                   icx_charge_acct_seg30,
1639                                   icx_charge_account_num,
1640                                   icx_percentage,
1641                                   icx_amount,
1642                                   icx_distribution_num,
1643                                   icx_distribution_id,
1644                                   v_error_text);
1645        ELSE
1646 
1647         apply_to_all(v_cart_id, v_cart_line_id);
1648 
1649         -- return to my_order tab
1650         js.scriptOpen;
1651         htp.p('parent.parent.account_dist="";');
1652         htp.p('parent.parent.cartLineId=' || v_cart_line_id || ';');
1653         htp.p('top.switchFrames("my_order");');
1654         js.scriptClose;
1655         RETURN;
1656        END IF;  /* IF v_errror_count...  */
1657 
1658     END IF; /* p_user_action = 'APPLY_TO_ALL' */
1659 
1660 EXCEPTION
1661   WHEN OTHERS THEN
1662     -- htp.p('Error in submit_accounts ' || substr(SQLERRM, 1, 512));
1663     icx_util.add_error(substr(SQLERRM, 12, 512));
1664     icx_util.error_page_print;
1665 
1666 END submit_accounts;
1667 
1668 
1669 ------------------------------------------------------
1670 PROCEDURE apply_account_distributions(v_cart_id IN NUMBER,
1671                           v_cart_line_id IN NUMBER,
1672                           icx_charge_acct_seg1 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1673                           icx_charge_acct_seg2 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1674                           icx_charge_acct_seg3 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1675                           icx_charge_acct_seg4 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1676                           icx_charge_acct_seg5 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1677                           icx_charge_acct_seg6 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1678                           icx_charge_acct_seg7 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1679                           icx_charge_acct_seg8 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1680                           icx_charge_acct_seg9 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1681                           icx_charge_acct_seg10 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1685                           icx_charge_acct_seg14 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1682                           icx_charge_acct_seg11 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1683                           icx_charge_acct_seg12 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1684                           icx_charge_acct_seg13 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1686                           icx_charge_acct_seg15 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1687                           icx_charge_acct_seg16 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1688                           icx_charge_acct_seg17 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1689                           icx_charge_acct_seg18 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1690                           icx_charge_acct_seg19 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1691                           icx_charge_acct_seg20 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1692                           icx_charge_acct_seg21 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1693                           icx_charge_acct_seg22 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1694                           icx_charge_acct_seg23 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1695                           icx_charge_acct_seg24 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1696                           icx_charge_acct_seg25 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1697                           icx_charge_acct_seg26 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1698                           icx_charge_acct_seg27 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1699                           icx_charge_acct_seg28 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1700                           icx_charge_acct_seg29 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1701                           icx_charge_acct_seg30 IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1702                           icx_charge_account_num IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1703                           icx_percentage IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1704                           icx_amount IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1705                           icx_distribution_num IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1706                           icx_distribution_id IN ICX_OWA_PARMS.ARRAY DEFAULT ICX_OWA_PARMS.empty,
1707                           v_error_text OUT VARCHAR2
1708          ) IS
1709 
1710 v_total_rows_returned     NUMBER := 0;
1711 v_row_count               NUMBER := 0;
1712 v_concatenated_segment    VARCHAR2(2) := NULL;
1713 v_allocation_type         VARCHAR2(30) := NULL;
1714 
1715 v_ak_attributes_table     varchar2_table;
1716 v_segment_value           fnd_flex_ext.SegmentArray;
1717 v_num_segments            NUMBER := 0;
1718 v_percent_total           NUMBER := 0;
1719 
1720 v_org_id                  NUMBER := NULL;
1721 l                         NUMBER := NULL;
1722 
1723  cursor get_ak_attributes is
1724         select  ltrim(rtrim(a.ATTRIBUTE_CODE)) ATTRIBUTE_NAME
1725         from       ak_region_items a,
1726         ak_attributes b,
1727         ak_regions c,
1728         ak_object_attributes d
1729         where      a.NODE_DISPLAY_FLAG = 'Y'
1730         and        a.ATTRIBUTE_CODE = b.ATTRIBUTE_CODE
1731         and        a.ATTRIBUTE_APPLICATION_ID = b.ATTRIBUTE_APPLICATION_ID
1732         and        b.DATA_TYPE = 'VARCHAR2'
1733         and        c.REGION_APPLICATION_ID = 601
1734         and        a.REGION_CODE = c.REGION_CODE
1735         and        a.REGION_APPLICATION_ID = c.REGION_APPLICATION_ID
1736         and        c.DATABASE_OBJECT_NAME = d.DATABASE_OBJECT_NAME
1740         order by a.display_sequence;
1737         and        a.ATTRIBUTE_CODE = d.ATTRIBUTE_CODE
1738         and        a.region_code = 'ICX_CART_LINE_DISTRIBUTIONS_R'
1739         and        a.ATTRIBUTE_CODE LIKE 'ICX_CHARGE_ACCT_SEG%'
1741 
1742  cursor check_concatenated_segment is
1743         select  1
1744         from       ak_region_items a,
1745         ak_attributes b,
1746         ak_regions c,
1747         ak_object_attributes d
1748         where      a.NODE_DISPLAY_FLAG = 'Y'
1749         and        a.ATTRIBUTE_CODE = b.ATTRIBUTE_CODE
1750         and        a.ATTRIBUTE_APPLICATION_ID = b.ATTRIBUTE_APPLICATION_ID
1751         and        b.DATA_TYPE = 'VARCHAR2'
1752         and        c.REGION_APPLICATION_ID = 601
1753         and        a.REGION_CODE = c.REGION_CODE
1754         and        a.REGION_APPLICATION_ID = c.REGION_APPLICATION_ID
1755         and        c.DATABASE_OBJECT_NAME = d.DATABASE_OBJECT_NAME
1756         and        a.ATTRIBUTE_CODE = d.ATTRIBUTE_CODE
1757         and        a.region_code = 'ICX_CART_LINE_DISTRIBUTIONS_R'
1758         and        a.attribute_code = 'ICX_CHARGE_ACCOUNT_NUM';
1759 
1760 BEGIN
1761 
1762  IF icx_sec.validateSession('ICX_REQS') THEN
1763 
1764     v_org_id := icx_sec.getId(icx_sec.PV_ORG_ID);
1765 
1766     -- Set the allocation type. Right now only percentage is allowed.
1767     v_allocation_type := 'PERCENT';
1768 
1769     -- get the total number of rows returned from the browser
1770     v_total_rows_returned := icx_percentage.COUNT;
1771 
1772     -- If percentage does not add up to 100% return as error.
1773     FOR l in 1 .. v_total_rows_returned LOOP
1774       v_percent_total := v_percent_total + NVL(to_number(icx_percentage(l)), 0);
1775     END LOOP; /* FOR v_total_rows_returned */
1776 
1777     IF v_percent_total <> 100 THEN
1778        FND_MESSAGE.SET_NAME('ICX','ICX_NOT_100_PERCENT');
1779        v_error_text := FND_MESSAGE.GET;
1780        RETURN;
1781     END IF;  /* IF v_percenet_total */
1782 
1783      -- Delete the error messages for the distribution
1784      DELETE FROM icx_req_cart_errors
1785      WHERE cart_id = v_cart_id
1786      AND   cart_line_id = v_cart_line_id
1787      AND   distribution_num IS NOT NULL;
1788 
1789 
1790     /*
1791     Delete all the distributions in the table. This need to be done to
1792     take care of the deletion option. As we don't provide delete button option
1793     the user will either enter '0' (zero) or leave blank in the percentage
1794     column to indicate that, account entry is deleted.
1795     */
1796 
1797     DELETE FROM icx_cart_line_distributions
1798     WHERE cart_id = v_cart_id
1799     AND   cart_line_id = v_cart_line_id;
1800 
1801 
1802     -- Determine what is turned for display, the concatenated segments or
1803     -- invidual segments.
1804     OPEN check_concatenated_segment;
1805     FETCH check_concatenated_segment INTO v_row_count;
1806     CLOSE check_concatenated_segment;
1807 
1808     IF  v_row_count = 1 THEN
1809         v_concatenated_segment := 'Y';
1810     ELSE
1811         v_concatenated_segment := 'N';
1812     END IF;
1813 
1814     IF v_concatenated_segment = 'N' THEN
1815     -- Find the segments turned on and build a pl/sql table to hold
1816     -- the segment attribute code
1817     l := 1;
1818     FOR ak_col IN get_ak_attributes LOOP
1819       v_ak_attributes_table(l) := ak_col.attribute_name;
1820       l := l + 1;
1821     END LOOP;  /* FOR ak_col */
1822 
1823     -- Get the total number of segments
1824     v_num_segments := v_ak_attributes_table.COUNT;
1825 
1826     -- loop through every line returned to get the account segments
1827     FOR i in 1.. v_total_rows_returned LOOP
1828 
1829       -- Build the segment table for each row
1830       FOR j in 1 .. v_num_segments LOOP
1831 
1832           IF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG1' THEN
1833              v_segment_value(j) := icx_charge_acct_seg1(i);
1834           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG2' THEN
1835              v_segment_value(j) := icx_charge_acct_seg2(i);
1836           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG3' THEN
1837              v_segment_value(j) := icx_charge_acct_seg3(i);
1838           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG4' THEN
1839              v_segment_value(j) := icx_charge_acct_seg4(i);
1840           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG5' THEN
1841              v_segment_value(j) := icx_charge_acct_seg5(i);
1842           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG6' THEN
1843              v_segment_value(j) := icx_charge_acct_seg6(i);
1844           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG7' THEN
1845              v_segment_value(j) := icx_charge_acct_seg7(i);
1846           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG8' THEN
1847              v_segment_value(j) := icx_charge_acct_seg8(i);
1848           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG9' THEN
1849              v_segment_value(j) := icx_charge_acct_seg9(i);
1850           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG10' THEN
1851              v_segment_value(j) := icx_charge_acct_seg10(i);
1852           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG11' THEN
1856           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG13' THEN
1853              v_segment_value(j) := icx_charge_acct_seg11(i);
1854           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG12' THEN
1855              v_segment_value(j) := icx_charge_acct_seg12(i);
1857              v_segment_value(j) := icx_charge_acct_seg13(i);
1858           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG14' THEN
1859              v_segment_value(j) := icx_charge_acct_seg14(i);
1860           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG15' THEN
1861              v_segment_value(j) := icx_charge_acct_seg15(i);
1862           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG16' THEN
1863              v_segment_value(j) := icx_charge_acct_seg16(i);
1864           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG17' THEN
1865              v_segment_value(j) := icx_charge_acct_seg17(i);
1866           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG18' THEN
1867              v_segment_value(j) := icx_charge_acct_seg18(i);
1868           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG19' THEN
1869              v_segment_value(j) := icx_charge_acct_seg19(i);
1870           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG20' THEN
1871              v_segment_value(j) := icx_charge_acct_seg20(i);
1872           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG21' THEN
1873              v_segment_value(j) := icx_charge_acct_seg21(i);
1874           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG22' THEN
1875              v_segment_value(j) := icx_charge_acct_seg22(i);
1876           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG23' THEN
1877              v_segment_value(j) := icx_charge_acct_seg23(i);
1878           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG24' THEN
1879              v_segment_value(j) := icx_charge_acct_seg24(i);
1880           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG25' THEN
1881              v_segment_value(j) := icx_charge_acct_seg25(i);
1882           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG26' THEN
1886           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG28' THEN
1883              v_segment_value(j) := icx_charge_acct_seg26(i);
1884           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG27' THEN
1885              v_segment_value(j) := icx_charge_acct_seg27(i);
1887              v_segment_value(j) := icx_charge_acct_seg28(i);
1888           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG29' THEN
1889              v_segment_value(j) := icx_charge_acct_seg29(i);
1890           ELSIF v_ak_attributes_table(j) = 'ICX_CHARGE_ACCT_SEG30' THEN
1891              v_segment_value(j) := icx_charge_acct_seg30(i);
1892           END IF;   /* IF v_ak_attributes_table(j) */
1893 
1894       END LOOP;  /* FOR j in 1 .. */
1895 
1896       -- do not insert rows which are null or zero percent
1897       IF (icx_percentage(i) IS NOT NULL AND icx_percentage(i) > 0) THEN
1898         -- Insert into distribution table
1899         icx_req_acct2.update_account( v_cart_line_id => v_cart_line_id,
1900                                 v_oo_id => v_org_id,
1901                                 v_cart_id => v_cart_id,
1902                                 v_segments => v_segment_value,
1903                                 v_allocation_type => v_allocation_type,
1904                                 v_allocation_value => to_number(icx_percentage(i)));
1905       END IF;  /* icx_percentage(i) */
1906 
1907 
1908     END LOOP;  /* FOR i in 1.. v_total_rows_returned */
1909     ELSE
1910       -- concatenated segment is turned for display
1911     -- loop through every line returned to get the account segments
1912     FOR i in 1.. v_total_rows_returned LOOP
1913       IF (icx_percentage(i) IS NOT NULL AND icx_percentage(i) > 0) THEN
1914         -- Insert into distribution table
1915         icx_req_acct2.update_account_num( v_cart_line_id => v_cart_line_id,
1916                                 v_oo_id => v_org_id,
1917                                 v_cart_id => v_cart_id,
1918                                 v_account_num => icx_charge_account_num(i),
1919                                 v_allocation_type => v_allocation_type,
1920                                 v_allocation_value => to_number(icx_percentage(i)));
1921       END IF;  /* icx_percentage(i) */
1922 
1923     END LOOP;  /* FOR i in 1.. v_total_rows_returned */
1924     END IF; /* v_concatenated_segment = 'N' */
1925  END IF; /* validate session */
1926 
1927 EXCEPTION
1928   WHEN OTHERS THEN
1929     -- htp.p('Error in apply_account_distributions ' || substr(SQLERRM, 1, 512));
1930     icx_util.add_error(substr(SQLERRM, 12, 512));
1931     icx_util.error_page_print;
1932 
1933 END apply_account_distributions;
1934 
1935 
1936 ------------------------------------------------------
1937 PROCEDURE apply_to_all(v_cart_id IN NUMBER,
1938                        v_cart_line_id IN NUMBER) IS
1939 
1940 l                   NUMBER := NULL;
1941 v_ak_segments       segment_table;
1942 v_num_segments      NUMBER := 0;
1943 v_where_clause      VARCHAR2(2000);
1944 v_employee_id       NUMBER := NULL;
1945 v_web_user_id       NUMBER := NULL;
1949 v_allocation_value  NUMBER := 0;
1946 v_responsibility_id NUMBER := NULL;
1947 v_org_id            NUMBER := NULL;
1948 v_allocation_type   VARCHAR2(50);
1950 v_row_count         NUMBER := 0;
1951 v_concatenated_segment    VARCHAR2(2) := NULL;
1952 
1953 v_distribution_lines_region  VARCHAR2(50) := NULL;
1954 
1955 l_values          icx_util.char240_table;
1956 v_segment_value   fnd_flex_ext.SegmentArray;
1957 v_line_segments   fnd_flex_ext.SegmentArray;
1958 
1959  CURSOR get_ak_attributes IS
1960         SELECT  ltrim(rtrim(a.ATTRIBUTE_CODE)) ATTRIBUTE_NAME,
1961                 a.UPDATE_FLAG  UPDATE_FLAG
1962         FROM       ak_region_items a,
1963         ak_attributes b,
1964         ak_regions c
1965         WHERE      a.NODE_DISPLAY_FLAG = 'Y'
1966         AND        a.ATTRIBUTE_CODE = b.ATTRIBUTE_CODE
1967         AND        a.ATTRIBUTE_APPLICATION_ID = b.ATTRIBUTE_APPLICATION_ID
1968         AND        b.DATA_TYPE = 'VARCHAR2'
1969         AND        c.REGION_APPLICATION_ID = 601
1970         AND        a.REGION_CODE = c.REGION_CODE
1971         AND        a.REGION_APPLICATION_ID = c.REGION_APPLICATION_ID
1972         AND        a.REGION_CODE = 'ICX_CART_LINE_DISTRIBUTIONS_R'
1973         AND        a.ATTRIBUTE_CODE LIKE 'ICX_CHARGE_ACCT_SEG%'
1974         ORDER BY a.display_sequence;
1975 
1976  -- Exclude the current line
1977  CURSOR get_req_lines IS
1978         SELECT cart_line_id
1979         FROM icx_shopping_cart_lines
1980         WHERE cart_id = v_cart_id
1981         AND   cart_line_id <> v_cart_line_id;
1982 
1983  CURSOR get_distributions IS
1984         SELECT distribution_id
1985         FROM icx_cart_line_distributions
1986         WHERE cart_id = v_cart_id
1987         AND   cart_line_id = v_cart_line_id;
1988 
1989  CURSOR get_distributions_account_num IS
1990         SELECT charge_account_num, allocation_value, allocation_type
1991         FROM icx_cart_line_distributions
1992         WHERE cart_id = v_cart_id
1993         AND   cart_line_id = v_cart_line_id;
1994 
1995  CURSOR check_concatenated_segment IS
1996         SELECT  1
1997         FROM       ak_region_items a,
1998         ak_attributes b,
1999         ak_regions c,
2000         ak_object_attributes d
2001         WHERE      a.NODE_DISPLAY_FLAG = 'Y'
2002         AND        a.ATTRIBUTE_CODE = b.ATTRIBUTE_CODE
2003         AND        a.ATTRIBUTE_APPLICATION_ID = b.ATTRIBUTE_APPLICATION_ID
2004         AND        b.DATA_TYPE = 'VARCHAR2'
2005         AND        c.REGION_APPLICATION_ID = 601
2006         AND        a.REGION_CODE = c.REGION_CODE
2007         AND        a.REGION_APPLICATION_ID = c.REGION_APPLICATION_ID
2011         AND        a.attribute_code = 'ICX_CHARGE_ACCOUNT_NUM';
2008         AND        c.DATABASE_OBJECT_NAME = d.DATABASE_OBJECT_NAME
2009         AND        a.ATTRIBUTE_CODE = d.ATTRIBUTE_CODE
2010         AND        a.region_code = 'ICX_CART_LINE_DISTRIBUTIONS_R'
2012 
2013 BEGIN
2014 
2015     v_distribution_lines_region  := 'ICX_CART_LINE_DISTRIBUTIONS_R';
2016     v_allocation_type := 'PERCENT';
2017 
2018     v_org_id := icx_sec.getId(icx_sec.PV_ORG_ID);
2019     v_employee_id := icx_sec.getID(icx_sec.PV_INT_CONTACT_ID);
2020     v_web_user_id := icx_sec.getID(icx_sec.PV_WEB_USER_ID);
2021     v_responsibility_id  := icx_sec.getID(icx_sec.PV_RESPONSIBILITY_ID);
2022 
2023     -- Determine what is turned for display, the concatenated segments or
2024     -- invidual segments.
2025     OPEN check_concatenated_segment;
2026     FETCH check_concatenated_segment INTO v_row_count;
2027     CLOSE check_concatenated_segment;
2028 
2029     IF  v_row_count = 1 THEN
2030         v_concatenated_segment := 'Y';
2031     ELSE
2032         v_concatenated_segment := 'N';
2033     END IF;
2034 
2035     -- Delte all the account distributions of all the lines except for
2036     -- for the current line. The 'apply to all' overwrites the existing
2037     -- distributions of other lines.
2038     DELETE FROM icx_cart_line_distributions
2039     WHERE cart_id = v_cart_id
2040     AND   cart_line_id <> v_cart_line_id;
2041 
2042     IF v_concatenated_segment = 'N' THEN
2043     /*
2044     Get the segment table first. This will be used to compare the
2045     segments with the actual segment value later. The update flag is updated
2046     Y in the pl/sql table record to indicate whether the default account need to
2047     be inherited from the line default.
2048     */
2049     l := 1;
2050     FOR ak_col IN get_ak_attributes LOOP
2051       v_ak_segments(l).segment_name := ak_col.attribute_name;
2052       v_ak_segments(l).update_flag  := ak_col.update_flag;
2053     l := l + 1;
2054     END LOOP;  /* FOR ak_col */
2055 
2056     v_num_segments := v_ak_segments.COUNT;
2057 
2058     -- For every line in the req apply the current distribution
2059     FOR req_line IN get_req_lines LOOP
2060 
2061       -- Get the current distribution
2062       FOR prec IN get_distributions LOOP
2063 
2064         v_where_clause := 'CART_ID =' || v_cart_id || 'AND CART_LINE_ID =' || v_cart_line_id || 'AND DISTRIBUTION_ID =' || prec.distribution_id;
2065 
2066         ak_query_pkg.exec_query(P_PARENT_REGION_APPL_ID => 601,
2067                                 P_PARENT_REGION_CODE    => v_distribution_lines_region,
2068                                 P_RESPONSIBILITY_ID     => v_responsibility_id,
2072                                 P_RETURN_CHILDREN       => 'F');
2069                                 P_USER_ID               => v_web_user_id,
2070                                 P_WHERE_CLAUSE          => v_where_clause,
2071                                 P_RETURN_PARENTS        => 'T',
2073 
2074         IF ak_query_pkg.g_results_table.COUNT > 0 THEN
2075           l := 1;
2076           FOR r IN 0..ak_query_pkg.g_results_table.LAST LOOP
2077 
2078             icx_util.transfer_Row_To_Column(ak_query_pkg.g_results_table(r),l_values);
2079 
2080             FOR i IN ak_query_pkg.g_items_table.FIRST .. ak_query_pkg.g_items_table.LAST LOOP
2081 
2082               IF ak_query_pkg.g_items_table(i).node_display_flag = 'Y'
2083                  AND (substr(ltrim(rtrim(ak_query_pkg.g_items_table(i).attribute_code)), 1, 19) = 'ICX_CHARGE_ACCT_SEG') THEN
2084 
2085                    -- Build the segment values in segment array
2086                    v_segment_value(l) := l_values(ak_query_pkg.g_items_table(i).value_id);
2087                    l := l + 1;
2088               END IF; /* IF ak_query_pkg */
2089 
2090               IF ak_query_pkg.g_items_table(i).attribute_code = 'ICX_PERCENTAGE' THEN
2091                  v_allocation_value := l_values(ak_query_pkg.g_items_table(i).value_id);
2092               END IF; /* IF ak_query_pkg */
2093 
2094             END LOOP; /* FOR i in items table */
2095 
2096           END LOOP; /* FOR r in results table */
2097 
2098         END IF; /* IF results_table.COUNT > 0 */
2099 
2100         -- Get the default segment for the current line
2101         icx_req_acct2.get_default_segs (v_cart_id => v_cart_id,
2102                                         v_cart_line_id => req_line.cart_line_id,
2103                                         v_emp_id => v_employee_id,
2104                                         v_oo_id => v_org_id,
2105                                         v_segments => v_line_segments);
2106 
2107         -- Only update the segments that are marked for update
2108         IF v_line_segments.COUNT > 0 THEN
2109 
2110            l := 1;
2111            FOR j IN v_ak_segments.FIRST .. v_ak_segments.LAST LOOP
2112              IF v_ak_segments(l).update_flag = 'Y' THEN
2113                 v_line_segments(l) := v_segment_value(l);
2114              END IF;
2115              l := l + 1;
2116            END LOOP; /* FOR v_line_segments */
2117 
2118 /*
2119 -- debug
2120 debug_plsql.write_time('Cart id  = ' || v_cart_id);
2121 debug_plsql.write_time('Cart line id  = ' || req_line.cart_line_id);
2122 debug_plsql.write_time('Current: v_segment_value(1) = ' || v_segment_value(1));
2123 debug_plsql.write_time('Current: v_segment_value(2) = ' || v_segment_value(2));
2124 debug_plsql.write_time('Current: v_segment_value(3) = ' || v_segment_value(3));
2125 debug_plsql.write_time('Current: v_segment_value(4) = ' || v_segment_value(4));
2126 debug_plsql.write_time('Current: v_segment_value(5) = ' || v_segment_value(5));
2127 debug_plsql.write_time('Current: v_segment_value(6) = ' || v_segment_value(6));
2128 debug_plsql.write_time('v_line_segments(1) = ' || v_line_segments(1));
2129 debug_plsql.write_time('v_line_segments(2) = ' || v_line_segments(2));
2130 debug_plsql.write_time('v_line_segments(3) = ' || v_line_segments(3));
2131 debug_plsql.write_time('v_line_segments(4) = ' || v_line_segments(4));
2132 debug_plsql.write_time('v_line_segments(5) = ' || v_line_segments(5));
2133 debug_plsql.write_time('v_line_segments(6) = ' || v_line_segments(6));
2134 debug_plsql.write_time('Allocation value = ' || v_allocation_value);
2135 */
2136 
2137            icx_req_acct2.update_account( v_cart_line_id => req_line.cart_line_id,
2138                                          v_oo_id => v_org_id,
2139                                          v_cart_id => v_cart_id,
2140                                          v_segments => v_line_segments,
2141                                          v_allocation_type => v_allocation_type,
2142                                          v_allocation_value => v_allocation_value,
2143                                          v_validate_flag => 'N');
2144        ELSIF v_line_segments.COUNT = 0 THEN
2145            /** If the code reaches here, we have been unable to build default
2146                account from the item/person. In this case, regardless of the
2147                updateability of the segments, we are going to copy over the
2148                current distribution's segments to all the lines.
2149            **/
2150            l := 1;
2151            FOR j IN v_ak_segments.FIRST .. v_ak_segments.LAST LOOP
2152 
2153                 v_line_segments(l) := v_segment_value(l);
2154 
2155              l := l + 1;
2156            END LOOP; /* FOR v_ak_segments */
2157            /** Insert the distribution **/
2158            icx_req_acct2.update_account( v_cart_line_id => req_line.cart_line_id,
2159                                          v_oo_id => v_org_id,
2160                                          v_cart_id => v_cart_id,
2161                                          v_segments => v_line_segments,
2162                                          v_allocation_type => v_allocation_type,
2163                                          v_allocation_value => v_allocation_value,
2164                                          v_validate_flag => 'N');
2165         END IF; /* IF v_line_segments.COUNT > 0 */
2166 
2167       END LOOP;  /* FOR prec IN get_distributions */
2168 
2169     END LOOP;  /* FOR req_line */
2170     ELSE
2171       -- Concatenated segments are turned for display
2172       -- For every line in the req apply the current distribution
2173       FOR req_line IN get_req_lines LOOP
2174           FOR prec IN get_distributions_account_num LOOP
2175           -- Insert into distribution table
2176 
2177           icx_req_acct2.update_account_num(v_cart_line_id => req_line.cart_line_id,
2178                                   v_oo_id => v_org_id,
2179                                   v_cart_id => v_cart_id,
2180                                   v_account_num => prec.charge_account_num,
2181                                   v_allocation_type => prec.allocation_type,
2182                                   v_allocation_value => prec.allocation_value,
2183                                   v_validate_flag => 'N');
2184 
2185           END LOOP;  /* FOR prec */
2186       END LOOP;  /* FOR req_line */
2187     END IF; /* if v_concatenated_segment = 'N' */
2188 
2189 EXCEPTION
2190   WHEN OTHERS THEN
2191     -- htp.p('Error in apply_to_all' || substr(SQLERRM, 1, 512));
2192     icx_util.add_error(substr(SQLERRM, 12, 512));
2193     icx_util.error_page_print;
2194 
2195 END apply_to_all;
2196 
2197 ------------------------------------------------------
2198 PROCEDURE display_account_errors(v_cart_id IN NUMBER,
2199                                  v_cart_line_id IN NUMBER) IS
2200 
2201   CURSOR get_errors(l_cart_id NUMBER) IS
2202   SELECT error_text
2203   FROM icx_req_cart_errors
2204   WHERE cart_id = v_cart_id
2205   AND   cart_line_id = v_cart_line_id
2206   AND distribution_num IS NOT NULL;
2207 
2208   l_first_time VARCHAR2(1);
2209 
2210 BEGIN
2211 
2212     l_first_time := 'Y';
2213     FOR prec IN get_errors(v_cart_id) LOOP
2214        IF l_first_time = 'Y' THEN
2215           htp.p('<TABLE BORDER=5>');
2216           l_first_time := 'N';
2217        END IF;
2218 
2219        htp.p('<TR><TD>' || prec.error_text || '</TD></TR>');
2220     END LOOP;
2221     IF l_first_time = 'N' THEN
2222        htp.p('</TABLE>');
2223     END IF;
2224 
2225 EXCEPTION
2226   WHEN OTHERS THEN
2227     -- htp.p('Error in display_account_errors' || substr(SQLERRM, 1, 512));
2228     icx_util.add_error(substr(SQLERRM, 12, 512));
2229     icx_util.error_page_print;
2230 
2231 END display_account_errors;
2232 
2233 END icx_req_acct_dist;