2 * This file is part of NOALYSS.
4 * NOALYSS is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * NOALYSS is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with NOALYSS; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
23 * This file permit to use the AJAX function to fill up
29 * clean the row (the label, price and vat)
30 * @param {string} p_ctl the calling ctrl
32function clean_Fid(p_ctl)
35 document.getElementById(p_ctl).value='';
36 var aField=['_price','_tva_amount','_tva_id'];
37 for ( field of aField) {
38 let obj=document.getElementById(p_ctl+field);
39 if ( obj ) {obj.value='0'}
41 var aField=['_label'];
42 for ( field of aField) {
43 let obj=document.getElementById(p_ctl+field);
44 if ( obj ) {obj.value=''}
47function errorFid(request,json)
49 alert_box('ERRFID'+content[48]);
52 * this function fills the data from fid.php,
53 * @param {object or string} p_ctl : field of the input, : object or string
54 possible object member
55 - label field to update with the card's name
56 - price field to update with the card's price
57 - tvaid field to update with the card's tva_id
58 - jrn field to force the ledger
59 *@see successFid errorFid fid.php
61function ajaxFid(p_ctl)
66 var gDossier=id$('gDossier').value;
67 // if p_ctl is a string that find the object
70 var jrn = (dome.jrn) ? dome.jrn.value:-1;
71 dome.value=dome.value.toUpperCase();
73 if ( jrn == undefined && document.getElementById('p_jrn')!=undefined)
75 jrn=id$('p_jrn').value;
79 if ( trim(dome.value)=="" )
81 nLabel=id$(dome).label;
82 if (document.getElementById(nLabel) )
85 id$(nLabel).innerHTML=" ";
90 var queryString="FID="+trim(dome.value);
93 queryString+='&l='+dome.label;
97 queryString+='&t='+dome.tvaid;
101 queryString+='&p='+dome.price;
105 queryString+='&b='+dome.purchase;
109 queryString+='&d='+dome.typecard;
111 queryString=queryString+"&j="+jrn+'&gDossier='+gDossier;
112 queryString=queryString+'&ctl='+dome.id;
113 queryString=encodeURI(queryString);
115 var action=new Ajax.Request (
119 parameters:queryString,
126 alert_box(e.message);
132 callback function for ajax
133 * @param request {object} object request
134 * @param json : {json} answer
138 "name":"Chambre de commerce",
141 "fPrice_sale":"none",
143 "fPrice_purchase":"none",
147function successFid(request,json)
149 if (request.responseText === 'NOCONX') { reconnect();return;}
151 var answer=request.responseText.evalJSON(true);
152 var flabel=answer.flabel;
153 if ( answer.answer=='nok' )
155 set_value(flabel," Fiche inexistante");
159 var ftva_id=answer.ftva_id;
160 var fsale=answer.fPrice_sale;
161 var fpurchase=answer.fPrice_purchase;
163 if ( ftva_id != 'none')
165 set_value(ftva_id,answer.tva_id);
167 if ( flabel != 'none')
169 set_value(flabel,answer.name);
171 if ( fsale != 'none')
173 set_value(fsale,answer.sell);
175 if ( fpurchase != 'none')
177 set_value(fpurchase,answer.buy);
182function ajax_error_saldo(request,json)
184 alert_box('ERRSAL'+content[48]);
187 * this function get the saldo
188 * \param p_ctl the ctrl where we take the quick_code
190function ajax_saldo(p_ctl)
192 var gDossier=id$('gDossier').value;
193 var ctl_value=trim(id$(p_ctl).value);
194 var jrn=id$('p_jrn').value;
195 queryString="FID="+ctl_value+"&op=saldo";
196 queryString=queryString+'&gDossier='+gDossier+'&j='+jrn;
197 queryString=queryString+'&ctl='+ctl_value;
198 /* alert_box(queryString); */
199 var action=new Ajax.Request (
203 parameters:queryString,
204 onFailure:ajax_error_saldo,
205 onSuccess:ajax_success_saldo
211/** callback function for ajax
212 * \param request : object request
213 * \param json : json answer */
214function ajax_success_saldo(request,json)
216 var answer=request.responseText.evalJSON(true);
217 id$('first_sold').value=answer.saldo;
222 * callback function for ajax_get when successuf
224function ajax_get_success(request,json)
226 var answer=request.responseText.evalJSON(false);
227 id$(answer.ctl).show();
228 id$(answer.ctl).innerHTML=answer.html;
230/** callback function for ajax_get when fails
232function ajax_get_failure(request,json)
234 alert_box(content[53]);
239 * @class category_card
244 * Add an attribute selected in "sel"+p_object_name into the list (id:p_object_name+"_list")
245 * this attribut will have the ID:p_object_name+"_elt"+ad_id (ad_id = attr_def.ad_id)
246 * @param {int} p_dossier dossier nb
247 * @param {int} p_fiche_def_ref is the frd_id
248 * @param {string} p_object_name , name of the prefix for id
250category_card.add_attribut=function (p_dossier,p_fiche_def_ref,p_object_name) {
251 var select=id$("sel"+p_object_name);
252 var selected_attr=select.value;
253 new Ajax.Request("ajax_misc.php",{
255 parameters:{"gDossier":p_dossier,
256 "objname":p_object_name,
257 "op":"template_cat_category",
258 "action":"add_attribute",
259 "frd_id":p_fiche_def_ref,
260 "ad_id":selected_attr
262 onSuccess:function(req) {
263 var answer=req.responseText.evalJSON();
264 if ( answer.status == 'OK') {
265 var newli = document.createElement("li")
267 id$(p_object_name + "_list").append(newli);
268 newli.replace(answer.content);
269 document.getElementById('attribut_order').value = Sortable.serialize(p_object_name + "_list");
270 select.remove(select.selectedIndex);
271 Sortable.create(p_object_name + '_list', {
272 onUpdate: function () {
273 document.getElementById('attribut_order').value = Sortable.serialize(p_object_name + "_list")
277 smoke.alert(answer.message);
283 * Remove an attribute (id:p_object_name+"_elt"+ad_id (ad_id = attr_def.ad_id))
284 * from the list (id:p_object_name+"list")
285 * @param {int} p_dossier dossier nb
286 * @param {string} p_object_name , name of the prefix for id
287 * @param {int} p_fiche_def_ref is the frd_id
288 * @param {type} p_attribute_id
290category_card.remove_attribut=function (p_dossier,p_fiche_def_ref,p_object_name,p_attribute_id) {
291 new Ajax.Request("ajax_misc.php",{
293 parameters:{"gDossier":p_dossier,
294 "objname":p_object_name,
295 "op":"template_cat_category",
296 "action":"remove_attribute",
297 "frd_id":p_fiche_def_ref,
298 "ad_id":p_attribute_id
300 onSuccess:function(req) {
301 var answer=req.responseText.evalJSON();
302 if ( answer.status == 'OK') {
303 id$(p_object_name+"_elt"+p_attribute_id).remove();
304 var option=document.createElement("option");
305 option.text=answer['content'];
306 option.value=p_attribute_id;
307 id$('sel'+p_object_name).add(option);
309 smoke.alert(answer.message);
315 * @brief ajax call to check a VAT number via VIES
316 * @param p_domid string domid of the IText
317 * @see ivatnumber.class.php
319category_card.check_vatnumber = function (p_domid) {
322 var dgbox = "info" + p_domid;
325 // For form , most of the parameters are in the FORM
326 // method is then POST
327 //var queryString=id$(p_form_id).serialize(true);
330 op: 'check_vatnumber',
331 vatnr: id$(p_domid).value,
335 var action = new Ajax.Request(
339 parameters: queryString,
340 onFailure: ajax_misc_failure,
341 onSuccess: function (req) {
342 remove_waiting_box();
343 if (req.responseText == 'NOCONX') {
347 var answer = req.responseJSON;
349 if (answer.status == 'OK')
351 id$(dgbox).update(answer.html);
352 id$(p_domid).value = answer.vat;
353 id$(p_domid).removeClassName("notice")
354 id$(p_domid).addClassName("valid")
356 id$(p_domid).addClassName("notice");
357 id$(p_domid).removeClassName("valid");
358 id$(dgbox).update(answer.html);
366 remove_waiting_box();
367 console.error(e.message);
370category_card.check_ibannumber = function (p_domid) {
373 var dgbox = "info" + p_domid;
376 // For form , most of the parameters are in the FORM
377 // method is then POST
378 //var queryString=id$(p_form_id).serialize(true);
381 op: 'check_ibannumber',
382 iban: id$(p_domid).value,
386 var action = new Ajax.Request(
390 parameters: queryString,
391 onFailure: ajax_misc_failure,
392 onSuccess: function (req) {
393 remove_waiting_box();
394 if (req.responseText == 'NOCONX') {
398 var answer = req.responseJSON;
400 if (answer.status == 'OK')
402 id$(p_domid).value = answer.data;
403 id$(p_domid).removeClassName("notice");
404 id$(p_domid).addClassName("valid");
407 id$(p_domid).addClassName("notice");
408 id$(p_domid).removeClassName("valid");
416 remove_waiting_box();
417 console.error(e.message);
422 * Display a dialog box to search the PEPPOL ID of someone
423 * @parameter p_domid (string) ID of the DOM Element to update
425category_card.display_search_peppol = function (p_domid)
429 var dgbox = "peppol_id_search_div";
431 let peppol_id=id$(p_domid).value;
437 if ( peppol_id != "") {
438 queryString['filter']='peppolid';
440 if (id$("peppol_id_search_div_frm")) {
441 queryString['query']=$F("query");
442 queryString['filter']=$F("filter");
445 var action = new Ajax.Request(
449 parameters: queryString,
450 onSuccess: function (req) {
451 remove_waiting_box();
452 if (req.responseText == 'NOCONX') {
457 var div_style = "position:absolute;" + ";top:" + y + "px" + ";z-index:" + get_next_layer();
458 add_div({id: dgbox, cssclass: 'inner_box', html: loading(), style: div_style, drag: false});
459 $(dgbox).update( req.responseText);
467 alert_box(e.message);