noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
ajax_fiche.js
Go to the documentation of this file.
1/*
2 * This file is part of NOALYSS.
3 *
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.
8 *
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.
13 *
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
17*/
18/* $Revision$ */
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21/**
22 * @file
23 * This file permit to use the AJAX function to fill up
24 * info from fiche
25 *
26 */
27
28/**
29 * clean the row (the label, price and vat)
30 * @param {string} p_ctl the calling ctrl
31 */
32function clean_Fid(p_ctl)
33{
34
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'}
40 }
41 var aField=['_label'];
42 for ( field of aField) {
43 let obj=document.getElementById(p_ctl+field);
44 if ( obj ) {obj.value=''}
45 }
46}
47function errorFid(request,json)
48{
49 alert_box('ERRFID'+content[48]);
50}
51/**
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
60 */
61function ajaxFid(p_ctl)
62{
63
64 try
65 {
66 var gDossier=id$('gDossier').value;
67 // if p_ctl is a string that find the object
68 var dome =id$(p_ctl);
69
70 var jrn = (dome.jrn) ? dome.jrn.value:-1;
71 dome.value=dome.value.toUpperCase();
72
73 if ( jrn == undefined && document.getElementById('p_jrn')!=undefined)
74 {
75 jrn=id$('p_jrn').value;
76 }
77
78
79 if ( trim(dome.value)=="" )
80 {
81 nLabel=id$(dome).label;
82 if (document.getElementById(nLabel) )
83 {
84 id$(nLabel).value="";
85 id$(nLabel).innerHTML=" ";
86 clean_Fid(dome.id);
87 return;
88 }
89 }
90 var queryString="FID="+trim(dome.value);
91 if ( dome.label)
92 {
93 queryString+='&l='+dome.label;
94 }
95 if ( dome.tvaid)
96 {
97 queryString+='&t='+dome.tvaid;
98 }
99 if ( dome.price)
100 {
101 queryString+='&p='+dome.price;
102 }
103 if ( dome.purchase)
104 {
105 queryString+='&b='+dome.purchase;
106 }
107 if ( dome.typecard)
108 {
109 queryString+='&d='+dome.typecard;
110 }
111 queryString=queryString+"&j="+jrn+'&gDossier='+gDossier;
112 queryString=queryString+'&ctl='+dome.id;
113 queryString=encodeURI(queryString);
114
115 var action=new Ajax.Request (
116 "fid.php",
117 {
118 method:'get',
119 parameters:queryString,
120 onFailure:errorFid,
121 onSuccess:successFid
122 }
123
124 );
125 }catch (e) {
126 alert_box(e.message);
127 alert_box(p_ctl);
128 }
129
130}
131/**
132 callback function for ajax
133 * @param request {object} object request
134 * @param json : {json} answer
135@verbatim
136 {"answer":"ok",
137 "flabel":"none",
138 "name":"Chambre de commerce",
139 "ftva_id":"none",
140 "tva_id":" ",
141 "fPrice_sale":"none",
142 "sell":" ",
143 "fPrice_purchase":"none",
144 "buy":" "}
145@endverbatim
146 */
147function successFid(request,json)
148{
149 if (request.responseText === 'NOCONX') { reconnect();return;}
150
151 var answer=request.responseText.evalJSON(true);
152 var flabel=answer.flabel;
153 if ( answer.answer=='nok' )
154 {
155 set_value(flabel," Fiche inexistante");
156 return;
157 }
158
159 var ftva_id=answer.ftva_id;
160 var fsale=answer.fPrice_sale;
161 var fpurchase=answer.fPrice_purchase;
162
163 if ( ftva_id != 'none')
164 {
165 set_value(ftva_id,answer.tva_id);
166 }
167 if ( flabel != 'none')
168 {
169 set_value(flabel,answer.name);
170 }
171 if ( fsale != 'none')
172 {
173 set_value(fsale,answer.sell);
174 }
175 if ( fpurchase != 'none')
176 {
177 set_value(fpurchase,answer.buy);
178 }
179
180
181}
182function ajax_error_saldo(request,json)
183{
184 alert_box('ERRSAL'+content[48]);
185}
186/**
187 * this function get the saldo
188 * \param p_ctl the ctrl where we take the quick_code
189 */
190function ajax_saldo(p_ctl)
191{
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 (
200 "ajax_misc.php",
201 {
202 method:'get',
203 parameters:queryString,
204 onFailure:ajax_error_saldo,
205 onSuccess:ajax_success_saldo
206 }
207
208 );
209
210}
211/** callback function for ajax
212 * \param request : object request
213 * \param json : json answer */
214function ajax_success_saldo(request,json)
215{
216 var answer=request.responseText.evalJSON(true);
217 id$('first_sold').value=answer.saldo;
218
219}
220
221/**
222 * callback function for ajax_get when successuf
223*/
224function ajax_get_success(request,json)
225{
226 var answer=request.responseText.evalJSON(false);
227 id$(answer.ctl).show();
228 id$(answer.ctl).innerHTML=answer.html;
229}
230/** callback function for ajax_get when fails
231*/
232function ajax_get_failure(request,json)
233{
234 alert_box(content[53]);
235
236}
237
238/**
239 * @class category_card
240 */
241var category_card={};
242
243/**
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
249 */
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",{
254 method:"post",
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
261 },
262 onSuccess:function(req) {
263 var answer=req.responseText.evalJSON();
264 if ( answer.status == 'OK') {
265 var newli = document.createElement("li")
266
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")
274 }
275 });
276 } else {
277 smoke.alert(answer.message);
278 }
279 }
280 });
281};
282/**
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
289 */
290category_card.remove_attribut=function (p_dossier,p_fiche_def_ref,p_object_name,p_attribute_id) {
291 new Ajax.Request("ajax_misc.php",{
292 method:"post",
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
299 },
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);
308 } else {
309 smoke.alert(answer.message);
310 }
311 }
312 });
313};
314/**
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
318 */
319category_card.check_vatnumber = function (p_domid) {
320 try
321 {
322 var dgbox = "info" + p_domid;
323 waiting_box();
324
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);
328
329 var queryString = {
330 op: 'check_vatnumber',
331 vatnr: id$(p_domid).value,
332 boxid: dgbox,
333 p_domid: p_domid
334 };
335 var action = new Ajax.Request(
336 "ajax_misc.php",
337 {
338 method: 'GET',
339 parameters: queryString,
340 onFailure: ajax_misc_failure,
341 onSuccess: function (req) {
342 remove_waiting_box();
343 if (req.responseText == 'NOCONX') {
344 reconnect();
345 return;
346 }
347 var answer = req.responseJSON;
348
349 if (answer.status == 'OK')
350 {
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")
355 } else {
356 id$(p_domid).addClassName("notice");
357 id$(p_domid).removeClassName("valid");
358 id$(dgbox).update(answer.html);
359 }
360
361 }
362 }
363 );
364 } catch (e)
365 {
366 remove_waiting_box();
367 console.error(e.message);
368 }
369}
370category_card.check_ibannumber = function (p_domid) {
371 try
372 {
373 var dgbox = "info" + p_domid;
374 waiting_box();
375
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);
379
380 var queryString = {
381 op: 'check_ibannumber',
382 iban: id$(p_domid).value,
383 boxid: dgbox,
384 p_domid: p_domid
385 };
386 var action = new Ajax.Request(
387 "ajax_misc.php",
388 {
389 method: 'GET',
390 parameters: queryString,
391 onFailure: ajax_misc_failure,
392 onSuccess: function (req) {
393 remove_waiting_box();
394 if (req.responseText == 'NOCONX') {
395 reconnect();
396 return;
397 }
398 var answer = req.responseJSON;
399
400 if (answer.status == 'OK')
401 {
402 id$(p_domid).value = answer.data;
403 id$(p_domid).removeClassName("notice");
404 id$(p_domid).addClassName("valid");
405
406 } else {
407 id$(p_domid).addClassName("notice");
408 id$(p_domid).removeClassName("valid");
409 }
410
411 }
412 }
413 );
414 } catch (e)
415 {
416 remove_waiting_box();
417 console.error(e.message);
418 }
419}
420
421/**
422 * Display a dialog box to search the PEPPOL ID of someone
423 * @parameter p_domid (string) ID of the DOM Element to update
424 */
425category_card.display_search_peppol = function (p_domid)
426{
427 try
428 {
429 var dgbox = "peppol_id_search_div";
430 waiting_box();
431 let peppol_id=id$(p_domid).value;
432 var queryString = {
433 op:'search_peppol'
434 ,ctl:p_domid
435 ,query:peppol_id
436 }
437 if ( peppol_id != "") {
438 queryString['filter']='peppolid';
439 }
440 if (id$("peppol_id_search_div_frm")) {
441 queryString['query']=$F("query");
442 queryString['filter']=$F("filter");
443 }
444
445 var action = new Ajax.Request(
446 "ajax_misc.php",
447 {
448 method: 'GET',
449 parameters: queryString,
450 onSuccess: function (req) {
451 remove_waiting_box();
452 if (req.responseText == 'NOCONX') {
453 reconnect();
454 return;
455 }
456 var y = calcy(15);
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);
460
461
462 }
463 }
464 );
465 } catch (e)
466 {
467 alert_box(e.message);
468 }
469
470}
471
472//-->
473