noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
acc_ledger.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 /*!\file
00023  * \brief javascript script for the ledger in accountancy,
00024  * compute the sum, add a row at the table..
00025  *
00026  */
00027 var layer=1;
00028 /**
00029 * @brief update the list of available predefined operation when we change the ledger.
00030 */
00031 function update_predef(p_type,p_direct,p_ac)
00032 {
00033     var jrn=g("p_jrn").value;
00034     var dossier=g("gDossier").value;
00035     var querystring='gDossier='+dossier+'&l='+jrn+'&t='+p_type+'&d='+p_direct+"&op=up_predef&ac="+p_ac;
00036     g("p_jrn_predef").value=jrn;
00037     var action = new Ajax.Request(
00038             "ajax_misc.php",
00039             {
00040                 method: 'get',
00041                 parameters: querystring,
00042                 onFailure: error_get_predef,
00043                 onSuccess: function(req) {
00044                     try {
00045                         $('info_div').innerHTML = "ok";
00046                         var answer = req.responseXML;
00047                         var a = answer.getElementsByTagName('code');
00048                         var html = answer.getElementsByTagName('value');
00049                         if (a.length == 0)
00050                         {
00051                             var rec = req.responseText;
00052                             alert('erreur :' + rec);
00053                         }
00054                         var code_html = getNodeText(html[0]);
00055                         code_html = unescape_xml(code_html);
00056                         // document.getElementsByName(name_ctl)[0].value = code_html;
00057                         $('modele_op_div').innerHTML=code_html;
00058                     } catch (e) {
00059                         $('info_div').innerHTML = e.getMessage;
00060                     }
00061                 }
00062             }
00063     );
00064 }
00065 
00066 /**
00067 * @brief update the list of payment method when we change the ledger.
00068 */
00069 function update_pay_method()
00070 {
00071     waiting_box();
00072     var jrn=g("p_jrn").value;
00073     var dossier=g("gDossier").value;
00074     var querystring='gDossier='+dossier+'&l='+jrn+"&op=up_pay_method";
00075     var action=new Ajax.Request(
00076         "ajax_misc.php",
00077         {
00078             method:'get',
00079             parameters:querystring,
00080             onFailure:error_get_predef,
00081             onSuccess:function(req){
00082                 remove_waiting_box();
00083                 var answer=req.responseText;
00084                 $('payment').innerHTML=answer;
00085             }
00086         }
00087         );
00088 }
00089 
00090 /**
00091  *@brief update ctl id =jrn_name with the value of p_jrn
00092  */
00093 function update_name()
00094 {
00095     var jrn_id=$('p_jrn').value;
00096     var dossier=g("gDossier").value;
00097     var querystring='gDossier='+dossier+'&l='+jrn_id+"&op=ledger_description";
00098     var action=new Ajax.Request(
00099                    "ajax_misc.php",
00100                    {
00101                    method:'get',
00102                    parameters:querystring,
00103                    onFailure:error_get_pj,
00104                    onSuccess:function (req){
00105                        $('jrn_name_div').innerHTML=req.responseText;
00106                    }
00107                    }
00108                );
00109     
00110 }
00111 /**
00112  * @brief update the field predef
00113  */
00114 function error_get_predef(request,json)
00115 {
00116     alert ("Erreur mise à jour champs non possible");
00117 
00118 }
00119 /**
00120 * @brief update the list of available predefined operation when we change the ledger.
00121 */
00122 function update_pj()
00123 {
00124     var jrn=g("p_jrn").value;
00125     var dossier=g("gDossier").value;
00126     var querystring='gDossier='+dossier+'&l='+jrn+"&op=upd_receipt";
00127     var action=new Ajax.Request(
00128                    "ajax_misc.php",
00129                    {
00130                    method:'get',
00131                    parameters:querystring,
00132                    onFailure:error_get_pj,
00133                    onSuccess:success_get_pj
00134                    }
00135                );
00136 }
00137 /**
00138  *ask the name, quick_code of the bank for the ledger
00139  */
00140 function update_bank()
00141 {
00142     var jrn=g('p_jrn').value;
00143     var dossier=g('gDossier').value;
00144     var qs='gDossier='+dossier+'&op=bkname&p_jrn='+jrn;
00145     var action=new Ajax.Request(
00146                    "ajax_misc.php",
00147                    {
00148                    method:'get',
00149                    parameters:qs,
00150                    onFailure:error_get_pj,
00151                    onSuccess:success_update_bank
00152                    }
00153                );
00154 
00155 }
00156 /**
00157  * Update the number of rows when changing of ledger
00158  */
00159 function update_row(ctl)
00160 {
00161         try
00162         {
00163     var jrn=g('p_jrn').value;
00164     var dossier=g('gDossier').value;
00165     var qs='gDossier='+dossier+'&op=minrow&j='+jrn+'&ctl='+ctl;
00166     var action=new Ajax.Request(
00167                    "ajax_misc.php",
00168                    {
00169                    method:'get',
00170                    parameters:qs,
00171                    onFailure:null,
00172                    onSuccess:function(request,json)
00173                                                 {
00174                                                         try {
00175                                                                 var answer=request.responseText.evalJSON(true);
00176                                                                 var row=parseFloat(answer.row);
00177                                                                 var current_row=parseFloat($('nb_item').value);
00178                                                                 if ( current_row > row ) {
00179                                                                         // Too many row
00180                                                                         var delta=$('nb_item').value-row;
00181                                                                         var idx=$('nb_item').value;
00182                                                                         for (var i=0;i<delta;i++){
00183                                                                                 $(ctl).deleteRow(-1);
00184                                                                                 idx--;
00185                                                                         }
00186                                                                         $('nb_item').value=row;
00187                                                                 }
00188                                                                 if (current_row < row) {
00189                                                                         // We need to add rows
00190                                                                                 var delta=row-current_row;
00191                                                                                 for (var i =0;i<delta;i++) {
00192                                                                                         if ( ctl=='fin_item') {
00193                                                                                                 ledger_fin_add_row();
00194                                                                                         }
00195                                                                                         if ( ctl=='sold_item'){
00196                                                                                                 ledger_add_row();
00197                                                                                         }
00198                                                                                         if (ctl=='quick_item'){
00199                                                                                                 quick_writing_add_row();
00200                                                                                         }
00201                                                                                 }
00202                                                                         }
00203                                                         }catch (e) { alert(e.getMessage);}
00204                                                 }
00205                                         }
00206                );
00207         } catch (e) {
00208                 alert(e.getMessage);
00209         }
00210 }
00211 /**
00212  * Put into the span, the name of the bank, the bank account
00213  * and the quick_code
00214  */
00215 function success_update_bank(req)
00216 {
00217     try
00218     {
00219         var answer=req.responseXML;
00220         var a=answer.getElementsByTagName('code');
00221         var html=answer.getElementsByTagName('value');
00222         if ( a.length == 0 )
00223         {
00224             var rec=req.responseText;
00225             alert ('erreur :'+rec);
00226         }
00227         var name_ctl=a[0].firstChild.nodeValue;
00228         var code_html=getNodeText(html[0]);
00229         code_html=unescape_xml(code_html);
00230         $(name_ctl).innerHTML=code_html;
00231     }
00232     catch (e)
00233     {
00234         alert("success_update_bank"+e.message);
00235     }
00236 }
00237 /**
00238  * call ajax, ask what is the last date for the current ledger
00239  */
00240 function get_last_date()
00241 {
00242     var jrn=g('p_jrn').value;
00243     var dossier=g('gDossier').value;
00244     var qs='gDossier='+dossier+'&op=lastdate&p_jrn='+jrn;
00245     var action=new Ajax.Request(
00246                    "ajax_misc.php",
00247                    {
00248                    method:'get',
00249                    parameters:qs,
00250                    onFailure:error_get_pj,
00251                    onSuccess:success_get_last_date
00252                    }
00253                );
00254 }
00255 /**
00256  * callback ajax, set the ctl with the last date from the ledger
00257  */
00258 function success_get_last_date(req)
00259 {
00260     try
00261     {
00262         var answer=req.responseXML;
00263         var a=answer.getElementsByTagName('code');
00264         var html=answer.getElementsByTagName('value');
00265         if ( a.length == 0 )
00266         {
00267             var rec=req.responseText;
00268             alert ('erreur :'+rec);
00269         }
00270         var name_ctl=a[0].firstChild.nodeValue;
00271         var code_html=getNodeText(html[0]);
00272         code_html=unescape_xml(code_html);
00273         document.getElementsByName(name_ctl)[0].value=code_html;
00274     }
00275     catch (e)
00276     {
00277         alert(e.message);
00278     }
00279 }
00280 /**
00281  * @brief update the field predef
00282  */
00283 function success_get_pj(request,json)
00284 {
00285 
00286     var answer=request.responseText.evalJSON(true);
00287     obj=g("e_pj");
00288     obj.value='';
00289     if ( answer.count == 0 ) return;
00290     obj.value=answer.pj;
00291     g("e_pj_suggest").value=answer.pj;
00292 }
00293 /**
00294  * @brief update the field predef
00295  */
00296 function error_get_pj(request,json)
00297 {
00298     alert("Ajax a echoue");
00299 }
00300 
00301 /**
00302  * @brief add a line in the form for the ledger fin
00303  */
00304 function ledger_fin_add_row()
00305 {
00306     var style='class="input_text"';
00307     var mytable=g("fin_item").tBodies[0];
00308     var line=mytable.rows.length;
00309     var row=mytable.insertRow(line);
00310     var nb=g("nb_item");
00311     var rowToCopy=mytable.rows[1];
00312     var nNumberCell=rowToCopy.cells.length;
00313     for ( var e=0;e < nNumberCell;e++)
00314     {
00315         var newCell=row.insertCell(e);
00316                 if ( e==0) {
00317                         newCell.id='tdchdate'+nb.value;
00318                 }
00319         var tt=rowToCopy.cells[e].innerHTML;
00320         var new_tt=tt.replace(/e_other0/g,"e_other"+nb.value);
00321         new_tt=new_tt.replace(/e_other0_comment/g,"e_other"+nb.value+'_comment');
00322         new_tt=new_tt.replace(/e_other_name0/g,"e_other_name"+nb.value);
00323         new_tt=new_tt.replace(/e_other0_amount/g,"e_other"+nb.value+'_amount');
00324         new_tt=new_tt.replace(/e_concerned0/g,"e_concerned"+nb.value);
00325         new_tt=new_tt.replace(/e_other0_label/g,"e_other"+nb.value+'_label');
00326         new_tt=new_tt.replace(/dateop0/g,"dateop"+nb.value);
00327         newCell.innerHTML=new_tt;
00328         new_tt.evalScripts();
00329     }
00330     g("e_other"+nb.value).value="";
00331     g("e_other_name"+nb.value).value="";
00332     g("e_other"+nb.value+'_amount').value="0";
00333     g("e_other"+nb.value+'_comment').value="";
00334     g("e_concerned"+nb.value).value="";
00335 
00336         var ch=$('chdate').options[$('chdate').selectedIndex].value;
00337         if (ch == 1 ) {
00338                         $('tdchdate'+nb.value).hide();
00339         }
00340         nb.value++;
00341 }
00342 
00343 /**
00344  * @brief add a line in the form for the purchase ledger
00345  * @param p_dossier folder id
00346  * @param p_table_name
00347  */
00348 function ledger_add_row()
00349 {
00350     try{
00351     style='class="input_text"';
00352     var mytable=g("sold_item").tBodies[0];
00353     var ofirstRow=mytable.rows[1];
00354     var line=mytable.rows.length;
00355     var nCell=mytable.rows[1].cells.length;
00356     var row=mytable.insertRow(line);
00357     var nb=g("nb_item");
00358     for (var e=0;e<nCell;e++)
00359     {
00360         var newCell=row.insertCell(e);
00361         var tt=ofirstRow.cells[e].innerHTML;
00362         var new_tt=tt.replace(/march0/g,"march"+nb.value);
00363         new_tt=new_tt.replace(/quant0/g,"quant"+nb.value);
00364         new_tt=new_tt.replace(/sold\(0\)/g,"sold("+nb.value+")");
00365         new_tt=new_tt.replace(/compute_ledger\(0\)/g,"compute_ledger("+nb.value+")");
00366         new_tt=new_tt.replace(/clean_tva\(0\)/g,"clean_tva("+nb.value+")");
00367         newCell.innerHTML=new_tt;
00368         new_tt.evalScripts();
00369     }
00370 
00371     $("e_march"+nb.value+"_label").innerHTML='';
00372     $("e_march"+nb.value+"_label").value='';
00373     $("e_march"+nb.value+"_price").value='0';
00374     $("e_march"+nb.value).value="";
00375     $("e_quant"+nb.value).value="1";
00376     if ($("e_march"+nb.value+"_tva_amount")) $("e_march"+nb.value+"_tva_amount").value=0;
00377 
00378     nb.value++;
00379 
00380     new_tt.evalScripts();
00381         } catch(e) {alert(e.message);}
00382 }
00383 /**
00384  * @brief compute the sum of a purchase, update the span tvac, htva and tva
00385  * all the needed data are taken from the document (hidden field :  gdossier)
00386  * @param the number of the changed ctrl
00387  */
00388 function compute_ledger(p_ctl_nb)
00389 {
00390     var dossier=g("gDossier").value;
00391     var a=-1;
00392     if ( document.getElementById("e_march"+p_ctl_nb+'_tva_amount'))
00393     {
00394         a=trim(g("e_march"+p_ctl_nb+'_tva_amount').value);
00395         g("e_march"+p_ctl_nb+'_tva_amount').value=a;
00396     }
00397         if ( ! document.getElementById("e_march"+p_ctl_nb))  {return;}
00398     g("e_march"+p_ctl_nb).value=trim(g("e_march"+p_ctl_nb).value);
00399     var qcode=g("e_march"+p_ctl_nb).value;
00400 
00401     if ( qcode.length == 0 )
00402     {
00403         clean_ledger(p_ctl_nb);
00404         refresh_ledger();
00405         return;
00406     }
00407     /*
00408      * if tva_id is empty send a value of -1
00409      */
00410     var tva_id=-1;
00411     if ( g('e_march'+p_ctl_nb+'_tva_id') )
00412     {
00413         tva_id=g('e_march'+p_ctl_nb+'_tva_id').value;
00414         if ( trim(tva_id) == '')
00415         {
00416             tva_id=-1;
00417         }
00418     }
00419 
00420     g('e_march'+p_ctl_nb+'_price').value=trim(g('e_march'+p_ctl_nb+'_price').value);
00421     var price=g('e_march'+p_ctl_nb+'_price').value;
00422 
00423     g('e_quant'+p_ctl_nb).value=trim(g('e_quant'+p_ctl_nb).value);
00424     var quantity=g('e_quant'+p_ctl_nb).value;
00425     var querystring='gDossier='+dossier+'&c='+qcode+'&t='+tva_id+'&p='+price+'&q='+quantity+'&n='+p_ctl_nb;
00426     $('sum').hide();
00427     var action=new Ajax.Request(
00428                    "compute.php",
00429                    {
00430                    method:'get',
00431                    parameters:querystring,
00432                    onFailure:error_compute_ledger,
00433                    onSuccess:success_compute_ledger
00434                    }
00435                );
00436 }
00437 /**
00438 *@brief refresh the purchase screen, recompute vat, total...
00439 */
00440 function refresh_ledger()
00441 {
00442     var tva=0;
00443     var htva=0;
00444     var tvac=0;
00445 
00446     for (var i=0;i<g("nb_item").value;i++)
00447     {
00448         if( g('tva_march'+i))  tva+=g('tva_march'+i).value*1;
00449         if (g('htva_march'+i)) htva+=g('htva_march'+i).value*1;
00450         if (g('tvac_march'+i)) tvac+=g('tvac_march'+i).value*1;
00451     }
00452 
00453     if ( g('tva') ) g('tva').innerHTML=Math.round(tva*100)/100;
00454     if (g('htva')) g('htva').innerHTML=Math.round(htva*100)/100;
00455     if (g('tvac'))    g('tvac').innerHTML=Math.round(tvac*100)/100;
00456 }
00457 /**
00458  *@brief update the field htva, tva_id and tvac, callback function for  compute_sold
00459  * it the field TVA in the answer contains NA it means that VAT is appliable and then do not
00460  * update the VAT field except htva_martc
00461  */
00462 function success_compute_ledger(request,json)
00463 {
00464     var answer=request.responseText.evalJSON(true);
00465     var ctl=answer.ctl;
00466     var rtva=answer.tva;
00467     var rhtva=answer.htva;
00468     var rtvac=answer.tvac;
00469 
00470     if ( rtva == 'NA' )
00471     {
00472         var rhtva=answer.htva*1;
00473         g('htva_march'+ctl).value=rhtva;
00474         g('tvac_march'+ctl).value=rtvac;
00475         g('sum').show();
00476         refresh_ledger();
00477 
00478         return;
00479     }
00480     rtva=answer.tva*1;
00481 
00482 
00483 
00484     g('sum').show();
00485     if ( g('e_march'+ctl+'_tva_amount').value=="" ||  g('e_march'+ctl+'_tva_amount').value==0 )
00486     {
00487         g('tva_march'+ctl).value=rtva;
00488         g('e_march'+ctl+'_tva_amount').value=rtva;
00489     }
00490     else
00491     {
00492         g('tva_march'+ctl).value=g('e_march'+ctl+'_tva_amount').value;
00493     }
00494     g('htva_march'+ctl).value=Math.round(parseFloat(rhtva)*100)/100;
00495     var tmp1=Math.round(parseFloat(g('htva_march'+ctl).value)*100)/100;
00496     var tmp2=Math.round(parseFloat(g('tva_march'+ctl).value)*100)/100;
00497     g('tvac_march'+ctl).value=Math.round((tmp1+tmp2)*100)/100;
00498 
00499     refresh_ledger();
00500 }
00501 
00502 /**
00503  * @brief callback error function for  compute_sold
00504  */
00505 function error_compute_ledger(request,json)
00506 {
00507     alert('Ajax does not work');
00508 }
00509 function compute_all_ledger()
00510 {
00511     var loop=0;
00512     for (loop=0;loop<g("nb_item").value;loop++)
00513     {
00514         compute_ledger(loop);
00515     }
00516     var tva=0;
00517     var htva=0;
00518     var tvac=0;
00519 
00520     for (var i=0;i<g("nb_item").value;i++)
00521     {
00522         if ( g('tva_march') ) tva+=g('tva_march'+i).value*1;
00523         if( g('htva_march'+i)) htva+=g('htva_march'+i).value*1;
00524         if( g('tvac_march'+i))tvac+=g('tvac_march'+i).value*1;
00525     }
00526 
00527     if ( g('tva') ) g('tva').innerHTML=Math.round(tva*100)/100;
00528     if (g('htva')) g('htva').innerHTML=Math.round(htva*100)/100;
00529     if (g('tvac'))g('tvac').innerHTML=Math.round(tvac*100)/100;
00530 
00531 
00532 }
00533 
00534 function clean_tva(p_ctl)
00535 {
00536     if ( g('e_march'+p_ctl+'_tva_amount') )g('e_march'+p_ctl+'_tva_amount').value=0;
00537 }
00538 
00539 function clean_ledger( p_ctl_nb)
00540 {
00541     if ( g("e_march"+p_ctl_nb) )
00542     {
00543         g("e_march"+p_ctl_nb).value=trim(g("e_march"+p_ctl_nb).value);
00544     }
00545     if (g('e_march'+p_ctl_nb+'_price'))
00546     {
00547         g('e_march'+p_ctl_nb+'_price').value='';
00548     }
00549     if ( g('e_quant'+p_ctl_nb))
00550     {
00551         g('e_quant'+p_ctl_nb).value='1';
00552     }
00553     if ( g('tva_march'+p_ctl_nb+'_show') )
00554     {
00555         g('tva_march'+p_ctl_nb+'_show').value='0';
00556     }
00557     if (g('tva_march'+p_ctl_nb))
00558     {
00559         g('tva_march'+p_ctl_nb).value=0;
00560     }
00561     if ( g('htva_march'+p_ctl_nb))
00562     {
00563         g('htva_march'+p_ctl_nb).value=0;
00564     }
00565     if ( g('tvac_march'+p_ctl_nb))
00566     {
00567         g('tvac_march'+p_ctl_nb).value=0;
00568     }
00569 
00570 }
00571 /**
00572  * @brief add a line in the form for the quick_writing
00573  */
00574 function quick_writing_add_row()
00575 {
00576     style='class="input_text"';
00577     var mytable=g("quick_item").tBodies[0];
00578     var nNumberRow=mytable.rows.length;
00579     var oRow=mytable.insertRow(nNumberRow);
00580     var rowToCopy=mytable.rows[1];
00581     var nNumberCell=rowToCopy.cells.length;
00582     var nb=g("nb_item");
00583 
00584     var oNewRow = mytable.insertRow(nNumberRow);
00585     for ( var e=0;e < nNumberCell;e++)
00586     {
00587         var newCell=oRow.insertCell(e);
00588         var tt=rowToCopy.cells[e].innerHTML;
00589         new_tt=tt.replace(/qc_0/g,"qc_"+nb.value);
00590         new_tt=new_tt.replace(/amount0/g,"amount"+nb.value);
00591         new_tt=new_tt.replace(/poste0/g,"poste"+nb.value);
00592         new_tt=new_tt.replace(/ck0/g,"ck"+nb.value);
00593         new_tt=new_tt.replace(/ld0/g,"ld"+nb.value);
00594         newCell.innerHTML=new_tt;
00595         new_tt.evalScripts();
00596     }
00597     $("qc_"+nb.value).value="";
00598     $("amount"+nb.value).value="";
00599     $("poste"+nb.value).value="";
00600     $("ld"+nb.value).value="";
00601 
00602 
00603 
00604     nb.value++;
00605 
00606 }
00607 function RefreshMe()
00608 {
00609     window.location.reload();
00610 }
00611 
00612 
00613 function go_next_concerned()
00614 {
00615     var form=document.forms[1];
00616 
00617     for (var e=0;e<form.elements.length;e++)
00618     {
00619         var elmt=form.elements[e];
00620         if ( elmt.type == "checkbox")
00621         {
00622             if (elmt.checked==true )
00623             {
00624                 return confirm("Si vous changez de page vous perdez les reconciliations, continuez ?");
00625             }
00626         }
00627     }
00628     return true;
00629 }
00630 function view_history_account(p_value,dossier)
00631 {
00632     layer++;
00633     id='det'+layer;
00634     var popup={'id':  id,'cssclass':'inner_box','html':loading(),'drag':true};
00635 
00636     querystring='gDossier='+dossier+'&act=de&pcm_val='+p_value+'&div='+id+"&l="+layer;
00637     add_div(popup);
00638 
00639     var action=new Ajax.Request(
00640                    "ajax_history.php",
00641                    {
00642                    method:'get',
00643                    parameters:querystring,
00644                    onFailure:error_box,
00645                    onSuccess:function (req,xml)
00646                                         {
00647                                                 success_box(req,xml);
00648                                                 g(id).style.top=calcy(140+(layer*3))+"px";
00649                                         }
00650                    }
00651                );
00652 
00653 }
00654 
00655 function update_history_account(obj)
00656 {
00657     try{
00658         var querystring="l="+obj.div+"&div="+obj.div+"&gDossier="+obj.gDossier+"&pcm_val="+obj.pcm_val+"&ex="+obj.select.options[obj.select.selectedIndex].text;
00659         var action=new Ajax.Request(
00660             "ajax_history.php",
00661             {
00662                 method:'get',
00663                 parameters:querystring,
00664                 onFailure:error_box,
00665                   onSuccess:function (req,xml)
00666                                         {
00667                                                 success_box(req,xml);
00668                                                 g(obj.div).style.top=calcy(140+(layer*3))+"px";
00669                                         }
00670             });
00671     } catch (e)
00672     {
00673         alert("update_history_account error "+e.message);
00674     }
00675 
00676     return false;
00677 }
00678 /*!\brief
00679  * \param p_value f_id of the card
00680  */
00681 
00682 function view_history_card(p_value,dossier)
00683 {
00684     layer++;
00685     id='det'+layer;
00686 var popup={'id':
00687            id,'cssclass':'inner_box'
00688            ,'html':
00689            loading(),'drag':
00690                true};
00691     querystring='gDossier='+dossier+'&act=de&f_id='+p_value+'&div='+id+"&l="+layer;
00692     add_div(popup);
00693     var action=new Ajax.Request(
00694                    "ajax_history.php",
00695                    {
00696                    method:'get',
00697                    parameters:querystring,
00698                    onFailure:error_box,
00699                    onSuccess:function (req,xml)
00700                                         {
00701                                                 success_box(req,xml);
00702                                                 g(id).style.top=calcy(140+(layer*3))+"px";
00703                                         }
00704                    }
00705                );
00706 }
00707 
00708 function update_history_card(obj)
00709 {
00710     try{
00711         var querystring="l="+obj.div+"&div="+obj.div+"&gDossier="+obj.gDossier+"&f_id="+obj.f_id+"&ex="+obj.select.options[obj.select.selectedIndex].text;
00712         var action=new Ajax.Request(
00713             "ajax_history.php",
00714             {
00715                 method:'get',
00716                 parameters:querystring,
00717                 onFailure:error_box,
00718                   onSuccess:function (req,xml)
00719                                         {
00720                                                 success_box(req,xml);
00721                                                 g(obj.div).style.top=calcy(140+(layer*3))+"px";
00722                                         }
00723             });
00724     } catch (e)
00725     {
00726         alert("update_history_account error "+e.message);
00727     }
00728 
00729     return false;
00730 }
00731 /**
00732 * remove an Operation
00733 *@param p_jr_id is the jrn.jr_id
00734 *@param dossier
00735 *@param the div
00736 */
00737 function removeOperation(p_jr_id,dossier,div)
00738 {
00739     waiting_box();
00740     var qs="gDossier="+dossier+"&act=rmop&div="+div+"&jr_id="+p_jr_id;
00741     var action=new Ajax.Request(
00742                    "ajax_ledger.php",
00743                    {
00744                    method:'get',
00745                    parameters:qs,
00746                    onFailure:error_box,
00747                    onSuccess:infodiv
00748                    }
00749                );
00750 
00751 }
00752 
00753 /**
00754 * reverse an Operation
00755 *@param pointer to the FORM
00756 */
00757 function reverseOperation(obj)
00758 {
00759     var qs=$(obj).serialize();
00760     g('ext'+obj.divname).style.display='none';
00761     g('bext'+obj.divname).style.display='none';
00762     waiting_box();
00763     var action=new Ajax.Request(
00764                    "ajax_ledger.php",
00765                    {
00766                    method:'get',
00767                    parameters:qs,
00768                    onFailure:error_box,
00769                    onSuccess:infodiv
00770                    }
00771                );
00772 
00773     return false;
00774 }
00775 
00776 /*!\brief
00777  * \param p_value jrn.jr_id
00778  */
00779 function modifyOperation(p_value, dossier)
00780 {
00781         layer++;
00782         var id = 'det' + layer;
00783         waiting_box();
00784         var querystring = 'gDossier=' + dossier + '&act=de&jr_id=' + p_value + '&div=' + id;
00785 
00786         var action = new Ajax.Request(
00787                         "ajax_ledger.php",
00788                         {
00789                                 method: 'get',
00790                                 parameters: querystring,
00791                                 onFailure: error_box,
00792                                 onSuccess: function(xml, txt) {
00793                                         var popup = {'id':id, 'cssclass': 'inner_box'
00794                                                                 , 'html':"", 'drag':true};
00795                                         remove_waiting_box();
00796                                         add_div(popup);
00797                                         success_box(xml, txt);
00798                                         $(id).style.position="absolute";
00799                                         $(id).style.top = calcy(100 + (layer * 3))+"px";
00800                                 }
00801                         }
00802         );
00803 }
00804 
00805 /*!\brief
00806  * \param p_value jrn.jr_id
00807  */
00808 
00809 function viewOperation(p_value,p_dossier)
00810 {
00811     modifyOperation(p_value,p_dossier)
00812 }
00813 function dropLink(p_dossier,p_div,p_jr_id,p_jr_id2)
00814 {
00815     var querystring='gDossier='+p_dossier;
00816     querystring+='&div='+p_div;
00817     querystring+='&jr_id='+p_jr_id;
00818     querystring+='&act=rmr';
00819     querystring+='&jr_id2='+p_jr_id2;
00820     var action=new Ajax.Request ( 'ajax_ledger.php',
00821                                   {
00822                                   method:'get',
00823                                   parameters:querystring,
00824                                   onFailure:null,
00825                                   onSuccess:null
00826                                   }
00827                                 );
00828 }
00829 /**
00830  *@brief this function is called before the querystring is send to the
00831  * fid2.php, add a filter based on the ledger 'p_jrn'
00832  *@param obj is the input field
00833  *@param queryString is the queryString to modify
00834  *@see ICard::input
00835  */
00836 function filter_card(obj,queryString)
00837 {
00838     jrn=$('p_jrn').value;
00839     if ( jrn == -1 )
00840     {
00841         type=$('ledger_type').value;
00842         queryString=queryString+'&type='+type;
00843     }
00844     else
00845     {
00846         queryString=queryString+'&j='+jrn;
00847     }
00848     return queryString;
00849 }
00850 /**
00851  *@brief to display the lettering for the operation, call
00852  * ajax function
00853  *@param obj object attribut :  gDossier,j_id,obj_type
00854  */
00855 function dsp_letter(obj)
00856 {
00857     try
00858     {
00859         var queryString='gDossier='+obj.gDossier+'&j_id='+obj.j_id+'&op=dl'+'&ot='+obj.obj_type;
00860         var action=new Ajax.Request(
00861                        "ajax_misc.php",
00862                        {
00863                    method:'get',
00864                    parameters:queryString,
00865                    onFailure:error_dsp_letter,
00866                    onSuccess:success_dsp_letter
00867                        }
00868                    );
00869         g('search').style.display='none';
00870         g('list').style.display='none';
00871         $('detail').innerHTML=loading();
00872         g('detail').style.display='block';
00873     }
00874     catch(e)
00875     {
00876         alert('dsp_letter failed  '+e.message);
00877     }
00878 }
00879 
00880 function success_dsp_letter(req)
00881 {
00882     try
00883     {
00884         var answer=req.responseXML;
00885         var a=answer.getElementsByTagName('code');
00886         var html=answer.getElementsByTagName('value');
00887         if ( a.length == 0 )
00888         {
00889             var rec=req.responseText;
00890             alert ('erreur :'+rec);
00891         }
00892         var name_ctl=a[0].firstChild.nodeValue;
00893         var code_html=getNodeText(html[0]);
00894         code_html=unescape_xml(code_html);
00895         $('detail').innerHTML=code_html;
00896     }
00897     catch (e)
00898     {
00899         alert(e.message);
00900     }
00901     try
00902     {
00903         code_html.evalScripts();
00904     }
00905     catch(e)
00906     {
00907         alert("Impossible executer script de la reponse\n"+e.message);
00908     }
00909 
00910 }
00911 function error_dsp_letter(req)
00912 {
00913     alert('Erreur AJAX DSP_LETTER');
00914 }
00915 
00916 function search_letter(obj)
00917 {
00918     try
00919     {
00920         var str_query='';
00921         if (obj.elements['gDossier'] ) str_query='gDossier='+obj.elements['gDossier'].value;
00922         if (obj.elements['j_id'] ) str_query+='&j_id='+obj.elements['j_id'].value;
00923         if (obj.elements['ot'] ) str_query+='&ot='+obj.elements['ot'].value;
00924         if (obj.elements['op'] ) str_query+='&op='+obj.elements['op'].value;
00925         if (obj.elements['min_amount'] ) str_query+='&min_amount='+obj.elements['min_amount'].value;
00926         if (obj.elements['max_amount'] ) str_query+='&max_amount='+obj.elements['max_amount'].value;
00927         if (obj.elements['search_start'] ) str_query+='&search_start='+obj.elements['search_start'].value;
00928         if (obj.elements['search_end'] ) str_query+='&search_end='+obj.elements['search_end'].value;
00929         if (obj.elements['side'] ) str_query+='&side='+obj.elements['side'].value;
00930 
00931 
00932         var action=new Ajax.Request(
00933                        "ajax_misc.php",
00934                        {
00935                    method:'get',
00936                    parameters:str_query,
00937                    onFailure:error_dsp_letter,
00938                    onSuccess:success_dsp_letter
00939                        }
00940                    );
00941         $('list').hide();
00942         $('search').hide();
00943         $('detail').innerHTML=loading();
00944         $('detail').show();
00945     }
00946     catch(e)
00947     {
00948         alert('search_letter  '+e.message);
00949     }
00950 }
00951 /**
00952 *@brief save an operation in ajax, it concerns only the
00953 * comment, the pj and the rapt
00954 * the form elements are access by their name
00955 *@param obj form
00956 */
00957 function op_save(obj)
00958 {
00959         try {
00960     var queryString=$(obj).serialize();
00961     queryString+="&gDossier="+obj.gDossier.value;
00962     var rapt2="rapt"+obj.whatdiv.value;
00963     queryString+="&rapt="+g(rapt2).value;
00964     queryString+='&jr_id='+obj.jr_id.value;
00965     queryString+='&div='+obj.whatdiv.value;
00966     queryString+='&act=save';
00967     waiting_box();
00968     if ( g('inpopup'))
00969     {
00970         var action=new Ajax.Request ( 'ajax_ledger.php',
00971                                       {
00972                                   method:'post',
00973                                   parameters:queryString,
00974                                   onFailure:null,
00975                                   onSuccess:infodiv
00976                                       }
00977                                     );
00978        // window.close();
00979     }
00980     else
00981     {
00982         var action=new Ajax.Request ( 'ajax_ledger.php',
00983                                       {
00984                                   method:'post',
00985                                   parameters:queryString,
00986                                   onFailure:null,
00987                                   onSuccess:infodiv
00988                                                }
00989                             );
00990     }
00991     return false;
00992         } catch (e)
00993         { alert(e.message);}
00994 }
00995 function  get_history_account(ctl,dossier) {
00996         if ( $(ctl).value != '')
00997                 {
00998                         view_history_account($(ctl).value, dossier);
00999                 }
01000 }
01001 var previous=[];
01002 function show_reconcile(p_div,p_let)
01003 {
01004         try
01005         {
01006                 if (previous.length != 0)
01007                         {
01008                                 var count_elt=previous.length;
01009                                 var i=0;
01010                                 for (i=0;i<count_elt;i++){
01011                                         previous[i].style.backgroundColor='';
01012                                         previous[i].style.color='';
01013                                         previous[i].style.fontWeight="";
01014                                 }
01015                         }
01016                 var name='tr_'+p_let+'_'+p_div;
01017                 var elt=document.getElementsByName(name);
01018                 previous=elt;
01019                 var count_elt=elt.length;
01020                 var i=0;
01021                 for (i=0;i<count_elt;i++){
01022                         elt[i].style.backgroundColor='#000066';
01023                         elt[i].style.color='white';
01024                         elt[i].style.fontWeight='bolder';
01025 
01026                 }
01027 
01028         } catch (e)
01029         {
01030                 alert(e.message);
01031         }
01032 
01033 
01034 }
01035 /**
01036  * @brief add a line in the form for the purchase ledger
01037  */
01038 function gestion_add_row()
01039 {
01040     try {
01041         style = 'class="input_text"';
01042         var mytable = g("art").tBodies[0];
01043         var ofirstRow = mytable.rows[1];
01044         var line = mytable.rows.length;
01045         var nCell = mytable.rows[1].cells.length;
01046         var row = mytable.insertRow(line);
01047         var nb = g("nb_item");
01048         for (var e = 0; e < nCell; e++)
01049         {
01050             var newCell = row.insertCell(e);
01051             var tt = ofirstRow.cells[e].innerHTML;
01052             var new_tt = tt.replace(/march0/g, "march" + nb.value);
01053             new_tt = new_tt.replace(/quant0/g, "quant" + nb.value);
01054             new_tt = new_tt.replace(/sold\(0\)/g, "sold(" + nb.value + ")");
01055             new_tt = new_tt.replace(/compute_ledger\(0\)/g, "compute_ledger(" + nb.value + ")");
01056             new_tt = new_tt.replace(/clean_tva\(0\)/g, "clean_tva(" + nb.value + ")");
01057             new_tt = new_tt + '<input type="hidden" id="tva_march'+nb.value+'">';
01058                new_tt = new_tt + '<input type="hidden" id="htva_march'+nb.value+'">';
01059             newCell.innerHTML = new_tt;
01060             if ( mytable.rows[1].cells[e].hasClassName("num") ) {
01061                 newCell.addClassName("num");
01062             }
01063             new_tt.evalScripts();
01064         }
01065 
01066         g("e_march" + nb.value + "_label").innerHTML = '&nbsp;';
01067         g("e_march" + nb.value + "_label").value = '';
01068         g("e_march" + nb.value + "_price").value = '0';
01069         g("e_march" + nb.value).value = "";
01070         g("e_quant" + nb.value).value = "1";
01071         g('tvac_march'+nb.value).value="0";
01072         if ($("e_march" + nb.value + "_tva_amount"))
01073             g("e_march" + nb.value + "_tva_amount").value = 0;
01074 
01075         nb.value++;
01076 
01077         new_tt.evalScripts();
01078     } catch (e) {
01079         alert(e.message);
01080     }
01081 
01082 }
 All Data Structures Namespaces Files Functions Variables Enumerations