2 * This file is part of NOALYSS.
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.
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.
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
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
24 * javascript for the analytic accountancy
28 * add a row for the CA
30 * \param p_amount amount to reach
32function add_row(p_table, p_seq)
34 var mytable = g(p_table).tBodies[0];
39 var a_amount=document.getElementsByClassName(p_table+'-amount');
41 for (var e=0;e<a_amount.length;e++) {
42 max +=Math.abs( parseFloat(a_amount[e].value));
46 if (mytable.rows.length > 15)
48 alert_box(content[55]);
51 var amount = compute_total_table(p_table, p_seq);
54 alert_box(content[48]+' '+content[56]+ ' '+max + content[57]+' '+ amount);
57 // For the detail view (modify_op) there is several form and then several time the
59 var rowToCopy = mytable.rows[1];
60 var row = mytable.insertRow(mytable.rows.length);
62 for (var i = 0; i < rowToCopy.cells.length; i++)
64 var cell = row.insertCell(i);
65 var txt = rowToCopy.cells[i].innerHTML;
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);
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
79function compute_total_table(p_table, seq)
85 var col = document.getElementsByClassName(p_table+'-value-'+seq);
86 var rounded_value = 0 ;
87 for (i = 0; i < col.length; i++)
90 rounded_value = Math.round(parseFloat(col[i].value) *100);
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
107function anc_refresh_remain(p_table, p_seq)
112 var a_amount=document.getElementsByClassName(p_table+'-amount');
114 for (var e=0;e<a_amount.length;e++) {
115 tot_line +=Math.abs( parseFloat(a_amount[e].value));
119 var tot_table = compute_total_table(p_table, p_seq);
120 var remain = tot_line - tot_table;
122 remain = Math.round(remain * 100) / 100;
123 $('remain' + p_table).innerHTML = remain;
126 $('remain' + p_table).style.color = "green"
130 $('remain' + p_table).style.color = "red"
134 alert_box(a.message);
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
142 * @returns true if the amounts are equal
144function verify_ca(div)
150 var amount_error = 0;
154 var table = div + 't' + idx;
157 var total_amount = 0;
158 // table is found compute the different val[]
159 var array_value = document.getElementsByClassName(table+'-value-'+idx);
162 for (var i = 0; i < array_value.length; i++)
164 if (isNaN(array_value[i].value))
166 array_value[i].value = 0;
169 total_amount += parseFloat(array_value[i].value);
171 var a_amount=document.getElementsByClassName(table+'-amount');
173 for (var e=0;e<a_amount.length;e++) {
174 amount +=Math.abs( parseFloat(a_amount[e].value));
180 amount = Math.round(amount*100)/100;
182 var diff = amount*100 - total_amount*100;
183 if (Math.round(diff/100) != 0.0)
185 g(table).style.backgroundColor = 'red';
190 g(table).style.backgroundColor = 'lightgreen';
198 if (amount_error != 0)
200 alert_box(content[54]);
207 alert_box(e.message);
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
217function search_ca(p_dossier, p_target, p_source)
219 var pa_id = g(p_source).value;
221 removeDiv('search_anc');
222 var qs = "op=openancsearch&gDossier=" + p_dossier + "&ctl=searchanc";
223 qs += "&c2=" + pa_id + "&c1=" + p_target;
225 var action = new Ajax.Request('ajax_misc.php',
230 onSuccess: function(req) {
232 remove_waiting_box();
233 var pos = fixed_position(250, 150) + ";width:30%;height:50%";
237 cssclass: "inner_box",
240 $('searchanc').innerHTML = req.responseText;
243 alert_box(e.message);
250function search_anc_form(obj)
252 var qs = "op=resultancsearch&ctl=searchanc&";
254 qs += $(name).serialize(false);
256 var action = new Ajax.Request('ajax_misc.php',
261 onSuccess: function(req) {
263 remove_waiting_box();
264 $('searchanc').innerHTML = req.responseText;
265 req.responseText.evalScripts();
268 alert_box(e.message);
275function caod_checkTotal()
281 }// Ajouter getElementById par document.all[str]
283 var total_cred = 0.0;
284 var nb_item = g('nbrow').value;
286 for (var i = 0; i < nb_item; i++)
288 var doc_amount = g("pamount" + i);
293 var side = g("pdeb" + i);
298 var amount = parseFloat(doc_amount.value);
300 if (isNaN(amount) == true)
304 amount = Math.round(amount*100)/100;
305 if (side.checked == false)
307 total_cred += amount;
309 if (side.checked == true)
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;
322 if (r_total_deb != r_total_cred)
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;
334 g("totalDiff").innerHTML = "0.0";
339 * remove an operation
340 *@param p_dossier is the folder
341 *@param p_oa_group is the group of the analytic operation
343function anc_remove_operation(p_dossier, p_oa_group)
345 smoke.confirm(content[50]+"\n",
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();
367 * add a row in misc operation for ANC
368 * the code must be adapted for that
370function anc_add_row(tableid)
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;
379 var oNewRow = mytable.insertRow(nNumberRow);
380 for (var e = 0; e < nNumberCell; e++)
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();
391 $("pamount" + nb.value).value = "0";
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
401function filter_anc(obj, queryString)
403 var pa_id = obj.plan_ctl;
404 queryString = queryString + "&pa_id=" + pa_id;
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
415function anc_key_compute(p_dossier, p_table, p_amount, p_key_id)
418 var op = "op=anc_key_compute";
419 var queryString = op + "&gDossier=" + p_dossier + "&t=" + p_table + "&amount=" + p_amount + '&key=' + p_key_id;
421 var action = new Ajax.Request(
425 parameters: queryString,
426 onFailure: error_box,
427 onSuccess: function(req, json) {
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);
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');
446 error_message(e.message);
453 error_message(e.message);
457 * choose the distribution key
458 * in ajax, a window let you choose what key you want to use
460 * @param p_dossier is the dossier
461 * @param p_table the table id of the target
462 * @param p_amount amount to distribute
465function anc_key_choice(p_dossier, p_table, p_amount,p_ledger)
468 var op = 'op=anc_key_choice';
469 var queryString = op + "&gDossier=" + p_dossier + "&t=" + p_table + "&amount=" + p_amount;
471 queryString+='&led='+p_ledger;
472 var action = new Ajax.Request(
476 parameters: queryString,
477 onFailure: error_box,
478 onSuccess: function(req, json) {
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);
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;
497 error_message(e.message);
505 error_message(e.message);
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
517function anc_key_clean(p_dossier, p_table, p_amount,p_ledger,p_jrnx_id,p_sequence)
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;
523 queryString+='&led='+p_ledger;
524 var action = new Ajax.Request(
528 parameters: queryString,
529 onFailure: error_box,
530 onSuccess: function(req, json) {
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);
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;
546 error_message(e.message);
554 error_message(e.message);
558 * Add a row for distribution key.
559 * This function add a row in the table key distribution
560 * @param p_table table id
562function add_row_key(p_table)
564 var mytable = g(p_table).tBodies[0];
569 var table_length=mytable.rows.length ;
570 if ( table_length > 15)
572 alert_box("Maximum 15 lignes ");
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++)
580 var cell = row.insertCell(i);
581 cell.className=rowToCopy.cells[i].className;
582 var txt = rowToCopy.cells[i].innerHTML;
586 cell.innerHTML =change+'<input id="row[]" type="hidden" value="-1" name="row[]">';
590 if (i == rowToCopy.cells.length -1 ) {
591 txt=txt.replace(/value="[0-9]*.{1}[0-9]*"/,'value="0"')
593 txt=txt.replace(/po_id\[0\]/g,'po_id['+nb+']');
595 cell.innerHTML = txt;
598 $('total_key').innerHTML="?";
600function anc_key_compute_table()
605 var percent=document.getElementsByName('percent[]');
606 for (i=0;i<percent.length;i++)
608 value=percent[i].value;
609 if ( value == 'undefined')
616 tot=tot+Math.round(value*100)/100;
618 $('total_key').innerHTML=Math.round(tot*100)/100;
622function anc_detail_op(p_oa_group,gDossier) {
625 new Ajax.Request ("ajax_misc.php",{
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();