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  */
00346 function ledger_add_row()
00347 {
00348         try{
00349     style='class="input_text"';
00350     var mytable=g("sold_item").tBodies[0];
00351     var ofirstRow=mytable.rows[1];
00352     var line=mytable.rows.length;
00353     var nCell=mytable.rows[1].cells.length;
00354     var row=mytable.insertRow(line);
00355     var nb=g("nb_item");
00356     for (var e=0;e<nCell;e++)
00357     {
00358         var newCell=row.insertCell(e);
00359         var tt=ofirstRow.cells[e].innerHTML;
00360         var new_tt=tt.replace(/march0/g,"march"+nb.value);
00361         new_tt=new_tt.replace(/quant0/g,"quant"+nb.value);
00362         new_tt=new_tt.replace(/sold\(0\)/g,"sold("+nb.value+")");
00363         new_tt=new_tt.replace(/compute_ledger\(0\)/g,"compute_ledger("+nb.value+")");
00364         new_tt=new_tt.replace(/clean_tva\(0\)/g,"clean_tva("+nb.value+")");
00365         newCell.innerHTML=new_tt;
00366         new_tt.evalScripts();
00367     }
00368 
00369     g("e_march"+nb.value+"_label").innerHTML='&nbsp;';
00370     g("e_march"+nb.value+"_label").value='';
00371     g("e_march"+nb.value+"_price").value='0';
00372     g("e_march"+nb.value).value="";
00373     g("e_quant"+nb.value).value="1";
00374     if ($("e_march"+nb.value+"_tva_amount")) g("e_march"+nb.value+"_tva_amount").value=0;
00375 
00376     nb.value++;
00377 
00378     new_tt.evalScripts();
00379         } catch(e) {alert(e.message);}
00380 
00381 }
00382 /**
00383  * @brief compute the sum of a purchase, update the span tvac, htva and tva
00384  * all the needed data are taken from the document (hidden field :  gdossier)
00385  * @param the number of the changed ctrl
00386  */
00387 function compute_ledger(p_ctl_nb)
00388 {
00389     var dossier=g("gDossier").value;
00390     var a=-1;
00391     if ( document.getElementById("e_march"+p_ctl_nb+'_tva_amount'))
00392     {
00393         a=trim(g("e_march"+p_ctl_nb+'_tva_amount').value);
00394         g("e_march"+p_ctl_nb+'_tva_amount').value=a;
00395     }
00396         if ( ! document.getElementById("e_march"+p_ctl_nb))  {return;}
00397     g("e_march"+p_ctl_nb).value=trim(g("e_march"+p_ctl_nb).value);
00398     var qcode=g("e_march"+p_ctl_nb).value;
00399 
00400     if ( qcode.length == 0 )
00401     {
00402         clean_ledger(p_ctl_nb);
00403         refresh_ledger();
00404         return;
00405     }
00406     /*
00407      * if tva_id is empty send a value of -1
00408      */
00409     var tva_id=-1;
00410     if ( g('e_march'+p_ctl_nb+'_tva_id') )
00411     {
00412         tva_id=g('e_march'+p_ctl_nb+'_tva_id').value;
00413         if ( trim(tva_id) == '')
00414         {
00415             tva_id=-1;
00416         }
00417     }
00418 
00419     g('e_march'+p_ctl_nb+'_price').value=trim(g('e_march'+p_ctl_nb+'_price').value);
00420     var price=g('e_march'+p_ctl_nb+'_price').value;
00421 
00422     g('e_quant'+p_ctl_nb).value=trim(g('e_quant'+p_ctl_nb).value);
00423     var quantity=g('e_quant'+p_ctl_nb).value;
00424     var querystring='gDossier='+dossier+'&c='+qcode+'&t='+tva_id+'&p='+price+'&q='+quantity+'&n='+p_ctl_nb;
00425     $('sum').hide();
00426     var action=new Ajax.Request(
00427                    "compute.php",
00428                    {
00429                    method:'get',
00430                    parameters:querystring,
00431                    onFailure:error_compute_ledger,
00432                    onSuccess:success_compute_ledger
00433                    }
00434                );
00435 }
00436 /**
00437 *@brief refresh the purchase screen, recompute vat, total...
00438 */
00439 function refresh_ledger()
00440 {
00441     var tva=0;
00442     var htva=0;
00443     var tvac=0;
00444 
00445     for (var i=0;i<g("nb_item").value;i++)
00446     {
00447         if( g('tva_march'+i))  tva+=g('tva_march'+i).value*1;
00448         if (g('htva_march'+i)) htva+=g('htva_march'+i).value*1;
00449         if (g('tvac_march'+i)) tvac+=g('tvac_march'+i).value*1;
00450     }
00451 
00452     if ( g('tva') ) g('tva').innerHTML=Math.round(tva*100)/100;
00453     if (g('htva')) g('htva').innerHTML=Math.round(htva*100)/100;
00454     if (g('tvac'))    g('tvac').innerHTML=Math.round(tvac*100)/100;
00455 }
00456 /**
00457  *@brief update the field htva, tva_id and tvac, callback function for  compute_sold
00458  * it the field TVA in the answer contains NA it means that VAT is appliable and then do not
00459  * update the VAT field except htva_martc
00460  */
00461 function success_compute_ledger(request,json)
00462 {
00463     var answer=request.responseText.evalJSON(true);
00464     var ctl=answer.ctl;
00465     var rtva=answer.tva;
00466     var rhtva=answer.htva;
00467     var rtvac=answer.tvac;
00468 
00469     if ( rtva == 'NA' )
00470     {
00471         var rhtva=answer.htva*1;
00472         g('htva_march'+ctl).value=rhtva;
00473         g('tvac_march'+ctl).value=rtvac;
00474         g('sum').show();
00475         refresh_ledger();
00476 
00477         return;
00478     }
00479     rtva=answer.tva*1;
00480 
00481 
00482 
00483     g('sum').show();
00484     if ( g('e_march'+ctl+'_tva_amount').value=="" ||  g('e_march'+ctl+'_tva_amount').value==0 )
00485     {
00486         g('tva_march'+ctl).value=rtva;
00487         g('e_march'+ctl+'_tva_amount').value=rtva;
00488     }
00489     else
00490     {
00491         g('tva_march'+ctl).value=g('e_march'+ctl+'_tva_amount').value;
00492     }
00493     g('htva_march'+ctl).value=Math.round(parseFloat(rhtva)*100)/100;
00494     var tmp1=Math.round(parseFloat(g('htva_march'+ctl).value)*100)/100;
00495     var tmp2=Math.round(parseFloat(g('tva_march'+ctl).value)*100)/100;
00496     g('tvac_march'+ctl).value=Math.round((tmp1+tmp2)*100)/100;
00497 
00498     refresh_ledger();
00499 }
00500 
00501 /**
00502  * @brief callback error function for  compute_sold
00503  */
00504 function error_compute_ledger(request,json)
00505 {
00506     alert('Ajax does not work');
00507 }
00508 function compute_all_ledger()
00509 {
00510     var loop=0;
00511     for (loop=0;loop<g("nb_item").value;loop++)
00512     {
00513         compute_ledger(loop);
00514     }
00515     var tva=0;
00516     var htva=0;
00517     var tvac=0;
00518 
00519     for (var i=0;i<g("nb_item").value;i++)
00520     {
00521         if ( g('tva_march') ) tva+=g('tva_march'+i).value*1;
00522         if( g('htva_march'+i)) htva+=g('htva_march'+i).value*1;
00523         if( g('tvac_march'+i))tvac+=g('tvac_march'+i).value*1;
00524     }
00525 
00526     if ( g('tva') ) g('tva').innerHTML=Math.round(tva*100)/100;
00527     if (g('htva')) g('htva').innerHTML=Math.round(htva*100)/100;
00528     if (g('tvac'))g('tvac').innerHTML=Math.round(tvac*100)/100;
00529 
00530 
00531 }
00532 
00533 function clean_tva(p_ctl)
00534 {
00535     if ( g('e_march'+p_ctl+'_tva_amount') )g('e_march'+p_ctl+'_tva_amount').value=0;
00536 }
00537 
00538 function clean_ledger( p_ctl_nb)
00539 {
00540     if ( g("e_march"+p_ctl_nb) )
00541     {
00542         g("e_march"+p_ctl_nb).value=trim(g("e_march"+p_ctl_nb).value);
00543     }
00544     if (g('e_march'+p_ctl_nb+'_price'))
00545     {
00546         g('e_march'+p_ctl_nb+'_price').value='';
00547     }
00548     if ( g('e_quant'+p_ctl_nb))
00549     {
00550         g('e_quant'+p_ctl_nb).value='1';
00551     }
00552     if ( g('tva_march'+p_ctl_nb+'_show') )
00553     {
00554         g('tva_march'+p_ctl_nb+'_show').value='0';
00555     }
00556     if (g('tva_march'+p_ctl_nb))
00557     {
00558         g('tva_march'+p_ctl_nb).value=0;
00559     }
00560     if ( g('htva_march'+p_ctl_nb))
00561     {
00562         g('htva_march'+p_ctl_nb).value=0;
00563     }
00564     if ( g('tvac_march'+p_ctl_nb))
00565     {
00566         g('tvac_march'+p_ctl_nb).value=0;
00567     }
00568 
00569 }
00570 /**
00571  * @brief add a line in the form for the quick_writing
00572  */
00573 function quick_writing_add_row()
00574 {
00575     style='class="input_text"';
00576     var mytable=g("quick_item").tBodies[0];
00577     var nNumberRow=mytable.rows.length;
00578     var oRow=mytable.insertRow(nNumberRow);
00579     var rowToCopy=mytable.rows[1];
00580     var nNumberCell=rowToCopy.cells.length;
00581     var nb=g("nb_item");
00582 
00583     var oNewRow = mytable.insertRow(nNumberRow);
00584     for ( var e=0;e < nNumberCell;e++)
00585     {
00586         var newCell=oRow.insertCell(e);
00587         var tt=rowToCopy.cells[e].innerHTML;
00588         new_tt=tt.replace(/qc_0/g,"qc_"+nb.value);
00589         new_tt=new_tt.replace(/amount0/g,"amount"+nb.value);
00590         new_tt=new_tt.replace(/poste0/g,"poste"+nb.value);
00591         new_tt=new_tt.replace(/ck0/g,"ck"+nb.value);
00592         new_tt=new_tt.replace(/ld0/g,"ld"+nb.value);
00593         newCell.innerHTML=new_tt;
00594         new_tt.evalScripts();
00595     }
00596     $("qc_"+nb.value).value="";
00597     $("amount"+nb.value).value="";
00598     $("poste"+nb.value).value="";
00599     $("ld"+nb.value).value="";
00600 
00601 
00602 
00603     nb.value++;
00604 
00605 }
00606 function RefreshMe()
00607 {
00608     window.location.reload();
00609 }
00610 
00611 
00612 function go_next_concerned()
00613 {
00614     var form=document.forms[1];
00615 
00616     for (var e=0;e<form.elements.length;e++)
00617     {
00618         var elmt=form.elements[e];
00619         if ( elmt.type == "checkbox")
00620         {
00621             if (elmt.checked==true )
00622             {
00623                 return confirm("Si vous changez de page vous perdez les reconciliations, continuez ?");
00624             }
00625         }
00626     }
00627     return true;
00628 }
00629 function view_history_account(p_value,dossier)
00630 {
00631     layer++;
00632     id='det'+layer;
00633     var popup={'id':  id,'cssclass':'inner_box','html':loading(),'drag':true};
00634 
00635     querystring='gDossier='+dossier+'&act=de&pcm_val='+p_value+'&div='+id+"&l="+layer;
00636     add_div(popup);
00637 
00638     var action=new Ajax.Request(
00639                    "ajax_history.php",
00640                    {
00641                    method:'get',
00642                    parameters:querystring,
00643                    onFailure:error_box,
00644                    onSuccess:function (req,xml)
00645                                         {
00646                                                 success_box(req,xml);
00647                                                 g(id).style.top=calcy(140+(layer*3))+"px";
00648                                                 g(id).style.left="10%";
00649                                                 g(id).style.width='80%';
00650                                         }
00651                    }
00652                );
00653 
00654 }
00655 
00656 function update_history_account(obj)
00657 {
00658     try{
00659         var querystring="l="+obj.div+"&div="+obj.div+"&gDossier="+obj.gDossier+"&pcm_val="+obj.pcm_val+"&ex="+obj.select.options[obj.select.selectedIndex].text;
00660         var action=new Ajax.Request(
00661             "ajax_history.php",
00662             {
00663                 method:'get',
00664                 parameters:querystring,
00665                 onFailure:error_box,
00666                   onSuccess:function (req,xml)
00667                                         {
00668                                                 success_box(req,xml);
00669                                                 g(obj.div).style.top=calcy(140+(layer*3))+"px";
00670                                                 g(obj.div).style.left="10%";
00671                                                 g(obj.div).style.width='80%';
00672                                         }
00673             });
00674     } catch (e)
00675     {
00676         alert("update_history_account error "+e.message);
00677     }
00678 
00679     return false;
00680 }
00681 /*!\brief
00682  * \param p_value f_id of the card
00683  */
00684 
00685 function view_history_card(p_value,dossier)
00686 {
00687     layer++;
00688     id='det'+layer;
00689 var popup={'id':
00690            id,'cssclass':'inner_box'
00691            ,'html':
00692            loading(),'drag':
00693                true};
00694     querystring='gDossier='+dossier+'&act=de&f_id='+p_value+'&div='+id+"&l="+layer;
00695     add_div(popup);
00696     var action=new Ajax.Request(
00697                    "ajax_history.php",
00698                    {
00699                    method:'get',
00700                    parameters:querystring,
00701                    onFailure:error_box,
00702                    onSuccess:function (req,xml)
00703                                         {
00704                                                 success_box(req,xml);
00705                                                 g(id).style.top=calcy(140+(layer*3))+"px";
00706                                                 g(id).style.left="10%";
00707                                                 g(id).style.width='80%';
00708                                         }
00709                    }
00710                );
00711 }
00712 
00713 function update_history_card(obj)
00714 {
00715     try{
00716         var querystring="l="+obj.div+"&div="+obj.div+"&gDossier="+obj.gDossier+"&f_id="+obj.f_id+"&ex="+obj.select.options[obj.select.selectedIndex].text;
00717         var action=new Ajax.Request(
00718             "ajax_history.php",
00719             {
00720                 method:'get',
00721                 parameters:querystring,
00722                 onFailure:error_box,
00723                   onSuccess:function (req,xml)
00724                                         {
00725                                                 success_box(req,xml);
00726                                                 g(obj.div).style.top=calcy(140+(layer*3))+"px";
00727                                                 g(obj.div).style.left="10%";
00728                                                 g(obj.div).style.width='80%';
00729                                         }
00730             });
00731     } catch (e)
00732     {
00733         alert("update_history_account error "+e.message);
00734     }
00735 
00736     return false;
00737 }
00738 /**
00739 * remove an Operation
00740 *@param p_jr_id is the jrn.jr_id
00741 *@param dossier
00742 *@param the div
00743 */
00744 function removeOperation(p_jr_id,dossier,div)
00745 {
00746     waiting_box();
00747     var qs="gDossier="+dossier+"&act=rmop&div="+div+"&jr_id="+p_jr_id;
00748     var action=new Ajax.Request(
00749                    "ajax_ledger.php",
00750                    {
00751                    method:'get',
00752                    parameters:qs,
00753                    onFailure:error_box,
00754                    onSuccess:infodiv
00755                    }
00756                );
00757 
00758 }
00759 
00760 /**
00761 * reverse an Operation
00762 *@param pointer to the FORM
00763 */
00764 function reverseOperation(obj)
00765 {
00766     var qs=$(obj).serialize();
00767     g('ext'+obj.divname).style.display='none';
00768     g('bext'+obj.divname).style.display='none';
00769     waiting_box();
00770     var action=new Ajax.Request(
00771                    "ajax_ledger.php",
00772                    {
00773                    method:'get',
00774                    parameters:qs,
00775                    onFailure:error_box,
00776                    onSuccess:infodiv
00777                    }
00778                );
00779 
00780     return false;
00781 }
00782 
00783 /*!\brief
00784  * \param p_value jrn.jr_id
00785  */
00786 function modifyOperation(p_value, dossier)
00787 {
00788         layer++;
00789         var id = 'det' + layer;
00790         waiting_box();
00791         var querystring = 'gDossier=' + dossier + '&act=de&jr_id=' + p_value + '&div=' + id;
00792 
00793         var action = new Ajax.Request(
00794                         "ajax_ledger.php",
00795                         {
00796                                 method: 'get',
00797                                 parameters: querystring,
00798                                 onFailure: error_box,
00799                                 onSuccess: function(xml, txt) {
00800                                         var popup = {'id':id, 'cssclass': 'inner_box'
00801                                                                 , 'html':"", 'drag':true};
00802                                         remove_waiting_box();
00803                                         add_div(popup);
00804                                         success_box(xml, txt);
00805                                         $(id).style.position="absolute";
00806                                         $(id).style.top = calcy(100 + (layer * 3))+"px";
00807                                         g(id).style.left = '10%';
00808                                         g(id).style.width = "80%";
00809                                 }
00810                         }
00811         );
00812 }
00813 
00814 /*!\brief
00815  * \param p_value jrn.jr_id
00816  */
00817 
00818 function viewOperation(p_value,p_dossier)
00819 {
00820     modifyOperation(p_value,p_dossier)
00821 }
00822 function dropLink(p_dossier,p_div,p_jr_id,p_jr_id2)
00823 {
00824     var querystring='gDossier='+p_dossier;
00825     querystring+='&div='+p_div;
00826     querystring+='&jr_id='+p_jr_id;
00827     querystring+='&act=rmr';
00828     querystring+='&jr_id2='+p_jr_id2;
00829     var action=new Ajax.Request ( 'ajax_ledger.php',
00830                                   {
00831                                   method:'get',
00832                                   parameters:querystring,
00833                                   onFailure:null,
00834                                   onSuccess:null
00835                                   }
00836                                 );
00837 }
00838 /**
00839  *@brief this function is called before the querystring is send to the
00840  * fid2.php, add a filter based on the ledger 'p_jrn'
00841  *@param obj is the input field
00842  *@param queryString is the queryString to modify
00843  *@see ICard::input
00844  */
00845 function filter_card(obj,queryString)
00846 {
00847     jrn=$('p_jrn').value;
00848     if ( jrn == -1 )
00849     {
00850         type=$('ledger_type').value;
00851         queryString=queryString+'&type='+type;
00852     }
00853     else
00854     {
00855         queryString=queryString+'&j='+jrn;
00856     }
00857     return queryString;
00858 }
00859 /**
00860  *@brief to display the lettering for the operation, call
00861  * ajax function
00862  *@param obj object attribut :  gDossier,j_id,obj_type
00863  */
00864 function dsp_letter(obj)
00865 {
00866     try
00867     {
00868         var queryString='gDossier='+obj.gDossier+'&j_id='+obj.j_id+'&op=dl'+'&ot='+this.obj_type;
00869         var action=new Ajax.Request(
00870                        "ajax_misc.php",
00871                        {
00872                    method:'get',
00873                    parameters:queryString,
00874                    onFailure:error_dsp_letter,
00875                    onSuccess:success_dsp_letter
00876                        }
00877                    );
00878         g('search').style.display='none';
00879         g('list').style.display='none';
00880         $('detail').innerHTML=loading();
00881         g('detail').style.display='block';
00882     }
00883     catch(e)
00884     {
00885         alert('dsp_letter failed  '+e.message);
00886     }
00887 }
00888 
00889 function success_dsp_letter(req)
00890 {
00891     try
00892     {
00893         var answer=req.responseXML;
00894         var a=answer.getElementsByTagName('code');
00895         var html=answer.getElementsByTagName('value');
00896         if ( a.length == 0 )
00897         {
00898             var rec=req.responseText;
00899             alert ('erreur :'+rec);
00900         }
00901         var name_ctl=a[0].firstChild.nodeValue;
00902         var code_html=getNodeText(html[0]);
00903         code_html=unescape_xml(code_html);
00904         $('detail').innerHTML=code_html;
00905     }
00906     catch (e)
00907     {
00908         alert(e.message);
00909     }
00910     try
00911     {
00912         code_html.evalScripts();
00913     }
00914     catch(e)
00915     {
00916         alert("Impossible executer script de la reponse\n"+e.message);
00917     }
00918 
00919 }
00920 function error_dsp_letter(req)
00921 {
00922     alert('Erreur AJAX DSP_LETTER');
00923 }
00924 
00925 function search_letter(obj)
00926 {
00927     try
00928     {
00929         var str_query='';
00930         if (obj.elements['gDossier'] ) str_query='gDossier='+obj.elements['gDossier'].value;
00931         if (obj.elements['j_id'] ) str_query+='&j_id='+obj.elements['j_id'].value;
00932         if (obj.elements['ot'] ) str_query+='&ot='+obj.elements['ot'].value;
00933         if (obj.elements['op'] ) str_query+='&op='+obj.elements['op'].value;
00934         if (obj.elements['min_amount'] ) str_query+='&min_amount='+obj.elements['min_amount'].value;
00935         if (obj.elements['max_amount'] ) str_query+='&max_amount='+obj.elements['max_amount'].value;
00936         if (obj.elements['search_start'] ) str_query+='&search_start='+obj.elements['search_start'].value;
00937         if (obj.elements['search_end'] ) str_query+='&search_end='+obj.elements['search_end'].value;
00938         if (obj.elements['side'] ) str_query+='&side='+obj.elements['side'].value;
00939 
00940 
00941         var action=new Ajax.Request(
00942                        "ajax_misc.php",
00943                        {
00944                    method:'get',
00945                    parameters:str_query,
00946                    onFailure:error_dsp_letter,
00947                    onSuccess:success_dsp_letter
00948                        }
00949                    );
00950         $('list').hide();
00951         $('search').hide();
00952         $('detail').innerHTML=loading();
00953         $('detail').show();
00954     }
00955     catch(e)
00956     {
00957         alert('search_letter  '+e.message);
00958     }
00959 }
00960 /**
00961 *@brief save an operation in ajax, it concerns only the
00962 * comment, the pj and the rapt
00963 * the form elements are access by their name
00964 *@param obj form
00965 */
00966 function op_save(obj)
00967 {
00968         try {
00969     var queryString=$(obj).serialize();
00970     queryString+="&gDossier="+obj.gDossier.value;
00971     var rapt2="rapt"+obj.whatdiv.value;
00972     queryString+="&rapt="+g(rapt2).value;
00973     queryString+='&jr_id='+obj.jr_id.value;
00974     queryString+='&div='+obj.whatdiv.value;
00975     queryString+='&act=save';
00976     waiting_box();
00977     if ( g('inpopup'))
00978     {
00979         var action=new Ajax.Request ( 'ajax_ledger.php',
00980                                       {
00981                                   method:'post',
00982                                   parameters:queryString,
00983                                   onFailure:null,
00984                                   onSuccess:infodiv
00985                                       }
00986                                     );
00987        // window.close();
00988     }
00989     else
00990     {
00991         var action=new Ajax.Request ( 'ajax_ledger.php',
00992                                       {
00993                                   method:'post',
00994                                   parameters:queryString,
00995                                   onFailure:null,
00996                                   onSuccess:infodiv
00997                                       }
00998                                     );
00999     }
01000     return false;
01001         } catch (e)
01002         { alert(e.message);}
01003 }
01004 function  get_history_account(ctl,dossier) {
01005         if ( $(ctl).value != '')
01006                 {
01007                         view_history_account($(ctl).value, dossier);
01008                 }
01009 }
01010 var previous=[];
01011 function show_reconcile(p_div,p_let)
01012 {
01013         try
01014         {
01015                 if (previous.length != 0)
01016                         {
01017                                 var count_elt=previous.length;
01018                                 var i=0;
01019                                 for (i=0;i<count_elt;i++){
01020                                         previous[i].style.backgroundColor='';
01021                                         previous[i].style.color='';
01022                                         previous[i].style.fontWeight="";
01023                                 }
01024                         }
01025                 var name='tr_'+p_let+'_'+p_div;
01026                 var elt=document.getElementsByName(name);
01027                 previous=elt;
01028                 var count_elt=elt.length;
01029                 var i=0;
01030                 for (i=0;i<count_elt;i++){
01031                         elt[i].style.backgroundColor='#000066';
01032                         elt[i].style.color='white';
01033                         elt[i].style.fontWeight='bolder';
01034 
01035                 }
01036 
01037         } catch (e)
01038         {
01039                 alert(e.message);
01040         }
01041 
01042 
01043 }
01044 /**
01045  * @brief add a line in the form for the purchase ledger
01046  */
01047 function gestion_add_row()
01048 {
01049     try {
01050         style = 'class="input_text"';
01051         var mytable = g("art").tBodies[0];
01052         var ofirstRow = mytable.rows[1];
01053         var line = mytable.rows.length;
01054         var nCell = mytable.rows[1].cells.length;
01055         var row = mytable.insertRow(line);
01056         var nb = g("nb_item");
01057         for (var e = 0; e < nCell; e++)
01058         {
01059             var newCell = row.insertCell(e);
01060             var tt = ofirstRow.cells[e].innerHTML;
01061             var new_tt = tt.replace(/march0/g, "march" + nb.value);
01062             new_tt = new_tt.replace(/quant0/g, "quant" + nb.value);
01063             new_tt = new_tt.replace(/sold\(0\)/g, "sold(" + nb.value + ")");
01064             new_tt = new_tt.replace(/compute_ledger\(0\)/g, "compute_ledger(" + nb.value + ")");
01065             new_tt = new_tt.replace(/clean_tva\(0\)/g, "clean_tva(" + nb.value + ")");
01066             new_tt = new_tt + '<input type="hidden" id="tva_march'+nb.value+'">';
01067                new_tt = new_tt + '<input type="hidden" id="htva_march'+nb.value+'">';
01068             newCell.innerHTML = new_tt;
01069             if ( mytable.rows[1].cells[e].hasClassName("num") ) {
01070                 newCell.addClassName("num");
01071             }
01072             new_tt.evalScripts();
01073         }
01074 
01075         g("e_march" + nb.value + "_label").innerHTML = '&nbsp;';
01076         g("e_march" + nb.value + "_label").value = '';
01077         g("e_march" + nb.value + "_price").value = '0';
01078         g("e_march" + nb.value).value = "";
01079         g("e_quant" + nb.value).value = "1";
01080         g('tvac_march'+nb.value).value="0";
01081         if ($("e_march" + nb.value + "_tva_amount"))
01082             g("e_march" + nb.value + "_tva_amount").value = 0;
01083 
01084         nb.value++;
01085 
01086         new_tt.evalScripts();
01087     } catch (e) {
01088         alert(e.message);
01089     }
01090 
01091 }
 All Data Structures Namespaces Files Functions Variables Enumerations