noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
anc_script.js
Go to the documentation of this file.
00001 /*
00002  *   This file is part of NOALYSS.
00003  *
00004  *   NOALYSS is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation; either version 2 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   NOALYSS is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with NOALYSS; if not, write to the Free Software
00016  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  */
00018 /* $Revision$ */
00019 
00020 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00021 
00022 /**
00023  * @file
00024  * @brief javascript for the analytic accountancy
00025  */
00026 
00027 /*!\brief add a row for the CA
00028  * \param p_table_id
00029  * \param p_amount amount to reach
00030  */
00031 function add_row(p_table, p_seq)
00032 {
00033     var mytable = g(p_table).tBodies[0];
00034     var max = parseFloat(g('amount_t' + p_seq).value);
00035     if (!mytable)
00036     {
00037         return;
00038     }
00039     var new_value = mytable.rows.length + 1;
00040 
00041 
00042     if (mytable.rows.length > 15)
00043     {
00044         alert("Maximum 15 lignes ");
00045         return;
00046     }
00047     var amount = compute_total_table(p_table, p_seq);
00048     if (max < amount)
00049     {
00050         alert('Montant incorrect : max = ' + max + " calculé=" + amount);
00051         return;
00052     }
00053     // For the detail view (modify_op) there is several form and then several time the
00054     // element
00055     var rowToCopy = mytable.rows[1];
00056     var row = mytable.insertRow(mytable.rows.length);
00057 
00058     for (var i = 0; i < rowToCopy.cells.length; i++)
00059     {
00060         var cell = row.insertCell(i);
00061         var txt = rowToCopy.cells[i].innerHTML;
00062 //      txt=txt.replace(/row_1/g,"row_"+new_value);
00063         cell.innerHTML = txt;
00064     }
00065     var col = document.getElementsByName("val[" + p_seq + "][]");
00066     col[col.length - 1].value = max - amount;
00067     anc_refresh_remain(p_table, p_seq);
00068 }
00069 /**
00070  *Compute total of a form from Anc_Operation::display_form_plan
00071  *@param p_table table id
00072  *@param seq sequence of the line
00073  *@see Anc_Operation::display_form_plan
00074  */
00075 function compute_total_table(p_table, seq)
00076 {
00077     try {
00078 
00079         var i = 0;
00080         var tot = 0;
00081         var col = document.getElementsByName("val[" + seq + "][]");
00082         for (i = 0; i < col.length; i++)
00083         {
00084             // here is the problem
00085             tot += parseFloat(col[i].value);
00086 
00087         }
00088         return tot;
00089     }
00090     catch (e)
00091     {
00092         alert(e.message);
00093     }
00094 }
00095 /**
00096  * Refresh remain of account. analytic
00097  *@param p_table table id
00098  *@param p_seq sequence of the line
00099  *@see Anc_Operation::display_form_plan
00100  */
00101 function anc_refresh_remain(p_table, p_seq)
00102 {
00103     try
00104     {
00105         var tot_line = parseFloat(g('amount_t' + p_seq).value);
00106         var tot_table = compute_total_table(p_table, p_seq);
00107         var remain = tot_line - tot_table;
00108         remain = Math.round(remain * 100) / 100;
00109   //      var popup_table = p_table.toString();
00110 //        p_table = popup_table.replace("popup", "");
00111         $('remain' + p_table).innerHTML = remain;
00112         if (remain == 0)
00113         {
00114             $('remain' + p_table).style.color = "green"
00115         }
00116         else
00117         {
00118             $('remain' + p_table).style.color = "red"
00119         }
00120     } catch (a)
00121     {
00122         alert(a.message);
00123     }
00124 }
00125 /*!
00126  * \brief Check the amount of the CA
00127  * \param p_style : error or ok, if ok show a ok box if the amount are equal
00128  *
00129  *
00130  * \return true if the amounts are equal
00131  */
00132 function verify_ca(div)
00133 {
00134     try
00135     {
00136 
00137         var idx = 0;
00138         var amount_error = 0;
00139         // put a maximum
00140         while (idx < 50)
00141         {
00142             var table = div + 't' + idx;
00143             if (g(table))
00144             {
00145                 var total_amount = 0;
00146                 // table is found compute the different val[]
00147                 var array_value = document.getElementsByName('val[' + idx + '][]');
00148 
00149                 for (var i = 0; i < array_value.length; i++)
00150                 {
00151                     if (isNaN(array_value[i].value))
00152                     {
00153                         array_value[i].value = 0;
00154                     }
00155 
00156                     total_amount += parseFloat(array_value[i].value);
00157                 }
00158                 var amount = parseFloat(g('amount_t' + idx).value);
00159                 var diff = amount - total_amount;
00160 
00161                 if (Math.round(diff, 2) != 0.0)
00162                 {
00163                     g(table).style.backgroundColor = 'red';
00164                     amount_error++;
00165                 }
00166                 else
00167                 {
00168                     g(table).style.backgroundColor = 'lightgreen';
00169 
00170                 }
00171                 idx++;
00172             }
00173             else
00174                 break;
00175         }
00176         if (amount_error != 0)
00177         {
00178             alert('Désolé, les montants pour la comptabilité analytique sont incorrects');
00179             return false;
00180         }
00181         return true;
00182     }
00183     catch (e)
00184     {
00185         alert(e.message);
00186         return false;
00187     }
00188 }
00189 /*!
00190  * \brief open a window for searching a CA account,
00191  * \param p_dossier dossier id
00192  * \param p_target ctrl to update
00193  * \param p_source ctrl containing the pa_id
00194  *
00195  *
00196  * \return
00197  */
00198 function search_ca(p_dossier, p_target, p_source)
00199 {
00200     var pa_id = g(p_source).value;
00201     waiting_box();
00202     removeDiv('search_anc');
00203     var qs = "op=openancsearch&gDossier=" + p_dossier + "&ctl=searchanc";
00204     qs += "&c2=" + pa_id + "&c1=" + p_target;
00205 
00206     var action = new Ajax.Request('ajax_misc.php',
00207             {
00208                 method: 'get',
00209                 parameters: qs,
00210                 onFailure: null,
00211                 onSuccess: function(req) {
00212                     try {
00213                         remove_waiting_box();
00214                         var pos = fixed_position(250, 150) + ";width:30%;height:50%";
00215                         add_div({
00216                             id: "searchanc",
00217                             drag: 1,
00218                             cssclass: "inner_box",
00219                             style: pos
00220                         });
00221                         $('searchanc').innerHTML = req.responseText;
00222 
00223                     } catch (e) {
00224                         alert(e.message);
00225                     }
00226                 }
00227             }
00228     );
00229 
00230 }
00231 function search_anc_form(obj)
00232 {
00233     var qs = "op=resultancsearch&ctl=searchanc&";
00234     var name = obj.id;
00235     qs += $(name).serialize(false);
00236     waiting_box();
00237     var action = new Ajax.Request('ajax_misc.php',
00238             {
00239                 method: 'get',
00240                 parameters: qs,
00241                 onFailure: null,
00242                 onSuccess: function(req) {
00243                     try {
00244                         remove_waiting_box();
00245                         $('searchanc').innerHTML = req.responseText;
00246                         req.responseText.evalScripts();
00247 
00248                     } catch (e) {
00249                         alert(e.message);
00250                     }
00251                 }
00252             }
00253     );
00254     return false;
00255 }
00256 function caod_checkTotal()
00257 {
00258     var ie4 = false;
00259     if (document.all)
00260     {
00261         ie4 = true;
00262     }// Ajouter getElementById par document.all[str]
00263     var total_deb = 0.0;
00264     var total_cred = 0.0;
00265     var nb_item = g('nbrow').value;
00266 
00267     for (var i = 0; i < nb_item; i++)
00268     {
00269         var doc_amount = g("pamount" + i);
00270         if (!doc_amount)
00271         {
00272             return;
00273         }
00274         var side = g("pdeb" + i);
00275         if (!side)
00276         {
00277             return;
00278         }
00279         var amount = parseFloat(doc_amount.value);
00280 
00281         if (isNaN(amount) == true)
00282         {
00283             amount = 0.0;
00284         }
00285         if (side.checked == false)
00286         {
00287             total_cred += amount;
00288         }
00289         if (side.checked == true)
00290         {
00291             total_deb += amount;
00292         }
00293     }
00294 
00295 
00296 
00297     var r_total_cred = Math.round(total_cred * 100) / 100;
00298     var r_total_deb = Math.round(total_deb * 100) / 100;
00299     g('totalDeb').innerHTML = r_total_deb;
00300     g('totalCred').innerHTML = r_total_cred;
00301 
00302     if (r_total_deb != r_total_cred)
00303     {
00304         g("totalDiff").style.color = "red";
00305         g("totalDiff").style.fontWeight = "bold";
00306         g("totalDiff").innerHTML = "Différence";
00307         var diff = total_deb - total_cred;
00308         diff = Math.round(diff * 100) / 100;
00309         g("totalDiff").innerHTML = diff;
00310 
00311     }
00312     else
00313     {
00314         g("totalDiff").innerHTML = "0.0";
00315     }
00316 }
00317 
00318 /**
00319  *@brief remove an operation
00320  *@param p_dossier is the folder
00321  *@param p_oa_group is the group of the analytic operation
00322  */
00323 function anc_remove_operation(p_dossier, p_oa_group)
00324 {
00325     var a = confirm("Etes-vous sur de vouloir effacer cette operation ?\n");
00326     if (a == false)
00327         return;
00328     var obj = {"oa":
00329                 p_oa_group, "gDossier":
00330                 p_dossier, "op": "remove_anc"};
00331     var queryString = encodeJSON(obj);
00332     g(p_oa_group).style.display = 'none';
00333     var e = new Ajax.Request("ajax_misc.php",
00334             {method: 'get', parameters: queryString});
00335 
00336 }
00337 /**
00338  * add a row in misc operation for ANC
00339  * the code must be adapted for that
00340  */
00341 function anc_add_row(tableid)
00342 {
00343     var style = 'class="input_text"';
00344     var mytable = g(tableid).tBodies[0];
00345     var nNumberRow = mytable.rows.length;
00346     var oRow = mytable.insertRow(nNumberRow);
00347     var rowToCopy = mytable.rows[1];
00348     var nNumberCell = rowToCopy.cells.length;
00349     var nb = g("nbrow");
00350     var oNewRow = mytable.insertRow(nNumberRow);
00351     for (var e = 0; e < nNumberCell; e++)
00352     {
00353         var newCell = oRow.insertCell(e);
00354         var tt = rowToCopy.cells[e].innerHTML;
00355         var new_tt = tt.replace(/pop0/g, "pop" + nb.value);
00356         new_tt = new_tt.replace(/pamount0/g, "pamount" + nb.value);
00357         new_tt = new_tt.replace(/pdeb0/g, "pdeb" + nb.value);
00358         newCell.innerHTML = new_tt;
00359         new_tt.evalScripts();
00360     }
00361     $("pamount" + nb.value).value = "0";
00362     nb.value++;
00363 }
00364 /**
00365  *@brief this function is called before the querystring is send to the
00366  * fid2.php, add a filter based on the ledger 'p_jrn'
00367  *@param obj is the input field
00368  *@param queryString is the queryString to modify
00369  *@see ICard::input
00370  */
00371 function filter_anc(obj, queryString)
00372 {
00373     var pa_id = obj.plan_ctl;
00374     queryString = queryString + "&pa_id=" + pa_id;
00375     return queryString;
00376 }
00377 /**
00378  * @brief compute and display Analytic activity, related to the choosen distribution key
00379  * @param p_dossier is the dossier id
00380  * @param p_table is table id to replace
00381  * @param p_amount is the amount to distribute
00382  * @param p_key_id is the choosen key
00383  * 
00384  */
00385 function anc_key_compute(p_dossier, p_table, p_amount, p_key_id)
00386 {
00387     waiting_box();
00388     var op = "op=anc_key_compute";
00389     var queryString = op + "&gDossier=" + p_dossier + "&t=" + p_table + "&amount=" + p_amount + '&key=' + p_key_id;
00390     try {
00391         var action = new Ajax.Request(
00392                 "ajax_misc.php",
00393                 {
00394                     method: 'get',
00395                     parameters: queryString,
00396                     onFailure: error_box,
00397                     onSuccess: function(req, json) {
00398                         try
00399                         {
00400                             var name_ctl = p_table;
00401                             var answer = req.responseXML;
00402                             remove_waiting_box();
00403                             var html = answer.getElementsByTagName('code');
00404                             if (html.length == 0) {
00405                                 var rec = req.responseText;
00406                                 alert('erreur :' + rec);
00407                             }
00408 
00409                             var code_html = getNodeText(html[0]); // Firefox ne prend que les 4096 car.
00410                             code_html = unescape_xml(code_html);
00411                             $(name_ctl).innerHTML = code_html;
00412                             removeDiv('div_anc_key_choice');
00413                         } catch (e)
00414                         {
00415                             error_message(e.message);
00416                         }
00417                     }
00418                 }
00419 
00420         );
00421     } catch (e) {
00422         error_message(e.message);
00423     }
00424 }
00425 /**
00426  * @brief choose the distribution key
00427  * in ajax, a window let you choose what key you want to use
00428  * 
00429  * @param p_dossier is the dossier
00430  * @param p_table the table id of the target
00431  * @param p_amount amount to distribute
00432  * @param p_ledger
00433  */
00434 function anc_key_choice(p_dossier, p_table, p_amount,p_ledger)
00435 {
00436     waiting_box();
00437     var op = 'op=anc_key_choice';
00438     var queryString = op + "&gDossier=" + p_dossier + "&t=" + p_table + "&amount=" + p_amount;
00439     try {
00440         queryString+='&led='+p_ledger;
00441         var action = new Ajax.Request(
00442                 "ajax_misc.php",
00443                 {
00444                     method: 'get',
00445                     parameters: queryString,
00446                     onFailure: error_box,
00447                     onSuccess: function(req, json) {
00448                         try
00449                         {
00450                             var name_ctl = 'div_anc_key_choice';
00451                             var answer = req.responseXML;
00452                             remove_waiting_box();
00453                             var html = answer.getElementsByTagName('code');
00454                             if (html.length == 0) {
00455                                 var rec = req.responseText;
00456                                 alert('erreur :' + rec);
00457                             }
00458 
00459                             var code_html = getNodeText(html[0]); // Firefox ne prend que les 4096 car.
00460                             code_html = unescape_xml(code_html);
00461                             var position=fixed_position(50,120);
00462                             add_div({id: name_ctl, cssclass: 'inner_box', style: position, drag: 1});
00463                             $(name_ctl).innerHTML = code_html;
00464                         } catch (e)
00465                         {
00466                             error_message(e.message);
00467                         }
00468                     }
00469                 }
00470 
00471         );
00472 
00473     } catch (e) {
00474         error_message(e.message);
00475     }
00476 }
00477 /**
00478  * Add a row for distribution key.
00479  * This function add a row in the table key distribution
00480  * @param p_table table id
00481  */
00482 function add_row_key(p_table)
00483 {
00484     var mytable = g(p_table).tBodies[0];
00485     if (!mytable)
00486     {
00487         return;
00488     }
00489     var table_length=mytable.rows.length ;
00490     if ( table_length > 15)
00491     {
00492         alert("Maximum 15 lignes ");
00493         return;
00494     }
00495     var rowToCopy = mytable.rows[1];
00496     var row = mytable.insertRow(table_length);
00497     var nb=mytable.rows.length -2;
00498     for (var i = 0; i < rowToCopy.cells.length; i++)
00499     {
00500         var cell = row.insertCell(i);
00501         cell.className=rowToCopy.cells[i].className;
00502         var txt = rowToCopy.cells[i].innerHTML;
00503         if (  i == 0 )
00504         {
00505             var change=nb+1;
00506             cell.innerHTML =change+'<input id="row[]" type="hidden" value="-1" name="row[]">';
00507         } 
00508         else
00509         {
00510             if (i == rowToCopy.cells.length -1 )  {
00511                 txt=txt.replace(/value="[0-9]*.{1}[0-9]*"/,'value="0"')
00512             } else {
00513                 txt=txt.replace(/po_id\[0\]/g,'po_id['+nb+']');
00514             }
00515            cell.innerHTML = txt;
00516         }
00517     }
00518     $('total_key').innerHTML="?";
00519 }
00520 function anc_key_compute_table()
00521 {
00522     var tot=0;
00523     var i=0;
00524     var value=0;
00525     var percent=document.getElementsByName('percent[]');
00526     for (i=0;i<percent.length;i++)
00527     {
00528         value=percent[i].value;
00529         if ( value == 'undefined')
00530         {
00531             value=0;
00532         }
00533         if ( isNaN(value)) {
00534             value=0;
00535         }
00536         tot=tot+Math.round(value*100)/100;
00537     }
00538     $('total_key').innerHTML=Math.round(tot*100)/100;
00539 
00540 }
 All Data Structures Namespaces Files Functions Variables Enumerations