noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
accounting_item.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
00024  * containing the javascript for opening a windows to search an account (poste comptable)
00025  */
00026 
00027 function set_poste_parent(p_ctl,p_value)
00028 {
00029     var f=g(p_ctl);
00030     f.value+='['+p_value+']';
00031 }
00032 
00033 function set_jrn_parent(p_ctl,p_value)
00034 {
00035     var f=g(p_ctl);
00036     if ( f )
00037     {
00038         if ( trim(f.value)!="") f.value+=' ';
00039         f.value+=p_value;
00040     }
00041 }
00042 /**
00043  * Display a box with accounting detail for update, delete or add
00044  * @param {type} p_value pcmn_val
00045  * @param {type} p_lib pcmn_lib
00046  * @param {type} p_parent pcmn_val_parent
00047  * @param {type} p_type pcmn_val_type
00048  * @param {type} p_dossier gDossier
00049  * @param {type} p_top position of the box
00050  * @param {type} p_action = new | update | delete
00051  * @returns {undefined}
00052  */
00053 
00054 function PcmnUpdate(p_value,p_lib,p_parent,p_type,p_dossier,p_top,p_action)
00055 {
00056     $('p_valu').value=p_value;
00057     $('p_oldu').value=p_value;
00058     $('p_libu').value=p_lib;
00059     $('p_parentu').value=p_parent;
00060     $('p_typeu').value=p_type;
00061     var i=0;
00062     for (i=0;i < $('p_typeu').options.length;i++) {
00063         if ($('p_typeu').options[i].value== p_type) {$('p_typeu').options.selectedIndex= i; break; }
00064     }
00065     $('p_typeu').options.selectedIndex=p_type;
00066     $('acc_update').style.top=(posY+offsetY+p_top)+"px";
00067     $('acc_update').style.left="10%";
00068     $('acc_update').style.width="80%";
00069     $('acc_update_info').innerHTML="";
00070     $('p_action').value=p_action;
00071     $('delete_acc').checked=false;
00072     $('acc_update').show();
00073 }
00074 /**
00075  *@brief show the popup for search an accounting item
00076  *@param object this, it must contains some attribute as
00077  * - jrn if set and different to 0, will filter the accounting item for a
00078  *   ledger
00079  * - account the tag which will contains the  number
00080  * - label the tag which will contains the label
00081  * - bracket if the value must be surrounded by [ ]
00082  * - acc_query for the initial query
00083  *\see ajax_poste.php
00084  */
00085 function search_poste(obj)
00086 {
00087         var sx=0;
00088         if ( window.scrollY)
00089         {
00090             sx=window.scrollY+40;
00091         }
00092         else
00093         {
00094             sx=document.body.scrollTop+60;
00095         }
00096 
00097         var div_style="top:"+sx+"px";
00098         removeDiv('search_account');
00099         add_div({id:'search_account',cssclass:'inner_box',html:loading(),style:div_style,drag:true});
00100 
00101     var dossier=$('gDossier').value;
00102 
00103     var queryString="gDossier="+dossier;
00104 
00105     queryString+="&op=sf";
00106     try
00107     {
00108         if ( obj.jrn)
00109         {
00110             queryString+="&j="+obj.jrn;
00111         }
00112         if ( obj.account)
00113         {
00114             queryString+="&c="+obj.account;
00115         } 
00116         if ( obj.label)
00117         {
00118             queryString+="&l="+obj.label;
00119         }
00120         if ( obj.bracket)
00121         {
00122             queryString+="&b="+obj.bracket;
00123         }
00124         if( obj.noquery)
00125         {
00126             queryString+="&nq";
00127         }
00128         if( obj.no_overwrite)
00129         {
00130             queryString+="&nover";
00131         }
00132         if( obj.bracket)
00133         {
00134             queryString+="&bracket";
00135         }
00136         if ( ! obj.noquery)
00137         {
00138             if( obj.acc_query)
00139             {
00140                 queryString+="&q="+obj.acc_query;
00141             }
00142             else
00143             {
00144                 if ($(obj).account)
00145                 {
00146                     var e=$(obj).account;
00147                     var str_account=$(e).value;
00148                     queryString+="&q="+str_account;
00149                 }
00150             }
00151         }
00152 
00153         queryString+="&ctl="+'search_account';
00154         queryString=encodeURI(queryString);
00155         var action=new Ajax.Request ( 'ajax_poste.php',
00156                                       {
00157                                   method:'get',
00158                                   parameters:queryString,
00159                                   onFailure:errorPoste,
00160                                   onSuccess:result_poste_search
00161                                       }
00162                                     );
00163     }
00164     catch (e)
00165     {
00166         alert(e.getMessage);
00167     }
00168 }
00169 /**
00170  *@brief when you submit the form for searching a accounting item
00171  *@param obj form
00172  *@note the same as search_poste, except it answer to a FORM and not
00173  * to a click event
00174  */
00175 function search_get_poste(obj)
00176 {
00177     var dossier=$('gDossier').value;
00178     var queryString="gDossier="+dossier;
00179 
00180     queryString+="&op=sf";
00181 
00182     if ( obj.elements['jrn'] )
00183     {
00184         queryString+="&j="+$F('jrn');
00185     }
00186     if ( obj.elements['account'])
00187     {
00188         queryString+="&c="+$F('account');
00189     }
00190     if ( obj.elements['label'])
00191     {
00192         queryString+="&l="+$F('label');
00193     }
00194     if( obj.elements['acc_query'])
00195     {
00196         queryString+="&q="+$F('acc_query');
00197     }
00198     if (obj.ctl )
00199     {
00200         queryString+="&ctl="+obj.ctl;
00201     }
00202     if( obj.elements['nosearch'])
00203     {
00204         queryString+="&nq";
00205     }
00206     if( obj.elements['nover'])
00207     {
00208         queryString+="&nover";
00209     }
00210     if( obj.elements['bracket'])
00211     {
00212         queryString+="&bracket";
00213     }
00214 
00215     $('asearch').innerHTML=loading();
00216     var action=new Ajax.Request ( 'ajax_poste.php',
00217                                   {
00218                                   method:'get',
00219                                   parameters:queryString,
00220                                   onFailure:errorPoste,
00221                                   onSuccess:result_poste_search
00222                                   }
00223                                 );
00224 }
00225 
00226 /**
00227  *@brief show the answer of ajax request
00228  *@param  answer in XML
00229  */
00230 function result_poste_search(req)
00231 {
00232     try
00233     {
00234         var answer=req.responseXML;
00235         var a=answer.getElementsByTagName('ctl');
00236         if ( a.length == 0 )
00237         {
00238             var rec=req.responseText;
00239             alert ('erreur :'+rec);
00240         }
00241         var html=answer.getElementsByTagName('code');
00242 
00243         var name_ctl=a[0].firstChild.nodeValue;
00244         var nodeXml=html[0];
00245         var code_html=getNodeText(nodeXml);
00246         code_html=unescape_xml(code_html);
00247         $('search_account').innerHTML=code_html;
00248     }
00249     catch (e)
00250     {
00251         alert(e.message);
00252     }
00253     try
00254     {
00255         code_html.evalScripts();
00256     }
00257     catch(e)
00258     {
00259         alert("Impossible executer script de la reponse\n"+e.message);
00260     }
00261 
00262 }
00263 /**
00264 *@brief error for ajax
00265 */
00266 function errorPoste()
00267 {
00268     alert('Ajax failed');
00269 }
00270 function pausecomp(millis)
00271  {
00272   var date = new Date();
00273   var curDate = null;
00274   do { curDate = new Date(); }
00275   while(curDate-date < millis);
00276 }
00277 /**
00278  * Update an accounting with the information in the form, called frmo
00279  * param_pcmn.inc.php
00280  * @param {type} p_obj_id id of the form
00281  * @returns false
00282  */
00283 function account_update(p_obj_id)
00284 {
00285     try {
00286         waiting_box();
00287         // initialize variables
00288         var gDossier=0;
00289         var p_action="";
00290         var p_oldu=-1;
00291         var p_valu="";
00292         var p_libu="";
00293         var p_parentu="";
00294         var form=$('acc_update_frm_id');
00295         var notfound="not found:";
00296         var p_typeu=-1;
00297         // get them
00298         if ( form['gDossier']) { gDossier=form['gDossier'].value;}else { notfound+='gDossier';} 
00299         if ( form['p_action']) { action=form['p_action'].value;}else { notfound+=', p_action ';}
00300         if ( form['p_oldu']) { p_oldu=form['p_oldu'].value;}else { notfound+=', p_oldu';}
00301         if ( form['p_valu']) { p_valu=form['p_valu'].value;}else { notfound+=', p_valu';}
00302         if ( form['p_libu']) { p_libu=form['p_libu'].value;}else { notfound+=', p_libu ';}
00303         if ( form['p_parentu']) { p_parentu=form['p_parentu'].value;}else { notfound+='p_parentu';}
00304         if ( form['delete_acc'])  { 
00305                 if (form['delete_acc'].checked) { acc_delete=1;} else {acc_delete=0} }
00306             else {
00307                 notfound += ', delete_acc';
00308             }
00309         if ( form['p_typeu']) { p_typeu=form['p_typeu'].value;} else { notfound+=", p_typeu";}
00310         
00311         
00312         if ( notfound != "not found:") throw notfound;
00313             
00314         var queryString = "op=account_update" + "&gDossier=" + gDossier+ "&action=" + action + "&p_oldu=" + p_oldu+"&p_valu="+p_valu+"&p_libu="+p_libu+"&p_parentu="+p_parentu+"&acc_delete="+acc_delete+"&p_typeu="+p_typeu;
00315         var ajax_action = new Ajax.Request(
00316                 "ajax_misc.php",
00317                 {
00318                     method: 'get',
00319                     parameters: queryString,
00320                     onFailure: error_box,
00321                     onSuccess: function(req, json) {
00322                         try
00323                         {
00324                             var name_ctl = 'acc_update_info';
00325                             var answer = req.responseXML;
00326                             remove_waiting_box();
00327                             var html = answer.getElementsByTagName('code');
00328                             var ctl = answer.getElementsByTagName('ctl')[0].textContent;
00329                             if (html.length == 0) {
00330                                 var rec = req.responseText;
00331                                 alert('erreur :' + rec);
00332                             }
00333                             var code_html = getNodeText(html[0]); // Firefox ne prend que les 4096 car.
00334                             code_html = unescape_xml(code_html);
00335                             
00336                             $(name_ctl).innerHTML = code_html;
00337                             if ( ctl == 'ok') {
00338                                window.location.reload();
00339                             }
00340                         } catch (e)
00341                         {
00342                             error_message(e.message);
00343                             return false;
00344                         }
00345                     }
00346                 }
00347 
00348         );
00349         
00350     }catch (e) {
00351         return false;
00352     }
00353     return false;
00354 }
00355  
 All Data Structures Namespaces Files Functions Variables Enumerations