noalyss Version-9
anc_script.js
Go to the documentation of this file.
1/*
2 * This file is part of NOALYSS.
3 *
4 * NOALYSS is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * NOALYSS is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with NOALYSS; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18/* $Revision$ */
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/**
23 * @file
24 * javascript for the analytic accountancy
25 */
26
27/**
28 * add a row for the CA
29 * \param p_table_id
30 * \param p_amount amount to reach
31 */
32function add_row(p_table, p_seq)
33{
34 var mytable = g(p_table).tBodies[0];
35 if (!mytable)
36 {
37 return;
38 }
39 var a_amount=document.getElementsByClassName(p_table+'-amount');
40 var max=0;
41 for (var e=0;e<a_amount.length;e++) {
42 max +=Math.abs( parseFloat(a_amount[e].value));
43 e=a_amount.length+1;
44 }
45
46 if (mytable.rows.length > 15)
47 {
48 alert_box(content[55]);
49 return;
50 }
51 var amount = compute_total_table(p_table, p_seq);
52 if (max < amount)
53 {
54 alert_box(content[48]+' '+content[56]+ ' '+max + content[57]+' '+ amount);
55
56 }
57 // For the detail view (modify_op) there is several form and then several time the
58 // element
59 var rowToCopy = mytable.rows[1];
60 var row = mytable.insertRow(mytable.rows.length);
61
62 for (var i = 0; i < rowToCopy.cells.length; i++)
63 {
64 var cell = row.insertCell(i);
65 var txt = rowToCopy.cells[i].innerHTML;
66 cell.innerHTML = txt;
67 }
68 var col = document.getElementsByName("val[" + p_seq + "][]");
69 let tmp_amount=max - amount;
70 col[col.length - 1].value = Math.round(tmp_amount*100)/100;
71 anc_refresh_remain(p_table, p_seq);
72}
73/**
74 *Compute total of a form from Anc_Operation::display_form_plan
75 *@param {dom_id} p_table table id
76 *@param {int}seq sequence of the line
77 *@see Anc_Operation::display_form_plan
78 */
79function compute_total_table(p_table, seq)
80{
81 try {
82
83 var i = 0;
84 var tot = 0;
85 var col = document.getElementsByClassName(p_table+'-value-'+seq);
86 var rounded_value = 0 ;
87 for (i = 0; i < col.length; i++)
88 {
89
90 rounded_value = Math.round(parseFloat(col[i].value) *100);
91 tot += rounded_value
92
93 }
94 return tot/100;
95 }
96 catch (e)
97 {
98 alert_box(e.message);
99 }
100}
101/**
102 * Refresh remain of account. analytic
103 *@param p_table table id
104 *@param p_seq sequence of the line
105 *@see Anc_Operation::display_form_plan
106 */
107function anc_refresh_remain(p_table, p_seq)
108{
109
110 try
111 {
112 var a_amount=document.getElementsByClassName(p_table+'-amount');
113 var tot_line=0;
114 for (var e=0;e<a_amount.length;e++) {
115 tot_line +=Math.abs( parseFloat(a_amount[e].value));
116 e=a_amount.length+1;
117 }
118
119 var tot_table = compute_total_table(p_table, p_seq);
120 var remain = tot_line - tot_table;
121
122 remain = Math.round(remain * 100) / 100;
123 $('remain' + p_table).innerHTML = remain;
124 if (remain == 0)
125 {
126 $('remain' + p_table).style.color = "green"
127 }
128 else
129 {
130 $('remain' + p_table).style.color = "red"
131 }
132 } catch (a)
133 {
134 alert_box(a.message);
135 }
136}
137/**
138 * Check the amount of the CA
139 * @param p_style : error or ok, if ok show a ok box if the amount are equal
140 *
141 *
142 * @returns true if the amounts are equal
143 */
144function verify_ca(div)
145{
146 try
147 {
148
149 var idx = 0;
150 var amount_error = 0;
151 // put a maximum
152 while (idx < 50)
153 {
154 var table = div + 't' + idx;
155 if (g(table))
156 {
157 var total_amount = 0;
158 // table is found compute the different val[]
159 var array_value = document.getElementsByClassName(table+'-value-'+idx);
160
161
162 for (var i = 0; i < array_value.length; i++)
163 {
164 if (isNaN(array_value[i].value))
165 {
166 array_value[i].value = 0;
167 }
168
169 total_amount += parseFloat(array_value[i].value);
170 }
171 var a_amount=document.getElementsByClassName(table+'-amount');
172 var amount=0;
173 for (var e=0;e<a_amount.length;e++) {
174 amount +=Math.abs( parseFloat(a_amount[e].value));
175 e=a_amount.length+1;
176 }
177 if (isNaN(amount)) {
178 amount=0;
179 } else {
180 amount = Math.round(amount*100)/100;
181 }
182 var diff = amount*100 - total_amount*100;
183 if (Math.round(diff/100) != 0.0)
184 {
185 g(table).style.backgroundColor = 'red';
186 amount_error++;
187 }
188 else
189 {
190 g(table).style.backgroundColor = 'lightgreen';
191
192 }
193 idx++;
194 }
195 else
196 break;
197 }
198 if (amount_error != 0)
199 {
200 alert_box(content[54]);
201 return false;
202 }
203 return true;
204 }
205 catch (e)
206 {
207 alert_box(e.message);
208 return false;
209 }
210}
211/***
212 * open a window for searching a CA account,
213 * @param p_dossier dossier id
214 * @param p_target ctrl to update
215 * @param p_source ctrl containing the pa_id
216 */
217function search_ca(p_dossier, p_target, p_source)
218{
219 var pa_id = g(p_source).value;
220 waiting_box();
221 removeDiv('search_anc');
222 var qs = "op=openancsearch&gDossier=" + p_dossier + "&ctl=searchanc";
223 qs += "&c2=" + pa_id + "&c1=" + p_target;
224
225 var action = new Ajax.Request('ajax_misc.php',
226 {
227 method: 'get',
228 parameters: qs,
229 onFailure: null,
230 onSuccess: function(req) {
231 try {
232 remove_waiting_box();
233 var pos = fixed_position(250, 150) + ";width:30%;height:50%";
234 add_div({
235 id: "searchanc",
236 drag: 1,
237 cssclass: "inner_box",
238 style: pos
239 });
240 $('searchanc').innerHTML = req.responseText;
241
242 } catch (e) {
243 alert_box(e.message);
244 }
245 }
246 }
247 );
248
249}
250function search_anc_form(obj)
251{
252 var qs = "op=resultancsearch&ctl=searchanc&";
253 var name = obj.id;
254 qs += $(name).serialize(false);
255 waiting_box();
256 var action = new Ajax.Request('ajax_misc.php',
257 {
258 method: 'get',
259 parameters: qs,
260 onFailure: null,
261 onSuccess: function(req) {
262 try {
263 remove_waiting_box();
264 $('searchanc').innerHTML = req.responseText;
265 req.responseText.evalScripts();
266
267 } catch (e) {
268 alert_box(e.message);
269 }
270 }
271 }
272 );
273 return false;
274}
275function caod_checkTotal()
276{
277 var ie4 = false;
278 if (document.all)
279 {
280 ie4 = true;
281 }// Ajouter getElementById par document.all[str]
282 var total_deb = 0.0;
283 var total_cred = 0.0;
284 var nb_item = g('nbrow').value;
285
286 for (var i = 0; i < nb_item; i++)
287 {
288 var doc_amount = g("pamount" + i);
289 if (!doc_amount)
290 {
291 return;
292 }
293 var side = g("pdeb" + i);
294 if (!side)
295 {
296 return;
297 }
298 var amount = parseFloat(doc_amount.value);
299
300 if (isNaN(amount) == true)
301 {
302 amount = 0.0;
303 }
304 amount = Math.round(amount*100)/100;
305 if (side.checked == false)
306 {
307 total_cred += amount;
308 }
309 if (side.checked == true)
310 {
311 total_deb += amount;
312 }
313 }
314
315
316
317 var r_total_cred = Math.round(total_cred * 100) / 100;
318 var r_total_deb = Math.round(total_deb * 100) / 100;
319 g('totalDeb').innerHTML = r_total_deb;
320 g('totalCred').innerHTML = r_total_cred;
321
322 if (r_total_deb != r_total_cred)
323 {
324 g("totalDiff").style.color = "red";
325 g("totalDiff").style.fontWeight = "bold";
326 g("totalDiff").innerHTML = "Différence";
327 var diff = total_deb - total_cred;
328 diff = Math.round(diff * 100) / 100;
329 g("totalDiff").innerHTML = diff;
330
331 }
332 else
333 {
334 g("totalDiff").innerHTML = "0.0";
335 }
336}
337
338/**
339 * remove an operation
340 *@param p_dossier is the folder
341 *@param p_oa_group is the group of the analytic operation
342 */
343function anc_remove_operation(p_dossier, p_oa_group)
344{
345 smoke.confirm(content[50]+"\n",
346 function (a)
347 {
348 if ( a) {
349 var obj = {"oa":
350 p_oa_group, "gDossier":
351 p_dossier, "op": "remove_anc"};
352 var queryString = encodeJSON(obj);
353 var e = new Ajax.Request("ajax_misc.php",
354 {method: 'get', parameters: queryString,onSuccess:function req() {
355 $("tr"+p_oa_group).remove();
356 }
357
358 });
359
360 } else
361 {
362 return;
363 }
364 });
365}
366/**
367 * add a row in misc operation for ANC
368 * the code must be adapted for that
369 */
370function anc_add_row(tableid)
371{
372 var style = 'class="input_text"';
373 var mytable = g(tableid).tBodies[0];
374 var nNumberRow = mytable.rows.length;
375 var oRow = mytable.insertRow(nNumberRow);
376 var rowToCopy = mytable.rows[1];
377 var nNumberCell = rowToCopy.cells.length;
378 var nb = g("nbrow");
379 var oNewRow = mytable.insertRow(nNumberRow);
380 for (var e = 0; e < nNumberCell; e++)
381 {
382 var newCell = oRow.insertCell(e);
383 var tt = rowToCopy.cells[e].innerHTML;
384 var new_tt = tt.replace(/pop0/g, "pop" + nb.value);
385 var new_tt = tt.replace(/qcode0/g, "qcode" + nb.value);
386 new_tt = new_tt.replace(/pamount0/g, "pamount" + nb.value);
387 new_tt = new_tt.replace(/pdeb0/g, "pdeb" + nb.value);
388 newCell.innerHTML = new_tt;
389 new_tt.evalScripts();
390 }
391 $("pamount" + nb.value).value = "0";
392 nb.value++;
393}
394/**
395 * this function is called before the querystring is send to the
396 * fid2.php, add a filter based on the ledger 'p_jrn'
397 *@param obj is the input field
398 *@param queryString is the queryString to modify
399 *@see ICard::input
400 */
401function filter_anc(obj, queryString)
402{
403 var pa_id = obj.plan_ctl;
404 queryString = queryString + "&pa_id=" + pa_id;
405 return queryString;
406}
407/**
408 * compute and display Analytic activity, related to the choosen distribution key
409 * @param p_dossier is the dossier id
410 * @param p_table is table id to replace
411 * @param p_amount is the amount to distribute
412 * @param p_key_id is the choosen key
413 *
414 */
415function anc_key_compute(p_dossier, p_table, p_amount, p_key_id)
416{
417 waiting_box();
418 var op = "op=anc_key_compute";
419 var queryString = op + "&gDossier=" + p_dossier + "&t=" + p_table + "&amount=" + p_amount + '&key=' + p_key_id;
420 try {
421 var action = new Ajax.Request(
422 "ajax_misc.php",
423 {
424 method: 'get',
425 parameters: queryString,
426 onFailure: error_box,
427 onSuccess: function(req, json) {
428 try
429 {
430 var name_ctl = p_table;
431 var answer = req.responseXML;
432 remove_waiting_box();
433 var html = answer.getElementsByTagName('code');
434 if (html.length == 0) {
435 var rec = req.responseText;
436 alert_box('erreur :' + rec);
437 }
438
439 var code_html = getNodeText(html[0]); // Firefox ne prend que les 4096 car.
440 code_html = unescape_xml(code_html);
441 $(name_ctl).innerHTML = code_html;
442 code_html.evalScripts();
443 removeDiv('div_anc_key_choice');
444 } catch (e)
445 {
446 error_message(e.message);
447 }
448 }
449 }
450
451 );
452 } catch (e) {
453 error_message(e.message);
454 }
455}
456/**
457 * choose the distribution key
458 * in ajax, a window let you choose what key you want to use
459 *
460 * @param p_dossier is the dossier
461 * @param p_table the table id of the target
462 * @param p_amount amount to distribute
463 * @param p_ledger
464 */
465function anc_key_choice(p_dossier, p_table, p_amount,p_ledger)
466{
467 waiting_box();
468 var op = 'op=anc_key_choice';
469 var queryString = op + "&gDossier=" + p_dossier + "&t=" + p_table + "&amount=" + p_amount;
470 try {
471 queryString+='&led='+p_ledger;
472 var action = new Ajax.Request(
473 "ajax_misc.php",
474 {
475 method: 'get',
476 parameters: queryString,
477 onFailure: error_box,
478 onSuccess: function(req, json) {
479 try
480 {
481 var name_ctl = 'div_anc_key_choice';
482 var answer = req.responseXML;
483 remove_waiting_box();
484 var html = answer.getElementsByTagName('code');
485 if (html.length == 0) {
486 var rec = req.responseText;
487 alert_box('erreur :' + rec);
488 }
489
490 var code_html = getNodeText(html[0]); // Firefox ne prend que les 4096 car.
491 code_html = unescape_xml(code_html);
492 var position=fixed_position(50,120);
493 add_div({id: name_ctl, cssclass: 'inner_box', style: position, drag: 1});
494 $(name_ctl).innerHTML = code_html;
495 } catch (e)
496 {
497 error_message(e.message);
498 }
499 }
500 }
501
502 );
503
504 } catch (e) {
505 error_message(e.message);
506 }
507}
508
509/**
510 * reset all the details of a row
511 * @param p_dossier is the dossier
512 * @param p_table the table id of the target
513 * @param p_amount amount to distribute
514 * @param p_ledger ledger id
515 * @param p_jrnx_id jrnx.id
516 */
517function anc_key_clean(p_dossier, p_table, p_amount,p_ledger,p_jrnx_id,p_sequence)
518{
519 waiting_box();
520 var op = 'op=anc_key_clean';
521 var queryString = op + "&gDossier=" + p_dossier + "&t=" + p_table + "&amount=" + p_amount+"&jrnx_id="+p_jrnx_id+'&p_seq='+p_sequence;
522 try {
523 queryString+='&led='+p_ledger;
524 var action = new Ajax.Request(
525 "ajax_misc.php",
526 {
527 method: 'get',
528 parameters: queryString,
529 onFailure: error_box,
530 onSuccess: function(req, json) {
531 try
532 {
533 var answer = req.responseXML;
534 remove_waiting_box();
535 var html = answer.getElementsByTagName('code');
536 if (html.length == 0) {
537 var rec = req.responseText;
538 alert_box('erreur :' + rec);
539 }
540
541 var code_html = getNodeText(html[0]); // Firefox ne prend que les 4096 car.
542 code_html = unescape_xml(code_html);
543 $(p_table+"t"+p_sequence).innerHTML=code_html;
544 } catch (e)
545 {
546 error_message(e.message);
547 }
548 }
549 }
550
551 );
552
553 } catch (e) {
554 error_message(e.message);
555 }
556}
557/**
558 * Add a row for distribution key.
559 * This function add a row in the table key distribution
560 * @param p_table table id
561 */
562function add_row_key(p_table)
563{
564 var mytable = g(p_table).tBodies[0];
565 if (!mytable)
566 {
567 return;
568 }
569 var table_length=mytable.rows.length ;
570 if ( table_length > 15)
571 {
572 alert_box("Maximum 15 lignes ");
573 return;
574 }
575 var rowToCopy = mytable.rows[1];
576 var row = mytable.insertRow(table_length);
577 var nb=mytable.rows.length -2;
578 for (var i = 0; i < rowToCopy.cells.length; i++)
579 {
580 var cell = row.insertCell(i);
581 cell.className=rowToCopy.cells[i].className;
582 var txt = rowToCopy.cells[i].innerHTML;
583 if ( i == 0 )
584 {
585 var change=nb+1;
586 cell.innerHTML =change+'<input id="row[]" type="hidden" value="-1" name="row[]">';
587 }
588 else
589 {
590 if (i == rowToCopy.cells.length -1 ) {
591 txt=txt.replace(/value="[0-9]*.{1}[0-9]*"/,'value="0"')
592 } else {
593 txt=txt.replace(/po_id\[0\]/g,'po_id['+nb+']');
594 }
595 cell.innerHTML = txt;
596 }
597 }
598 $('total_key').innerHTML="?";
599}
600function anc_key_compute_table()
601{
602 var tot=0;
603 var i=0;
604 var value=0;
605 var percent=document.getElementsByName('percent[]');
606 for (i=0;i<percent.length;i++)
607 {
608 value=percent[i].value;
609 if ( value == 'undefined')
610 {
611 value=0;
612 }
613 if ( isNaN(value)) {
614 value=0;
615 }
616 tot=tot+Math.round(value*100)/100;
617 }
618 $('total_key').innerHTML=Math.round(tot*100)/100;
619
620}
621
622function anc_detail_op(p_oa_group,gDossier) {
623 waiting_box();
624 // create div
625 new Ajax.Request ("ajax_misc.php",{
626 method:"get",
627 parameters:{"gDossier":gDossier,"op":"anc_detail_op","oa_group":p_oa_group},
628 onSuccess:function (req) {
629 add_div({"id":"anc_detail_op_div","cssclass":"inner_box","style":"position:fixed;top:5%"});
630 $('anc_detail_op_div').update(req.responseText);
631 remove_waiting_box();
632 }
633 });
634}