noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
ajax_fiche.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 This file permit to use the AJAX function to fill up
00024  *        info from fiche
00025  *
00026  */
00027 
00028 /*!\brief clean the row (the label, price and vat)
00029  * \param p_ctl the calling ctrl
00030  */
00031 function clean_Fid(p_ctl)
00032 {
00033     nSell=p_ctl+"_price";
00034     nTvaAmount=p_ctl+"_tva_amount";
00035     nBuy=p_ctl+"_price";
00036     nTva_id=p_ctl+"_tva_id";
00037     if ( $(nSell) )
00038     {
00039         $(nSell).value="";
00040     }
00041     if ( $(nBuy) )
00042     {
00043         $(nBuy).value="";
00044     }
00045     if ( $(nTva_id) )
00046     {
00047         $(nTva_id).value="-1";
00048     }
00049     if ( $(nTvaAmount))
00050     {
00051         $(nTvaAmount).value=0;
00052     }
00053 }
00054 function errorFid(request,json)
00055 {
00056     alert('erreur : ajax fiche');
00057 }
00058 /*!\brief this function fills the data from fid.php,
00059  * \param p_ctl object : field of the input,
00060  *  possible object member
00061  * - label field to update with the card's name
00062  * - price field to update with the card's price
00063  * - tvaid field to update with the card's tva_id
00064  * - jrn field to force the ledger
00065   *\see successFid errorFid fid.php
00066  */
00067 function ajaxFid(p_ctl)
00068 {
00069         try
00070         {
00071         var gDossier=$('gDossier').value;
00072     var jrn=$(p_ctl).jrn;
00073     $(p_ctl).value=$(p_ctl).value.toUpperCase();
00074     if ( jrn == undefined )
00075     {
00076         if ($('p_jrn')!=undefined)
00077         {
00078             jrn=$('p_jrn').value;
00079         }
00080     }
00081     if ( jrn == undefined )
00082     {
00083         jrn=-1;
00084     }
00085     if ( trim($(p_ctl).value)=="" )
00086     {
00087         nLabel=$(p_ctl).label;
00088         if ($(nLabel) )
00089         {
00090             $(nLabel).value="";
00091             $(nLabel).innerHTML=" ";
00092             clean_Fid(p_ctl);
00093             return;
00094         }
00095     }
00096     var queryString="FID="+trim($(p_ctl).value);
00097     if ( $(p_ctl).label)
00098     {
00099         queryString+='&l='+$(p_ctl).label;
00100     }
00101     if ( $(p_ctl).tvaid)
00102     {
00103         queryString+='&t='+$(p_ctl).tvaid;
00104     }
00105     if ( $(p_ctl).price)
00106     {
00107         queryString+='&p='+$(p_ctl).price;
00108     }
00109     if ( $(p_ctl).purchase)
00110     {
00111         queryString+='&b='+$(p_ctl).purchase;
00112     }
00113     if ( $(p_ctl).typecard)
00114     {
00115         queryString+='&d='+$(p_ctl).typecard;
00116     }
00117     queryString=queryString+"&j="+jrn+'&gDossier='+gDossier;
00118     queryString=queryString+'&ctl='+p_ctl.id;
00119 
00120     var action=new Ajax.Request (
00121                    "fid.php",
00122                    {
00123                    method:'get',
00124                    parameters:queryString,
00125                    onFailure:errorFid,
00126                    onSuccess:successFid
00127                    }
00128 
00129                );
00130         }catch (e)  {
00131                 alert(e.message);
00132                 alert(p_ctl);
00133         }
00134 
00135 }
00136 /*!\brief callback function for ajax
00137  * \param request : object request
00138  * \param json : json answer
00139 \verbatim
00140  {"answer":"ok",
00141  "flabel":"none",
00142  "name":"Chambre de commerce",
00143  "ftva_id":"none",
00144  "tva_id":" ",
00145  "fPrice_sale":"none",
00146  "sell":" ",
00147  "fPrice_purchase":"none",
00148  "buy":" "}
00149 \endverbatim
00150  */
00151 function successFid(request,json)
00152 {
00153     var answer=request.responseText.evalJSON(true);
00154     var flabel=answer.flabel;
00155     if ( answer.answer=='nok' )
00156     {
00157         set_value(flabel," Fiche inexistante");
00158         return;
00159     }
00160 
00161     var ftva_id=answer.ftva_id;
00162     var fsale=answer.fPrice_sale;
00163     var fpurchase=answer.fPrice_purchase;
00164 
00165     if ( ftva_id != 'none')
00166     {
00167         set_value(ftva_id,answer.tva_id);
00168     }
00169     if ( flabel != 'none')
00170     {
00171         set_value(flabel,answer.name);
00172     }
00173     if ( fsale != 'none')
00174     {
00175         set_value(fsale,answer.sell);
00176     }
00177     if ( fpurchase != 'none')
00178     {
00179         set_value(fpurchase,answer.buy);
00180     }
00181 
00182 
00183 }
00184 function ajax_error_saldo(request,json)
00185 {
00186     alert('erreur : ajax solde ');
00187 }
00188 /*!\brief this function get the saldo
00189  * \param p_ctl the ctrl where we take the quick_code
00190  */
00191 function ajax_saldo(p_ctl)
00192 {
00193     var gDossier=$('gDossier').value;
00194     var ctl_value=trim($(p_ctl).value);
00195     var jrn=$('p_jrn').value;
00196     queryString="FID="+ctl_value+"&op=saldo";
00197     queryString=queryString+'&gDossier='+gDossier+'&j='+jrn;
00198     queryString=queryString+'&ctl='+ctl_value;
00199     /*  alert(queryString); */
00200     var action=new Ajax.Request (
00201                    "ajax_misc.php",
00202                    {
00203                    method:'get',
00204                    parameters:queryString,
00205                    onFailure:ajax_error_saldo,
00206                    onSuccess:ajax_success_saldo
00207                    }
00208 
00209                );
00210 
00211 }
00212 /*!\brief callback function for ajax
00213  * \param request : object request
00214  * \param json : json answer */
00215 function ajax_success_saldo(request,json)
00216 {
00217     var answer=request.responseText.evalJSON(true);
00218     $('first_sold').value=answer.saldo;
00219 
00220 }
00221 /*!\brief this function get data from ajax_card.php and fill the hidden div with the return html string
00222 * \param p_dossier
00223 * \param f_id fiche.f_id
00224 * \param p_operation what to do : op : history of operation
00225 * \param ctl : id of the div to show
00226 * \param page
00227 */
00228 function ajax_card(p_dossier,f_id,p_operation,ctl,page)
00229 {
00230     $(ctl).show();
00231     var queryString="gDossier="+p_dossier+"&f_id="+f_id+"&op="+p_operation+"&p="+page+'&ctl='+ctl;
00232     var action = new Ajax.Request(
00233                  "ajax_card.php" , { method:'get', parameters:queryString,onFailure:ajax_get_failure,onSuccess:ajax_get_success}
00234                  );
00235 }
00236 /*!\brief callback function for ajax_get when successuf
00237 */
00238 function ajax_get_success(request,json)
00239 {
00240     var answer=request.responseText.evalJSON(false);
00241     $(answer.ctl).show();
00242     $(answer.ctl).innerHTML=answer.html;
00243 }
00244 /*!\brief callback function for ajax_get when fails
00245 */
00246 function ajax_get_failure(request,json)
00247 {
00248     alert("Ajax do not work for ajax_get");
00249 
00250 }
00251 
00252 //-->
 All Data Structures Namespaces Files Functions Variables Enumerations