noalyss Version-9
acc_ledger.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/*!
23 * \file
24 * \brief javascript script for the ledger in accountancy,
25 * compute the sum, add a row at the table..
26 *
27 */
28var layer = 1;
29
30/**
31 * \fn
32 * \brief update the list of available predefined operation when we change the ledger.
33 */
34function update_predef(p_type, p_direct, p_ac) {
35 var jrn = g("p_jrn").value;
36 var dossier = g("gDossier").value;
37 var querystring = 'gDossier=' + dossier + '&l=' + jrn + '&t=' + p_type + '&d=' + p_direct + "&op=up_predef&ac=" + p_ac;
38 g("p_jrn_predef").value = jrn;
39 var action = new Ajax.Request(
40 "ajax_misc.php",
41 {
42 method: 'get',
43 parameters: querystring,
44 onFailure: error_get_predef,
45 onSuccess: function (req) {
46 try {
47 $('info_div').innerHTML = "ok";
48 var answer = req.responseXML;
49 var a = answer.getElementsByTagName('code');
50 var html = answer.getElementsByTagName('value');
51 if (a.length == 0) {
52 var rec = req.responseText;
53 alert_box(content[48] + rec);
54 }
55 var code_html = getNodeText(html[0]);
56 code_html = unescape_xml(code_html);
57 // document.getElementsByName(name_ctl)[0].value = code_html;
58 $('modele_op_div').innerHTML = code_html;
59 } catch (e) {
60 $('info_div').innerHTML = e.message;
61 }
62 }
63 }
64 );
65}
66
67/**
68 * update the list of payment method when we change the ledger.
69 */
70function update_pay_method() {
71 waiting_box();
72 var jrn = g("p_jrn").value;
73 var dossier = g("gDossier").value;
74 var querystring = 'gDossier=' + dossier + '&l=' + jrn + "&op=up_pay_method";
75 var action = new Ajax.Request(
76 "ajax_misc.php",
77 {
78 method: 'get',
79 parameters: querystring,
80 onFailure: error_get_predef,
81 onSuccess: function (req) {
82 remove_waiting_box();
83 var answer = req.responseText;
84 $('payment').innerHTML = answer;
85 }
86 }
87 );
88}
89
90/**
91 * update the list of additional tax
92 */
93function update_other_tax() {
94 waiting_box();
95 var jrn = g("p_jrn").value;
96 var dossier = g("gDossier").value;
97 var querystring = {gDossier: dossier, jrn_id: jrn, op: "up_other_tax"};
98 var action = new Ajax.Request(
99 "ajax_misc.php",
100 {
101 method: 'get',
102 parameters: querystring,
103 onFailure: error_get_predef,
104 onSuccess: function (req) {
105 remove_waiting_box();
106 var answer = req.responseText;
107 answer.evalScripts();
108 $('additional_tax_div').innerHTML = answer;
109 }
110 }
111 );
112}
113
114/**
115 * update ctl id =jrn_name with the value of p_jrn
116 */
117function update_name() {
118 var jrn_id = $('p_jrn').value;
119 var dossier = g("gDossier").value;
120 var querystring = 'gDossier=' + dossier + '&l=' + jrn_id + "&op=ledger_description";
121 var action = new Ajax.Request(
122 "ajax_misc.php",
123 {
124 method: 'get',
125 parameters: querystring,
126 onFailure: error_get_pj,
127 onSuccess: function (req) {
128 $('jrn_name_div').innerHTML = req.responseText;
129 }
130 }
131 );
132
133}
134
135/**
136 * update the field predef
137 */
138function error_get_predef(request, json) {
139 alert_box(content[49]);
140
141}
142
143/**
144 * update the list of available predefined operation when we change the ledger.
145 */
146function update_pj() {
147 var jrn = g("p_jrn").value;
148 var dossier = g("gDossier").value;
149 var querystring = 'gDossier=' + dossier + '&l=' + jrn + "&op=upd_receipt";
150 var action = new Ajax.Request(
151 "ajax_misc.php",
152 {
153 method: 'get',
154 parameters: querystring,
155 onFailure: error_get_pj,
156 onSuccess: success_get_pj
157 }
158 );
159}
160
161/**
162 * ask the name, quick_code of the bank for the ledger
163 */
164function update_bank() {
165 var jrn = g('p_jrn').value;
166 var dossier = g('gDossier').value;
167 var qs = 'gDossier=' + dossier + '&op=bkname&p_jrn=' + jrn;
168 var action = new Ajax.Request(
169 "ajax_misc.php",
170 {
171 method: 'get',
172 parameters: qs,
173 onFailure: error_get_pj,
174 onSuccess: success_update_bank
175 }
176 );
177
178}
179
180/**
181 * Update the number of rows when changing of ledger
182 */
183function update_row(ctl) {
184 try {
185 var row_to_keep = 3; /* Number of row to keep (head and foot)*/
186 if (ctl === 'quick_item') {
187 row_to_keep = 1;
188 } /* for ODS , only 1 rows to keep */
189 var jrn = g('p_jrn').value;
190 var dossier = g('gDossier').value;
191 var qs = encodeURI('gDossier=' + dossier + '&op=minrow&j=' + jrn + '&ctl=' + ctl);
192 var current_row = parseFloat($('nb_item').value);
193 var action = new Ajax.Request(
194 "ajax_misc.php",
195 {
196 method: 'get',
197 parameters: qs,
198 onFailure: null,
199 onSuccess: function (request, json) {
200 try {
201 var answer = request.responseText.evalJSON(true);
202 var row = parseFloat(answer.row);
203
204 var table_to_update = $(ctl);
205 if (current_row > row) {
206 // Too many row, we always must keep 2 rows for the sum
207 var delta = $('nb_item').value - row;
208 var idx = $('nb_item').value;
209 for (var i = 0; i < delta; i++) {
210 var pos_row = table_to_update.rows.length;
211 var cell0 = table_to_update.rows[pos_row - row_to_keep].cells[0];
212 var cell0Element = cell0.childNodes;
213 var canDelete = true;
214 /**
215 * prevent truncating
216 */
217 cell0Element.forEach(function (x) {
218 if (canDelete && x.nodeName == 'INPUT' && x.type === "text" && x.value) {
219 canDelete = false;
220 }
221 }
222 );
223 /*
224 * prevent truncating
225 * For ODS we also need to check the second column
226 * */
227 if (canDelete && ctl === 'quick_item') {
228 var cell1 = table_to_update.rows[pos_row - row_to_keep].cells[1];
229 var cell1Element = cell1.childNodes;
230 cell1Element.forEach(function (x) {
231 if (canDelete && x.nodeName == 'INPUT' && x.type === "text" && x.value) {
232 canDelete = false;
233 }
234 });
235 }
236 if (canDelete) {
237 table_to_update.deleteRow(pos_row - row_to_keep);
238 idx--;
239 }
240
241 }
242 $('nb_item').value = table_to_update.rows.length - row_to_keep;
243 }
244 if (current_row < row) {
245 // We need to add rows
246 var delta = row - current_row;
247 for (var i = 0; i < delta; i++) {
248 if (ctl == 'fin_item') {
249 ledger_fin_add_row();
250 }
251 if (ctl == 'sold_item') {
252 ledger_add_row();
253 }
254 if (ctl == 'quick_item') {
255 quick_writing_add_row();
256 }
257 }
258 }
259 } catch (e) {
260 alert_box("update_row:01" + e.message);
261 }
262 }
263 }
264 );
265 } catch (e) {
266 alert_box(e.message);
267 }
268}
269
270/**
271 * @brief hide or show the column quantity
272 */
273function update_visibility_quantity() {
274 var jrn = g("p_jrn").value;
275 var dossier = g("gDossier").value;
276 var querystring = 'gDossier=' + dossier + '&l=' + jrn + "&op=update_visibility_quantity";
277 var action = new Ajax.Request(
278 "ajax_misc.php",
279 {
280 method: 'get',
281 parameters: querystring,
282 onSuccess: function (req) {
283 try {
284 // retrieve quantity
285 var quantity_col = document.getElementsByClassName("col_quant");
286 for (var i = 0; i < quantity_col.length; i++) {
287 if (req.responseText == "0") {
288 // hide the columns quantity and return
289 quantity_col[i].hide();
290 quantity_col[i].addClassName('d-none');
291 }
292 if (req.responseText == "1") {
293 // show the columns quantity and return
294 quantity_col[i].show();
295 quantity_col[i].removeClassName('d-none');
296 }
297 }
298 } catch (e) {
299 console.error("update_visibility_quantity" + e.message);
300 }
301
302
303 }
304 }
305 );
306}
307
308/**
309 * Put into the span, the name of the bank, the bank account
310 * and the quick_code
311 */
312function success_update_bank(req) {
313 try {
314 var answer = req.responseXML;
315 var a = answer.getElementsByTagName('code');
316 var html = answer.getElementsByTagName('value');
317 if (a.length == 0) {
318 var rec = req.responseText;
319 alert_box('UPDBK-' + content[48] + rec);
320 }
321 var name_ctl = a[0].firstChild.nodeValue;
322 var code_html = getNodeText(html[0]);
323 code_html = unescape_xml(code_html);
324 $(name_ctl).innerHTML = code_html;
325 } catch (e) {
326 alert_box("success_update_bank" + e.message);
327 }
328}
329
330/**
331 * call ajax, ask what is the last date for the current ledger
332 */
333function get_last_date() {
334 var jrn = g('p_jrn').value;
335 var dossier = g('gDossier').value;
336 var qs = 'gDossier=' + dossier + '&op=lastdate&p_jrn=' + jrn;
337 var action = new Ajax.Request(
338 "ajax_misc.php",
339 {
340 method: 'get',
341 parameters: qs,
342 onFailure: error_get_pj,
343 onSuccess: success_get_last_date
344 }
345 );
346}
347
348/**
349 * callback ajax, set the ctl with the last date from the ledger
350 */
351function success_get_last_date(req) {
352 try {
353 var answer = req.responseXML;
354 var a = answer.getElementsByTagName('code');
355 var html = answer.getElementsByTagName('value');
356 if (a.length == 0) {
357 var rec = req.responseText;
358 alert_box('GETLASTDA:' + content[48] + rec);
359 }
360 var name_ctl = a[0].firstChild.nodeValue;
361 var code_html = getNodeText(html[0]);
362 code_html = unescape_xml(code_html);
363 document.getElementsByName(name_ctl)[0].value = code_html;
364 } catch (e) {
365 alert_box(e.message);
366 }
367}
368
369/**
370 * update the field predef
371 */
372function success_get_pj(request, json) {
373
374 var answer = request.responseText.evalJSON(true);
375 var obj = g("e_pj");
376 obj.value = '';
377 if (answer.length == 0)
378 return;
379 obj.value = answer.pj;
380 g("e_pj_suggest").value = answer.pj;
381}
382
383/**
384 * update the field predef
385 */
386function error_get_pj(request, json) {
387 alert_box("GETPJ:" + content[48]);
388}
389
390/**
391 * add a line in the form for the ledger fin
392 */
393function ledger_fin_add_row() {
394 var style = 'class="input_text"';
395 var mytable = g("fin_item").tBodies[0];
396 var line = mytable.rows.length;
397 var row = mytable.insertRow(line);
398 var nb = g("nb_item");
399 var rowToCopy = mytable.rows[1];
400 var nNumberCell = rowToCopy.cells.length;
401 for (var e = 0; e < nNumberCell; e++) {
402 var newCell = row.insertCell(e);
403 if (e == 0) {
404 newCell.id = 'tdchdate' + nb.value;
405 }
406 var tt = rowToCopy.cells[e].innerHTML;
407 var new_tt = tt.replace(/e_other0/g, "e_other" + nb.value);
408 new_tt = new_tt.replace(/e_other0_comment/g, "e_other" + nb.value + '_comment');
409 new_tt = new_tt.replace(/e_other_name0/g, "e_other_name" + nb.value);
410 new_tt = new_tt.replace(/e_other0_amount/g, "e_other" + nb.value + '_amount');
411 new_tt = new_tt.replace(/e_concerned0/g, "e_concerned" + nb.value);
412 new_tt = new_tt.replace(/e_other0_label/g, "e_other" + nb.value + '_label');
413 new_tt = new_tt.replace(/dateop0/g, "dateop" + nb.value);
414 newCell.innerHTML = new_tt;
415 newCell.className = rowToCopy.cells[e].className;
416 new_tt.evalScripts();
417 }
418 g("e_other" + nb.value).value = "";
419 g("e_other_name" + nb.value).value = "";
420 g("e_other" + nb.value + '_amount').value = "0";
421 g("e_other" + nb.value + '_comment').value = "";
422 g("e_concerned" + nb.value).value = "";
423
424 var ch = $('chdate').options[$('chdate').selectedIndex].value;
425 if (ch == 1) {
426 $('tdchdate' + nb.value).hide();
427 }
428 nb.value++;
429}
430
431/**
432 * Add multiple row
433 * @param string p_elid is the id of element with the number of rows to add, and p_elid+"_ledger" is the type of ledger : M : Misc Operation O : Sales or purchase and F for financial
434 */
435function ledger_add_multiple(p_elid) {
436 var nbrow = $(p_elid).value;
437 if (nbrow == NaN) {
438 nbrow = 1;
439 }
440 var type_ledger = $(p_elid + "_ledger").value;
441 var i = 0;
442 for (i = 0; i < nbrow; i++) {
443 if (type_ledger == 'O') {
444 ledger_add_row();
445 }
446 if (type_ledger == 'F') {
447 ledger_fin_add_row();
448 }
449 if (type_ledger == 'M') {
450 quick_writing_add_row();
451 }
452 }
453 if (type_ledger == 'M') {
454 var aCheckBox = $$('.debit-credit')
455 aCheckBox.forEach((item) => display_dcside(item))
456 }
457}
458
459/**
460 * add a line in the form for the purchase ledger
461 * @param p_dossier folder id
462 * @param p_table_name
463 */
464function ledger_add_row() {
465 try {
466 style = 'class="input_text"';
467 var mytable = g("sold_item").tBodies[0];
468 var ofirstRow = mytable.rows[1];
469 var line = mytable.rows.length;
470 var nCell = mytable.rows[1].cells.length;
471 var row = mytable.insertRow(line);
472 var nb = g("nb_item");
473 for (var e = 0; e < nCell; e++) {
474 var newCell = row.insertCell(e);
475 var tt = ofirstRow.cells[e].innerHTML;
476 var new_tt = tt.replace(/march0/g, "march" + nb.value);
477 new_tt = new_tt.replace(/quant0/g, "quant" + nb.value);
478 new_tt = new_tt.replace(/sold\‍(0\‍)/g, "sold(" + nb.value + ")");
479 new_tt = new_tt.replace(/compute_ledger\‍(0\‍)/g, "compute_ledger(" + nb.value + ")");
480 new_tt = new_tt.replace(/clean_tva\‍(0\‍)/g, "clean_tva(" + nb.value + ")");
481 newCell.innerHTML = new_tt;
482 newCell.className = ofirstRow.cells[e].className;
483 new_tt.evalScripts();
484 }
485
486 $("e_march" + nb.value + "_label").innerHTML = '';
487 $("e_march" + nb.value + "_label").value = '';
488 $("e_march" + nb.value + "_price").value = '0';
489 $("e_march" + nb.value).value = "";
490 $("e_quant" + nb.value).value = "1";
491 if ($("e_march" + nb.value + "_tva_amount"))
492 $("e_march" + nb.value + "_tva_amount").value = 0;
493
494 nb.value++;
495
496 new_tt.evalScripts();
497 } catch (e) {
498 alert_box(e.message);
499 }
500}
501
502/**
503 * compute the sum of a purchase, update the span tvac, htva and tva
504 * all the needed data are taken from the document (hidden field : gdossier)
505 * @param the number of the changed ctrl
506 */
507function compute_ledger(p_ctl_nb) {
508 var dossier = g("gDossier").value;
509 var a = -1;
510 if (document.getElementById("e_march" + p_ctl_nb + '_tva_amount')) {
511 a = trim(g("e_march" + p_ctl_nb + '_tva_amount').value);
512 g("e_march" + p_ctl_nb + '_tva_amount').value = a;
513 }
514 if (!document.getElementById("e_march" + p_ctl_nb)) {
515 return;
516 }
517 g("e_march" + p_ctl_nb).value = trim(g("e_march" + p_ctl_nb).value);
518 var qcode = g("e_march" + p_ctl_nb).value;
519
520 if (qcode.length == 0) {
521 clean_ledger(p_ctl_nb);
522 refresh_ledger();
523 return;
524 }
525 /*
526 * if tva_id is empty send a value of -1
527 */
528 var tva_id = -1;
529 if (g('e_march' + p_ctl_nb + '_tva_id')) {
530 tva_id = g('e_march' + p_ctl_nb + '_tva_id').value;
531 if (trim(tva_id) == '') {
532 tva_id = -1;
533 }
534 }
535
536 g('e_march' + p_ctl_nb + '_price').value = trim(g('e_march' + p_ctl_nb + '_price').value);
537 var price = g('e_march' + p_ctl_nb + '_price').value;
538
539 g('e_quant' + p_ctl_nb).value = trim(g('e_quant' + p_ctl_nb).value);
540 var quantity = g('e_quant' + p_ctl_nb).value;
541 let other_tax = g("other_tax");
542 let other_tax_id = (other_tax && other_tax.checked) ? other_tax.value : -1;
543
544 var querystring = {
545 gDossier: dossier,
546 c: qcode,
547 t: tva_id,
548 p: price,
549 q: quantity,
550 n: p_ctl_nb,
551 'other_tax_id': other_tax_id
552 };
553 var action = new Ajax.Request(
554 "compute.php",
555 {
556 method: 'get',
557 parameters: querystring,
558 onFailure: error_compute_ledger,
559 onSuccess: success_compute_ledger
560 }
561 );
562}
563
564/**
565 * refresh the purchase screen, recompute vat, total...
566 */
567function refresh_ledger() {
568 var tva = 0;
569 var htva = 0;
570 var tvac = 0;
571
572 nb_item = g("nb_item").value;
573 for (var i = 0; i < nb_item; i++) {
574 if (g('tva_march' + i))
575 tva += g('tva_march' + i).value * 1;
576 if (g('htva_march' + i))
577 htva += g('htva_march' + i).value * 1;
578 if (g('tvac_march' + i))
579 tvac += g('tvac_march' + i).value * 1;
580 }
581 id_tva = g("tva");
582 id_htva = g("htva");
583 id_tvac = g("tvac");
584 id_other_tax = g("other_tax_amount");
585 if (id_tva)
586 id_tva.innerHTML = Math.round(tva * 100) / 100;
587 if (id_htva)
588 id_htva.innerHTML = Math.round(htva * 100) / 100;
589 if (id_other_tax) {
590 let total_operation = tvac + parseFloat(id_other_tax.value);
591 $('total_operation_other_tax').innerHTML = Math.round(total_operation * 100) / 100;
592 }
593 if (id_tvac)
594 id_tvac.innerHTML = Math.round(tvac * 100) / 100;
595
596
597}
598
599/**
600 * update the field htva, tva_id and tvac, callback function for compute_sold
601 * it the field TVA in the answer contains NA it means that VAT is appliable and then do not
602 * update the VAT field except htva_martc
603 */
604function success_compute_ledger(request, json) {
605 var answer = request.responseText.evalJSON(true);
606 var ctl = answer.ctl;
607 var rtva = answer.tva;
608 var rhtva = answer.htva;
609 var rtvac = answer.tvac;
610 let other_tax = g("other_tax_amount")
611 if (other_tax) {
612 other_tax.value = answer.other_tax;
613 }
614 if (rtva == 'NA') {
615 var rhtva = answer.htva * 1;
616 g('htva_march' + ctl).value = rhtva;
617 g('tvac_march' + ctl).value = rtvac;
618 g('sum').show();
619 refresh_ledger();
620 CurrencyCompute('p_currency_rate', 'p_currency_euro');
621
622 return;
623 }
624 rtva = answer.tva * 1;
625
626
627 g('sum').show();
628 if (g('e_march' + ctl + '_tva_amount').value == "" || g('e_march' + ctl + '_tva_amount').value == 0) {
629 g('tva_march' + ctl).value = rtva;
630 g('e_march' + ctl + '_tva_amount').value = rtva;
631 } else {
632 g('tva_march' + ctl).value = g('e_march' + ctl + '_tva_amount').value;
633 }
634 g('htva_march' + ctl).value = Math.round(parseFloat(rhtva) * 100) / 100;
635 var tmp1 = Math.round(parseFloat(g('htva_march' + ctl).value) * 100) / 100;
636 var tmp2 = Math.round(parseFloat(g('tva_march' + ctl).value) * 100) / 100;
637 g('tvac_march' + ctl).value = Math.round((tmp1 + tmp2) * 100) / 100;
638 refresh_ledger();
639 CurrencyCompute('p_currency_rate', 'p_currency_euro');
640
641}
642
643/**
644 * callback error function for compute_sold
645 */
646function error_compute_ledger(request, json) {
647 alert_box('Ajax does not work');
648}
649
650function compute_all_ledger() {
651 var loop = 0;
652 let nb_item = g("nb_item").value;
653 for (loop = 0; loop < nb_item; loop++) {
654 compute_ledger(loop);
655 }
656 var tva = 0;
657 var htva = 0;
658 var tvac = 0;
659
660 for (var i = 0; i < nb_item; i++) {
661 if (g('tva_march'))
662 tva += g('tva_march' + i).value * 1;
663 if (g('htva_march' + i))
664 htva += g('htva_march' + i).value * 1;
665 if (g('tvac_march' + i))
666 tvac += g('tvac_march' + i).value * 1;
667 }
668 id_other_tax = g("other_tax_amount");
669 if (g('tva'))
670 g('tva').innerHTML = Math.round(tva * 100) / 100;
671 if (g('htva'))
672 g('htva').innerHTML = Math.round(htva * 100) / 100;
673 if (id_other_tax) {
674 tvac += id_other_tax.value;
675 }
676 if (g('tvac'))
677 g('tvac').innerHTML = Math.round(tvac * 100) / 100;
678
679
680}
681
682function clean_tva(p_ctl) {
683 if (g('e_march' + p_ctl + '_tva_amount'))
684 g('e_march' + p_ctl + '_tva_amount').value = 0;
685}
686
687function clean_ledger(p_ctl_nb) {
688 if (g("e_march" + p_ctl_nb)) {
689 g("e_march" + p_ctl_nb).value = trim(g("e_march" + p_ctl_nb).value);
690 }
691 if (g('e_march' + p_ctl_nb + '_price')) {
692 g('e_march' + p_ctl_nb + '_price').value = '';
693 }
694 if (g('e_quant' + p_ctl_nb)) {
695 g('e_quant' + p_ctl_nb).value = '1';
696 }
697 if (g('tva_march' + p_ctl_nb + '_show')) {
698 g('tva_march' + p_ctl_nb + '_show').value = '0';
699 }
700 if (g('tva_march' + p_ctl_nb)) {
701 g('tva_march' + p_ctl_nb).value = 0;
702 }
703 if (g('htva_march' + p_ctl_nb)) {
704 g('htva_march' + p_ctl_nb).value = 0;
705 }
706 if (g('tvac_march' + p_ctl_nb)) {
707 g('tvac_march' + p_ctl_nb).value = 0;
708 }
709
710}
711
712/**
713 * add a line in the form for the quick_writing
714 */
715function quick_writing_add_row() {
716 style = 'class="input_text"';
717 var mytable = g("quick_item").tBodies[0];
718 var nNumberRow = mytable.rows.length;
719 var oRow = mytable.insertRow(nNumberRow);
720 var rowToCopy = mytable.rows[1];
721 var nNumberCell = rowToCopy.cells.length;
722 var nb = g("nb_item");
723
724 var oNewRow = mytable.insertRow(nNumberRow);
725 for (var e = 0; e < nNumberCell; e++) {
726 var newCell = oRow.insertCell(e);
727 var tt = rowToCopy.cells[e].innerHTML;
728 new_tt = tt.replace(/qc_0/g, "qc_" + nb.value);
729 new_tt = new_tt.replace(/amount0/g, "amount" + nb.value);
730 new_tt = new_tt.replace(/poste0/g, "poste" + nb.value);
731 new_tt = new_tt.replace(/ck0/g, "ck" + nb.value);
732 new_tt = new_tt.replace(/ld0/g, "ld" + nb.value);
733 newCell.innerHTML = new_tt;
734 newCell.className = rowToCopy.cells[e].className;
735 new_tt.evalScripts();
736
737 }
738 var ck = $('ck' + nb.value);
739 ck.addEventListener('click', function (event) {
740 display_range_dcside(event, ck);
741 display_dcside(ck);
742 });
743
744
745 $("qc_" + nb.value).value = "";
746 $("amount" + nb.value).value = "";
747 $("poste" + nb.value).value = "";
748 $("ld" + nb.value).value = "";
749
750
751 nb.value++;
752
753}
754
755function RefreshMe() {
756 window.location.reload();
757}
758
759
760function go_next_concerned() {
761 var form = document.forms[1];
762
763 for (var e = 0; e < form.elements.length; e++) {
764 var elmt = form.elements[e];
765 if (elmt.type == "checkbox") {
766 if (elmt.checked == true) {
767 return confirm(content[52]);
768 }
769 }
770 }
771 return true;
772}
773
774/**
775 * View the history of an account
776 * @param {type} p_value
777 * @param {type} dossier
778 * @returns {undefined}
779 */
780function view_history_account(p_value, dossier, p_exercice) {
781 layer++;
782 var idbox = 'det' + layer;
783 var popup = {'id': idbox, 'cssclass': 'inner_box', 'html': loading(), 'drag': false};
784
785 var querystring = {
786 'gDossier': dossier,
787 'act': 'de',
788 'pcm_val': p_value,
789 'div': idbox,
790 'l': layer,
791 'op': 'history',
792 'exercice': p_exercice
793 };
794 waiting_box();
795
796 var action = new Ajax.Request(
797 "ajax_misc.php",
798 {
799 method: 'get',
800 parameters: querystring,
801 onFailure: error_box,
802 onSuccess: function (req, xml) {
803 remove_waiting_box();
804 if (req.responseText === 'NOCONX') { reconnect();return;}
805
806 add_div(popup);
807 success_box(req, xml);
808 $(idbox).style.top = calcy(140 + (layer * 3)) + "px";
809 }
810 }
811 );
812
813}
814
815/**
816 * View the history of an account
817 * @param {type} p_value
818 * @param {type} dossier
819 * @returns {undefined}
820 */
821function view_history_anc_account(p_value, dossier, p_exercice) {
822 layer++;
823 var idbox = 'det' + layer;
824 var popup = {'id': idbox, 'cssclass': 'inner_box', 'html': loading(), 'drag': false};
825
826 var querystring = {
827 'gDossier': dossier,
828 'op': 'history_anc_account',
829 'po_id': p_value,
830 'div': idbox,
831 'l': layer,
832 'act': 'history',
833 'exercice': p_exercice
834 };
835 waiting_box();
836
837 var action = new Ajax.Request(
838 "ajax_misc.php",
839 {
840 method: 'get',
841 parameters: querystring,
842 onFailure: error_box,
843 onSuccess: function (req, xml) {
844 remove_waiting_box();
845 if (req.responseText === 'NOCONX') { reconnect();return;}
846
847 add_div(popup);
848 $(idbox).innerHTML = req.responseText;
849 $(idbox).style.top = calcy(140 + (layer * 3)) + "px";
850 }
851 }
852 );
853
854}
855
856/**
857 * Change the view of account history
858 * @param {type} obj
859 * @returns {Boolean}
860 */
861function update_history_account(obj) {
862 try {
863 var querystring = {
864 "l": obj.div,
865 "div": obj.div,
866 "gDossier": obj.gDossier,
867 "pcm_val": obj.pcm_val,
868 "ex": obj.select.options[obj.select.selectedIndex].text,
869 "op": "history",
870 "exercice": obj.exercice
871 };
872 waiting_box();
873 var action = new Ajax.Request(
874 "ajax_misc.php",
875 {
876 method: 'get',
877 parameters: querystring,
878 onFailure: error_box,
879 onSuccess: function (req, xml) {
880 remove_waiting_box();
881 if (req.responseText === 'NOCONX') { reconnect();return;}
882
883 success_box(req, xml);
884 g(obj.div).style.top = calcy(140 + (layer * 3)) + "px";
885 }
886 });
887 } catch (e) {
888 alert_box("update_history_account error " + e.message);
889 }
890
891 return false;
892}
893
894/*!\brief Change the view of card history
895 * \param p_value f_id of the card
896 */
897function view_history_card(p_value, dossier, p_exercice) {
898 layer++;
899 var idbox = 'det' + layer;
900 var popup = {
901 'id': idbox,
902 'cssclass': 'inner_box',
903 'html': loading(),
904 'drag': false
905 };
906 var querystring = {
907 'gDossier': dossier,
908 'act': 'de',
909 'f_id': p_value,
910 'div': idbox,
911 "l": layer,
912 "op": "history",
913 "exercice": p_exercice
914 };
915 waiting_box();
916 var action = new Ajax.Request(
917 "ajax_misc.php",
918 {
919 method: 'get',
920 parameters: querystring,
921 onFailure: error_box,
922 onSuccess: function (req, xml) {
923 remove_waiting_box();
924 if (req.responseText === 'NOCONX') { reconnect();return;}
925
926 add_div(popup);
927 success_box(req, xml);
928 g(idbox).style.top = calcy(140 + (layer * 3)) + "px";
929 }
930 }
931 );
932}
933/*!
934 * \brief list followup of a card
935 * \param p_value int fiche.f_id of the card
936 */
937function view_followup_card(p_value, dossier) {
938 layer++;
939 var idbox = 'detfu' + layer;
940 var popup = {
941 'id': idbox,
942 'cssclass': 'inner_box',
943 'html': loading(),
944 'drag': false
945 };
946 var querystring = {
947 'gDossier': dossier,
948 'f_id': p_value,
949 'div': idbox,
950 "l": layer,
951 "op": "view_followup_card",
952 };
953 waiting_box();
954 var action = new Ajax.Request(
955 "ajax_misc.php",
956 {
957 method: 'get',
958 parameters: querystring,
959 onFailure: error_box,
960 onSuccess: function (req, xml) {
961 remove_waiting_box();
962 if (req.responseText === 'NOCONX') { reconnect();return;}
963
964 add_div(popup);
965 $(idbox).update(req.responseText);
966 g(idbox).style.top = calcy(140 + (layer * 3)) + "px";
967 }
968 }
969 );
970}
971
972/**
973 * update history view after changing the exercice
974 * @param {type} obj
975 * @returns {Boolean}
976 */
977function update_history_card(obj) {
978 try {
979 var querystring = {
980 "l": obj.div,
981 "div": obj.div,
982 "gDossier": obj.gDossier,
983 "f_id": obj.f_id,
984 "ex": obj.select.options[obj.select.selectedIndex].text,
985 "op": "history",
986 "exercice": obj.exercice
987 };
988 waiting_box();
989 var action = new Ajax.Request(
990 "ajax_misc.php",
991 {
992 method: 'get',
993 parameters: querystring,
994 onFailure: error_box,
995 onSuccess: function (req, xml) {
996 if (req.responseText === 'NOCONX') { reconnect();return;}
997
998 remove_waiting_box();
999 success_box(req, xml);
1000 g(obj.div).style.top = calcy(140 + (layer * 3)) + "px";
1001 }
1002 });
1003 } catch (e) {
1004 alert_box("update_history_account error " + e.message);
1005 }
1006
1007 return false;
1008}
1009
1010/**
1011 * remove an Operation
1012 *@param p_jr_id is the jrn.jr_id
1013 *@param dossier
1014 *@param the div
1015 */
1016function removeOperation(p_jr_id, dossier, div) {
1017 waiting_box();
1018 var qs = {
1019 "gDossier": dossier,
1020 "op": "ledger",
1021 "act": "rmop",
1022 "div": div,
1023 "jr_id": p_jr_id
1024 };
1025 new Ajax.Request(
1026 "ajax_misc.php",
1027 {
1028 method: 'get',
1029 parameters: qs,
1030 onFailure: error_box,
1031 onSuccess: infodiv
1032 }
1033 );
1034
1035}
1036
1037/**
1038 * reverse an Operation
1039 *@param pointer to the FORM
1040 */
1041function reverseOperation(obj) {
1042 var qs = $(obj).serialize() + "&op=ledger";
1043 g('ext' + obj.divname).style.display = 'none';
1044 waiting_box();
1045 new Ajax.Request(
1046 "ajax_misc.php",
1047 {
1048 method: 'get',
1049 parameters: qs,
1050 onFailure: error_box,
1051 onSuccess: function (req) {
1052 try {
1053 var action = new Ajax.Request(
1054 "ajax_misc.php",
1055 {
1056 method: 'get',
1057 parameters: {
1058 "gDossier": obj["gDossier"].value,
1059 "op": "ledger",
1060 "act": "de",
1061 "div": obj['div'].value,
1062 "jr_id": obj['jr_id'].value
1063 },
1064 onFailure: error_box,
1065 onSuccess: function (xml, txt) {
1066
1067 success_box(xml, txt);
1068 infodiv(req);
1069 }
1070 });
1071 } catch (ex) {
1072 smoke.alert(ex.message);
1073 }
1074 }
1075 }
1076 );
1077
1078 return false;
1079}
1080
1081/*!
1082 * \brief Show the details of an operation
1083 * \param p_value jrn.jr_id
1084 * \param dossier dossier id
1085 */
1086function modifyOperation(p_value, dossier) {
1087 layer++;
1088 var id_div = 'det' + layer;
1089 waiting_box();
1090 var querystring = {
1091 "gDossier": dossier,
1092 "op": "ledger",
1093 "act": "de",
1094 "div": id_div,
1095 "jr_id": p_value
1096 };
1097 var action = new Ajax.Request(
1098 "ajax_misc.php",
1099 {
1100 method: 'get',
1101 parameters: querystring,
1102 onFailure: error_box,
1103 onSuccess: function (xml, txt) {
1104 if (xml.responseText === 'NOCONX') {
1105 reconnect();
1106 return;
1107 }
1108 var popup = {
1109 'id': id_div, 'cssclass': 'inner_box'
1110 , 'html': "", 'drag': false
1111 };
1112 remove_waiting_box();
1113 add_div(popup);
1114 success_box(xml, txt);
1115 $(id_div).style.position = "absolute";
1116 $(id_div).style.top = calcy(100 + (layer * 3)) + "px";
1117 }
1118 }
1119 );
1120}
1121
1122/*!\brief
1123 * \param p_value jrn.jr_id
1124 */
1125
1126function viewOperation(p_value, p_dossier) {
1127 modifyOperation(p_value, p_dossier)
1128}
1129
1130function dropLink(p_dossier, p_div, p_jr_id, p_jr_id2) {
1131 var querystring = {
1132 "gDossier": p_dossier,
1133 "op": "ledger",
1134 "act": "rmr",
1135 "div": p_div,
1136 "jr_id": p_jr_id,
1137 "jr_id2": p_jr_id2
1138 };
1139 var action = new Ajax.Request('ajax_misc.php',
1140 {
1141 method: 'get',
1142 parameters: querystring,
1143 onFailure: null,
1144 onSuccess: null
1145 }
1146 );
1147}
1148
1149/**
1150 * this function is called before the querystring is send to the
1151 * fid2.php, add a filter based on the ledger 'p_jrn'
1152 *@param obj is the input field
1153 *@param queryString is the queryString to modify
1154 *@see ICard::input
1155 */
1156function filter_card(obj, queryString) {
1157 jrn = $('p_jrn').value;
1158 if (jrn == -1) {
1159 type = $('ledger_type').value;
1160 queryString = queryString + '&type=' + type;
1161 } else {
1162 queryString = queryString + '&j=' + jrn;
1163 }
1164 return queryString;
1165}
1166
1167/**
1168 * to display the lettering for the operation, call
1169 * ajax function
1170 *@param obj object attribut : gDossier,j_id,obj_type
1171 */
1172function dsp_letter(obj) {
1173 try {
1174 //var queryString = 'gDossier=' + obj.gDossier + '&j_id=' + obj.j_id + '&op=dl' + '&ot=' + obj.obj_type+'&start='+obj.start;
1175
1176 var action = new Ajax.Request(
1177 "ajax_misc.php",
1178 {
1179 method: 'get',
1180 parameters: obj,
1181 onFailure: error_dsp_letter,
1182 onSuccess: success_dsp_letter
1183 }
1184 );
1185 g('search').style.display = 'none';
1186 g('list').style.display = 'none';
1187 $('detail').innerHTML = loading();
1188 g('detail').style.display = 'block';
1189 } catch (e) {
1190 alert_box('dsp_letter failed ' + e.message);
1191 }
1192}
1193
1194function success_dsp_letter(req) {
1195 try {
1196 var answer = req.responseXML;
1197 var a = answer.getElementsByTagName('code');
1198 var html = answer.getElementsByTagName('value');
1199 if (a.length == 0) {
1200 var rec = req.responseText;
1201 alert_box('erreur :' + rec);
1202 }
1203 var name_ctl = a[0].firstChild.nodeValue;
1204 var code_html = getNodeText(html[0]);
1205 code_html = unescape_xml(code_html);
1206 $('detail').innerHTML = code_html;
1207 } catch (e) {
1208 alert_box(e.message);
1209 }
1210 try {
1211 code_html.evalScripts();
1212 } catch (e) {
1213 alert_box("DSPLETTER:" + content[48] + e.message);
1214 }
1215
1216}
1217
1218function error_dsp_letter(req) {
1219 alert_box("DSPLETTER:" + content[48]);
1220}
1221
1222function search_letter(obj) {
1223 try {
1224 var str_query = '';
1225 if (obj.elements['gDossier'])
1226 str_query = 'gDossier=' + obj.elements['gDossier'].value;
1227 if (obj.elements['j_id'])
1228 str_query += '&j_id=' + obj.elements['j_id'].value;
1229 if (obj.elements['obj_type'])
1230 str_query += '&obj_type=' + obj.elements['obj_type'].value;
1231 if (obj.elements['op'])
1232 str_query += '&op=' + obj.elements['op'].value;
1233 if (obj.elements['min_amount'])
1234 str_query += '&min_amount=' + obj.elements['min_amount'].value;
1235 if (obj.elements['max_amount'])
1236 str_query += '&max_amount=' + obj.elements['max_amount'].value;
1237 if (obj.elements['search_start'])
1238 str_query += '&search_start=' + obj.elements['search_start'].value;
1239 if (obj.elements['search_end'])
1240 str_query += '&search_end=' + obj.elements['search_end'].value;
1241 if (obj.elements['side'])
1242 str_query += '&side=' + obj.elements['side'].value;
1243
1244
1245 var action = new Ajax.Request(
1246 "ajax_misc.php",
1247 {
1248 method: 'get',
1249 parameters: str_query,
1250 onFailure: error_dsp_letter,
1251 onSuccess: success_dsp_letter
1252 }
1253 );
1254 $('list').hide();
1255 $('search').hide();
1256 $('detail').innerHTML = loading();
1257 $('detail').show();
1258 } catch (e) {
1259 alert_box('search_letter ' + e.message);
1260 }
1261}
1262
1263/**
1264 * save an operation in ajax, it concerns only the
1265 * comment, the pj and the rapt
1266 * the form elements are access by their name
1267 *@param obj form
1268 */
1269function op_save(obj) {
1270 try {
1271 var queryString = $(obj).serialize(true);
1272 queryString ["gDossier"] = obj.gDossier.value;
1273 var rapt2 = "rapt" + obj.whatdiv.value;
1274 queryString ["rapt"] = g(rapt2).value;
1275 queryString ["jr_id"] = obj.jr_id.value;
1276 var jr_id = obj.jr_id.value;
1277 queryString ["div"] = obj.whatdiv.value;
1278 var divid = obj.whatdiv.value;
1279 queryString ["act"] = "save";
1280 queryString ["op"] = "ledger";
1281
1282 waiting_box();
1283 /*
1284 * Operation detail is in a new window
1285 */
1286 if (g('inpopup')) {
1287 var action = new Ajax.Request('ajax_misc.php',
1288 {
1289 method: 'post',
1290 parameters: queryString,
1291 onFailure: null,
1292 onSuccess: function (req) {
1293 remove_waiting_box();
1294 var answer = req.getElementsByTagName('code');
1295 if (answer[0] !== 'OK') {
1296 console.error("D2. op_save")
1297 smoke.alert(req.responseText);
1298 }
1299 }
1300 }
1301 );
1302 // window.close();
1303 } else {
1304 /*
1305 *Operation is in a modal box
1306 */
1307 var action = new Ajax.Request('ajax_misc.php',
1308 {
1309 method: 'post',
1310 parameters: queryString,
1311 onFailure: null,
1312 onSuccess: function (req, json) {
1313
1314
1315 if (req.responseXML == null) {
1316 smoke.alert(req.responseText);
1317 }
1318 new Ajax.Request('ajax_misc.php', {
1319 parameters: {
1320 'gDossier': obj.gDossier.value,
1321 'act': 'de',
1322 'op': 'ledger',
1323 'jr_id': jr_id,
1324 'div': divid
1325 },
1326 onSuccess: function (xml) {
1327 try {
1328 var answer = xml.responseXML;
1329 var html = answer.getElementsByTagName('code');
1330 $(divid).innerHTML = unescape(getNodeText(html[0]));
1331 $(divid).innerHTML.evalScripts();
1332 remove_waiting_box();
1333 } catch (e) {
1334 console.error("D1. op_save")
1335 alert_box("1038" + e.message)
1336 }
1337 }
1338 });
1339
1340 }
1341 });
1342 }
1343 return false;
1344 } catch (e) {
1345 console.error("F1. op_save")
1346 alert_box(e.message);
1347 }
1348}
1349
1350function get_history_account(ctl, dossier) {
1351 if ($(ctl).value != '') {
1352 view_history_account($(ctl).value, dossier);
1353 }
1354}
1355
1356var previous = [];
1357var let_previous = "";
1358
1359function show_reconcile(p_div, p_let) {
1360 try {
1361 if (previous.length != 0 || p_let == let_previous) {
1362 var count_elt = previous.length;
1363 var i = 0;
1364 for (i = 0; i < count_elt; i++) {
1365 previous[i].style.backgroundColor = '';
1366 previous[i].style.color = '';
1367 previous[i].style.fontWeight = "";
1368 }
1369 }
1370 var name = 'tr_' + p_let + '_' + p_div;
1371 var elt = document.getElementsByName(name);
1372 if (p_let != let_previous) {
1373
1374 previous = elt;
1375 var count_elt = elt.length;
1376 var i = 0;
1377 for (i = 0; i < count_elt; i++) {
1378 elt[i].style.backgroundColor = '#000066';
1379 elt[i].style.color = 'white';
1380 elt[i].style.fontWeight = 'bolder';
1381
1382 }
1383 let_previous = p_let;
1384 } else {
1385 let_previous = "";
1386 }
1387
1388 } catch (e) {
1389 alert_box(e.message);
1390 }
1391
1392
1393}
1394
1395/**
1396 * add a line in the form for the purchase ledger
1397 */
1398function gestion_add_row() {
1399 try {
1400 style = 'class="input_text"';
1401 var mytable = g("art").tBodies[0];
1402 var ofirstRow = mytable.rows[1];
1403 var line = mytable.rows.length;
1404 var nCell = mytable.rows[1].cells.length;
1405 var row = mytable.insertRow(line);
1406 var nb = g("nb_item");
1407 for (var e = 0; e < nCell; e++) {
1408 var newCell = row.insertCell(e);
1409 var tt = ofirstRow.cells[e].innerHTML;
1410 var new_tt = tt.replace(/march0/g, "march" + nb.value);
1411 new_tt = new_tt.replace(/quant0/g, "quant" + nb.value);
1412 new_tt = new_tt.replace(/sold\‍(0\‍)/g, "sold(" + nb.value + ")");
1413 new_tt = new_tt.replace(/compute_ledger\‍(0\‍)/g, "compute_ledger(" + nb.value + ")");
1414 new_tt = new_tt.replace(/clean_tva\‍(0\‍)/g, "clean_tva(" + nb.value + ")");
1415 new_tt = new_tt + '<input type="hidden" id="tva_march' + nb.value + '">';
1416 new_tt = new_tt + '<input type="hidden" id="htva_march' + nb.value + '">';
1417 newCell.innerHTML = new_tt;
1418 if (mytable.rows[1].cells[e].hasClassName("num")) {
1419 newCell.addClassName("num");
1420 }
1421 new_tt.evalScripts();
1422 }
1423
1424 g("e_march" + nb.value + "_label").innerHTML = '&nbsp;';
1425 g("e_march" + nb.value + "_label").value = '';
1426 g("e_march" + nb.value + "_price").value = '0';
1427 g("e_march" + nb.value).value = "";
1428 g("e_quant" + nb.value).value = "1";
1429 g('tvac_march' + nb.value).value = "0";
1430 if ($("e_march" + nb.value + "_tva_amount"))
1431 g("e_march" + nb.value + "_tva_amount").value = 0;
1432
1433 nb.value++;
1434
1435 new_tt.evalScripts();
1436 } catch (e) {
1437 alert_box(e.message);
1438 }
1439
1440}
1441
1442function document_remove(p_dossier, p_div, p_jrid) {
1443 smoke.confirm(content[50], function (e) {
1444 if (e) {
1445 new Ajax.Request('ajax_misc.php',
1446 {
1447 parameters: {"op": "ledger", "gDossier": p_dossier, "div": p_div, "p_jrid": p_jrid, 'act': 'rmf'},
1448 onSuccess: function (x) {
1449 $('receipt' + p_div).innerHTML = x.responseText;
1450 }
1451 })
1452 }
1453 });
1454}
1455
1456/***
1457 * receive an object and display a list of filter + form to save one
1458 * fill up the span (id : {div}search_filter_span) with the name of the selected filter
1459 * Object = '{'div':'','type':'ALL','all_type':1,'dossier':'10104'}'
1460 * @see Acc_Ledger_Search
1461 */
1462function manage_search_filter(p_obj) {
1463 waiting_box();
1464 new Ajax.Request("ajax_misc.php", {
1465 method: 'get',
1466 parameters: {
1467 "op": "display_search_filter",
1468 "gDossier": p_obj.dossier,
1469 "div": p_obj.div,
1470 "ledger_type": p_obj.ledger_type,
1471 "all_type": p_obj.all_type
1472 },
1473 onSuccess: function (req) {
1474 remove_waiting_box();
1475 var x = posX;
1476 var y = calcy(200)
1477 create_div({
1478 'id': 'boxfilter' + p_obj.div,
1479 'cssclass': 'inner_box',
1480 'html': req.responseText,
1481 'style': 'top:' + y + 'px;left:' + x + 'px;position:absolute;width:400px',
1482 drag: 1
1483 });
1484 $('boxfilter' + p_obj.div).show();
1485 }
1486 });
1487}
1488
1489/**
1490 * Send data from the form and record a new filter , the ajax answer is a json object
1491 * with the attribute filter_name,filter_id,status,message
1492 *
1493 * @param p_div prefix id of all concerned DOM Element
1494 * @param p_dossier
1495 * @see Acc_Ledger_Search
1496 */
1497function save_filter(p_div, p_dossier) {
1498 var elt = ['ledger_type', 'nb_jrn', 'date_start', 'date_end',
1499 'date_paid_start', 'date_paid_end', 'desc', 'amount_min', 'amount_max', 'qcode', 'accounting',
1500 'operation_filter', 'tag_option', 'p_currency_code', 'tva_id_search'];
1501 var eltValue = {};
1502 var i = 0;
1503 eltValue['gDossier'] = p_dossier;
1504 eltValue['op'] = "save_filter";
1505 eltValue['div'] = p_div;
1506 eltValue['filter_name'] = $(p_div + "filter_new").value;
1507 // Get all elt from the form
1508 for (var i = 0; i < elt.length; i++) {
1509 var idx = elt[i];
1510 eltValue[idx] = $(p_div + elt[i]).value;
1511
1512 }
1513 if (eltValue['amount_min'] == "") eltValue["amount_min"] = 0;
1514 if (eltValue['amount_max'] == "") eltValue["amount_max"] = 0;
1515
1516 //ledger's list r_jrn
1517 if (eltValue['nb_jrn'] > 0) {
1518 eltValue['r_jrn'] = [];
1519 for (i = 0; i < eltValue['nb_jrn']; i++) {
1520 var idx = p_div + 'r_jrn[' + i + ']';
1521 eltValue['r_jrn' + i] = $(idx).value
1522
1523 }
1524 }
1525 //ledger's tags
1526 var aTag = Array.from(document.getElementsByName(p_div + "tag[]"));
1527 eltValue["tag[]"] = [];
1528 for (i = 0; i < aTag.length; i++) {
1529 eltValue["tag[]"][i] = aTag[i].value;
1530 }
1531 new Ajax.Request('ajax_misc.php', {
1532 method: "POST",
1533 parameters: eltValue,
1534 onSuccess: function (req) {
1535 try {
1536 var answer = req.responseJSON;
1537 if (answer.status == 'OK') {
1538 /*Add the new list to the selection */
1539 var new_item = document.createElement('li');
1540 new_item.innerHTML = answer.filter_name;
1541 new_item.setAttribute("id", "manageli" + p_div + "_" + answer.filter_id);
1542 $('manage' + p_div).appendChild(new_item);
1543 $(p_div + "filter_new").value = "";
1544 } else {
1545 throw answer.message;
1546 }
1547 } catch (e) {
1548 smoke.alert(e);
1549 }
1550 }
1551 });
1552}
1553
1554/**
1555 * Load a search filter and fill up the form search
1556 * @param p_div prefix id of all concerned DOM Element
1557 * @param p_dossier
1558 * @param p_filter_id filter id (SQL user_filter.id)
1559 * @see Acc_Ledger_Search
1560 */
1561function load_filter(p_div, p_dossier, p_filter_id) {
1562 new Ajax.Request('ajax_misc.php', {
1563 method: "get",
1564 parameters: {"gDossier": p_dossier, "div": p_div, "op": "load_filter", "filter_id": p_filter_id},
1565 onSuccess: function (req) {
1566 try {
1567 var answer = req.responseJSON;
1568 var elt = ['ledger_type', 'date_start', 'date_end', 'date_paid_start', 'date_paid_end',
1569 'desc', 'amount_min', 'amount_max', 'qcode', 'accounting', 'operation_filter', 'tag_option'
1570 , 'p_currency_code', 'tva_id_search'];
1571 for (var i = 0; i < elt.length; i++) {
1572 var idx = elt[i];
1573 $(p_div + idx).value = answer[elt[i]];
1574 }
1575 // fillup the r_jrn array
1576 var eltLedgerId = $("ledger_id" + p_div);
1577 eltLedgerId.innerHTML = "";
1578 var eltHidden = document.createElement("input");
1579 eltHidden.setAttribute("name", p_div + "nb_jrn");
1580 eltHidden.setAttribute("type", "hidden");
1581 eltHidden.setAttribute("id", p_div + "nb_jrn");
1582 eltHidden.setAttribute("value", answer.nb_jrn);
1583 eltLedgerId.appendChild(eltHidden);
1584
1585 for (var i = 0; i < answer.nb_jrn; i++) {
1586 // create hidden element and add them into eltLedgerId
1587 var eltHidden = document.createElement("input");
1588
1589 eltHidden.setAttribute("name", p_div + "r_jrn[" + i + "]");
1590 eltHidden.setAttribute("type", "hidden");
1591 eltHidden.setAttribute("id", p_div + "r_jrn[" + i + "]");
1592 eltHidden.setAttribute("value", answer.r_jrn[i]);
1593 eltLedgerId.appendChild(eltHidden);
1594 }
1595 new Ajax.Request("ajax_misc.php", {
1596 method: "get",
1597 parameters: {
1598 "gDossier": p_dossier, "div": p_div, "op": "display_filter_tag", "filter_id": p_filter_id,
1599 uf_tag: answer.uf_tag
1600 },
1601 onSuccess: function (req) {
1602 $(p_div + 'tag_choose_td').update(req.responseText);
1603 }
1604 })
1605
1606
1607 } catch (e) {
1608 smoke.alert(e.message);
1609 }
1610
1611 }
1612 });
1613}
1614
1615/**
1616 * delete a saved search filter from the db, it is limited to the current
1617 * user
1618 * @parameter p_div
1619 identification des elements LI manageli{div}_{filter_id}
1620 identification element UL manage{div}
1621 @parameter p_filter_id SQL user_filter.id
1622 */
1623
1624function delete_filter(p_div, p_dossier, p_filter_id) {
1625 new Ajax.Request("ajax_misc.php", {
1626 parameters: {"gDossier": p_dossier, "div": p_div, "filter_id": p_filter_id, 'op': "delete_search_operation"},
1627 method: "POST",
1628 onSuccess: function (req) {
1629 try {
1630 var answer = req.evalJSON;
1631
1632 var child = $("manageli" + p_div + "_" + p_filter_id);
1633 if (child) {
1634 $("manage" + p_div).removeChild(child);
1635 }
1636 } catch (e) {
1637 console.log(e.message)
1638 }
1639
1640 }
1641 })
1642
1643}
1644
1645/**
1646 * Reset the search_form and reinitialize all the input but ledger_type
1647 * @param p_div prefix for DOM Element
1648 */
1649function reset_filter(p_div) {
1650 // clean all the input fields but ledger_type remains
1651 var elt = ['date_start', 'date_end', 'date_paid_start', 'date_paid_end', 'desc', 'amount_min', 'amount_max', 'qcode', 'accounting', 'tva_id_search'];
1652 for (var i = 0; i < elt.length; i++) {
1653 var idx = elt[i];
1654 $(p_div + idx).value = "";
1655 }
1656 if ($(p_div + "date_start_hidden")) {
1657 $(p_div + "date_start").value = $(p_div + "date_start_hidden").value;
1658 }
1659 if ($(p_div + "date_end_hidden")) {
1660 $(p_div + "date_end").value = $(p_div + "date_end_hidden").value;
1661 }
1662 // clean all the selected ledger
1663 var eltLedgerId = $("ledger_id" + p_div);
1664 eltLedgerId.innerHTML = "";
1665 var eltHidden = document.createElement("input");
1666 eltHidden.setAttribute("name", p_div + "nb_jrn");
1667 eltHidden.setAttribute("type", "hidden");
1668 eltHidden.setAttribute("id", p_div + "nb_jrn");
1669 eltHidden.setAttribute("value", 0);
1670 eltLedgerId.appendChild(eltHidden);
1671
1672 // By default , unpaid is uncked
1673 $(p_div + "operation_filter").value = "all";
1674}
1675function display_list_filter(p_dossier,access_code,ledger_type)
1676{
1677 new Ajax.Request("ajax_misc.php",{
1678 parameters:{"gDossier":p_dossier
1679 ,"op":"display_list_filter"
1680 ,"ac":access_code
1681 ,'ledger_type':ledger_type
1682 },
1683 method:'GET',
1684 onSuccess: function (responseHtml) {
1685 try {
1686 var posy=calcy(250)
1687 var div = create_div({"id":"display_list_filter_div",
1688 'cssclass': "inner_box", 'style': 'width:90%,right:5%;top:'+posy+"px"});
1689 div.update(responseHtml.responseText);
1690 div.show();
1691 }catch (e) {
1692 console.error(e.message);
1693 }
1694 }
1695 })
1696}
1697
1698/**
1699 * propose to duplicate an operation
1700 */
1701function duplicate_operation(p_dossier, p_jr_id) {
1702 waiting_box();
1703 var duplicate_div = create_div({id: "duplicate_operation_div", cssclass: "inner_box"});
1704
1705 new Ajax.Request("ajax_misc.php", {
1706 parameters: {
1707 "op": "ledger",
1708 "gDossier": p_dossier,
1709 "jr_id": p_jr_id,
1710 "act": "duplicateop",
1711 "div": "duplicate_operation_div"
1712 },
1713 onSuccess: function (req) {
1714 remove_waiting_box();
1715 var xml = req.responseXML;
1716
1717 if (xml.getElementsByTagName("ctl").length == 0) {
1718 console.log("erreur" + req.responseText);
1719 }
1720 add_div(duplicate_div);
1721
1722 duplicate_div.setStyle({
1723 "position": "fixed", "top": "15%", "z-index": "999",
1724 "min-width": "30rem",
1725 "left": "30%",
1726 "width": "40%"
1727 });
1728 duplicate_div.innerHTML = getNodeText(xml.getElementsByTagName("code")[0]);
1729 duplicate_div.setStyle({display: "block"});
1730 }
1731 }
1732 );
1733}
1734
1735/**
1736 * For operation_exercice let update periode when changing folder
1737 * @type {{update_periode: operation_exercice.update_periode}}
1738 */
1739var operation_exercice = {
1740 update_periode: function (dossier_id) {
1741 try {
1742 waiting_box();
1743 var queryString = {
1744 op: 'operation_exercice+update_periode',
1745 folder: $('dos_id').value,
1746 gDossier: dossier_id
1747 };
1748 var action = new Ajax.Request(
1749 "ajax_misc.php",
1750 {
1751 method: 'GET',
1752 parameters: queryString,
1753 onFailure: ajax_misc_failure,
1754 onSuccess: function (req) {
1755 remove_waiting_box();
1756 if (req.responseText == 'NOCONX') {
1757 reconnect();
1758 return;
1759 }
1760
1761 $("select_exercice_id").update(req.responseText);
1762
1763 }
1764 }
1765 );
1766 } catch (e) {
1767 console.error('oe-update_periode', e.message);
1768 }
1769 },
1770 modify_row: function (row_operation_exercice, oe_id) {
1771 try {
1772 var dgbox = "operation_exercice_bx";
1773 waiting_box();
1774 removeDiv(dgbox);
1775 // For form , most of the parameters are in the FORM
1776 // method is then POST
1777 //var queryString=$(p_form_id).serialize(true);
1778 console.debug(row_operation_exercice);
1779 var queryString = {
1780 op: 'operation_exercice+modify_row',
1781 oe_id: oe_id,
1782 row_id: row_operation_exercice,
1783 gDossier: $('gDossier').value
1784 };
1785 var action = new Ajax.Request(
1786 "ajax_misc.php",
1787 {
1788 method: 'POST',
1789 parameters: queryString,
1790 onFailure: ajax_misc_failure,
1791 onSuccess: function (req) {
1792 remove_waiting_box();
1793 if (req.responseText == 'NOCONX') {
1794 reconnect();
1795 return;
1796 }
1797 console.debug(req.responseText)
1798 var y = calcy(15);
1799 var div_style = "position:absolute;" + ";top:" + y + "px";
1800 add_div({id: dgbox, cssclass: 'inner_box', html: loading(), style: div_style, drag: true});
1801 $(dgbox).update(req.responseText);
1802 }
1803 }
1804 );
1805 } catch (e) {
1806 console.error('oe-modify_row', e.message);
1807 }
1808 },
1809 /**
1810 * Save data from modify_row
1811 */
1812 save_row: function () {
1813 try {
1814 var dgbox = "operation_exercice_bx";
1815 waiting_box();
1816
1817 // For form , most of the parameters are in the FORM
1818 // method is then POST
1819 //var queryString=$(p_form_id).serialize(true);
1820
1821 var queryString = $('operation_exercice_input_row_frm').serialize(true);
1822
1823 var action = new Ajax.Request(
1824 "ajax_misc.php",
1825 {
1826 method: 'POST',
1827 parameters: queryString,
1828 onFailure: ajax_misc_failure,
1829 onSuccess: function (req) {
1830 remove_waiting_box();
1831 if (req.responseText == 'NOCONX') {
1832 reconnect();
1833 return;
1834 }
1835
1836 if (req.responseJSON['status'] == "OK") {
1837 rowid = req.responseJSON['row_id'];
1838 if (queryString['row_id'] == -1) {
1839 var row = new Element("tr");
1840 row.id = "oe_" + rowid;
1841 row.setAttribute("oed_id", rowid);
1842 row.setAttribute("oe_id", req.responseJSON['oe_id']);
1843 row.update(req.responseJSON['content']);
1844 $("operation_exercice_tb").appendChild(row);
1845 row.addEventListener("click", function (event) {
1846 operation_exercice.click_modify_row(row)
1847 })
1848
1849 } else {
1850 $("oe_" + rowid).update(req.responseJSON['content']);
1851 }
1852 new Effect.Highlight("oe_" + req.responseJSON['row_id'], {
1853 startcolor: '#FAD4D4',
1854 endcolor: '#F78082'
1855 });
1856 operation_exercice.display_total(rowid)
1857 $(dgbox).remove();
1858 return;
1859
1860 }
1861 $(dgbox).update(req.responseText);
1862
1863 }
1864 }
1865 );
1866 } catch (e) {
1867 console.error('oe-save_row' + e.message);
1868 }
1869 },
1870 /**
1871 * display the balance
1872 */
1873 display_total: function (row_id) {
1874 try {
1875 var dgbox = "tot_ope_exe";
1876 var queryString = {
1877 op: 'operation_exercice+display_total',
1878 row_id: row_id,
1879 gDossier: $('gDossier').value
1880 };
1881 var action = new Ajax.Request(
1882 "ajax_misc.php",
1883 {
1884 method: 'GET',
1885 parameters: queryString,
1886 onFailure: ajax_misc_failure,
1887 onSuccess: function (req) {
1888 remove_waiting_box();
1889 if (req.responseText == 'NOCONX') {
1890 reconnect();
1891 return;
1892 }
1893
1894 $(dgbox).update(req.responseText);
1895
1896 }
1897 }
1898 );
1899 } catch (e) {
1900 console.error('oe-display_total' + e.message);
1901 }
1902 },
1903 /**
1904 * delete a row
1905 */
1906 delete_row: function (row_id) {
1907 try {
1908 var queryString = {
1909 op: 'operation_exercice+delete_row',
1910 row_id: row_id,
1911 gDossier: $('gDossier').value
1912 };
1913 var action = new Ajax.Request(
1914 "ajax_misc.php",
1915 {
1916 method: 'GET',
1917 parameters: queryString,
1918 onFailure: ajax_misc_failure,
1919 onSuccess: function (req) {
1920 remove_waiting_box();
1921 if (req.responseText == 'NOCONX') {
1922 reconnect();
1923 return;
1924 }
1925 if (req.responseJSON["row_id"] != "") {
1926 operation_exercice.display_total(req.responseJSON["row_id"])
1927 }
1928 $('oe_' + queryString['row_id']).remove();
1929 $('operation_exercice_bx').remove();
1930 }
1931 }
1932 );
1933 } catch (e) {
1934 alert_box("oe+delete_row", e.message);
1935 }
1936 },
1937 click_modify_row: function (item) {
1938 operation_exercice.modify_row(item.getAttribute("oed_id"), item.getAttribute("oe_id"));
1939 },
1940 /**
1941 * check and transfer if it is good
1942 */
1943 transfer: function () {
1944 try {
1945 var dgbox = "oe_transfer_div";
1946 waiting_box();
1947
1948 var queryString = $("operation_exercice_transfer_frm").serialize(true);
1949 var action = new Ajax.Request(
1950 "ajax_misc.php",
1951 {
1952 method: 'GET',
1953 parameters: queryString,
1954 onFailure: ajax_misc_failure,
1955 onSuccess: function (req) {
1956 remove_waiting_box();
1957 if (req.responseText == 'NOCONX') {
1958 reconnect();
1959 return;
1960 }
1961 var answer=req.responseJSON;
1962console.debug(answer['content']);
1963 $('operation_exercice_transfer_info').update(answer.content);
1964
1965
1966 }
1967 }
1968 );
1969 } catch (e) {
1970 alert_box(e.message);
1971 }
1972 }
1973}