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
24 * \brief javascript script for the ledger in accountancy,
25 * compute the sum, add a row at the table..
32 * \brief update the list of available predefined operation when we change the ledger.
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(
43 parameters: querystring,
44 onFailure: error_get_predef,
45 onSuccess: function (req) {
47 $('info_div').innerHTML = "ok";
48 var answer = req.responseXML;
49 var a = answer.getElementsByTagName('code');
50 var html = answer.getElementsByTagName('value');
52 var rec = req.responseText;
53 alert_box(content[48] + rec);
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;
60 $('info_div').innerHTML = e.message;
68 * update the list of payment method when we change the ledger.
70function update_pay_method() {
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(
79 parameters: querystring,
80 onFailure: error_get_predef,
81 onSuccess: function (req) {
83 var answer = req.responseText;
84 $('payment').innerHTML = answer;
91 * update the list of additional tax
93function update_other_tax() {
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(
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;
115 * update ctl id =jrn_name with the value of p_jrn
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(
125 parameters: querystring,
126 onFailure: error_get_pj,
127 onSuccess: function (req) {
128 $('jrn_name_div').innerHTML = req.responseText;
136 * update the field predef
138function error_get_predef(request, json) {
139 alert_box(content[49]);
144 * update the list of available predefined operation when we change the ledger.
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(
154 parameters: querystring,
155 onFailure: error_get_pj,
156 onSuccess: success_get_pj
162 * ask the name, quick_code of the bank for the ledger
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(
173 onFailure: error_get_pj,
174 onSuccess: success_update_bank
181 * Update the number of rows when changing of ledger
183function update_row(ctl) {
185 var row_to_keep = 3; /* Number of row to keep (head and foot)*/
186 if (ctl === 'quick_item') {
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(
199 onSuccess: function (request, json) {
201 var answer = request.responseText.evalJSON(true);
202 var row = parseFloat(answer.row);
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;
217 cell0Element.forEach(function (x) {
218 if (canDelete && x.nodeName == 'INPUT' && x.type === "text" && x.value) {
225 * For ODS we also need to check the second column
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) {
237 table_to_update.deleteRow(pos_row - row_to_keep);
242 $('nb_item').value = table_to_update.rows.length - row_to_keep;
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();
251 if (ctl == 'sold_item') {
254 if (ctl == 'quick_item') {
255 quick_writing_add_row();
260 alert_box("update_row:01" + e.message);
266 alert_box(e.message);
271 * @brief hide or show the column quantity
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(
281 parameters: querystring,
282 onSuccess: function (req) {
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');
292 if (req.responseText == "1") {
293 // show the columns quantity and return
294 quantity_col[i].show();
295 quantity_col[i].removeClassName('d-none');
299 console.error("update_visibility_quantity" + e.message);
309 * Put into the span, the name of the bank, the bank account
312function success_update_bank(req) {
314 var answer = req.responseXML;
315 var a = answer.getElementsByTagName('code');
316 var html = answer.getElementsByTagName('value');
318 var rec = req.responseText;
319 alert_box('UPDBK-' + content[48] + rec);
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;
326 alert_box("success_update_bank" + e.message);
331 * call ajax, ask what is the last date for the current ledger
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(
342 onFailure: error_get_pj,
343 onSuccess: success_get_last_date
349 * callback ajax, set the ctl with the last date from the ledger
351function success_get_last_date(req) {
353 var answer = req.responseXML;
354 var a = answer.getElementsByTagName('code');
355 var html = answer.getElementsByTagName('value');
357 var rec = req.responseText;
358 alert_box('GETLASTDA:' + content[48] + rec);
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;
365 alert_box(e.message);
370 * update the field predef
372function success_get_pj(request, json) {
374 var answer = request.responseText.evalJSON(true);
377 if (answer.length == 0)
379 obj.value = answer.pj;
380 g("e_pj_suggest").value = answer.pj;
384 * update the field predef
386function error_get_pj(request, json) {
387 alert_box("GETPJ:" + content[48]);
391 * add a line in the form for the ledger fin
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);
404 newCell.id = 'tdchdate' + nb.value;
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();
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 = "";
424 var ch = $('chdate').options[$('chdate').selectedIndex].value;
426 $('tdchdate' + nb.value).hide();
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
435function ledger_add_multiple(p_elid) {
436 var nbrow = $(p_elid).value;
440 var type_ledger = $(p_elid + "_ledger").value;
442 for (i = 0; i < nbrow; i++) {
443 if (type_ledger == 'O') {
446 if (type_ledger == 'F') {
447 ledger_fin_add_row();
449 if (type_ledger == 'M') {
450 quick_writing_add_row();
453 if (type_ledger == 'M') {
454 var aCheckBox = $$('.debit-credit')
455 aCheckBox.forEach((item) => display_dcside(item))
460 * add a line in the form for the purchase ledger
461 * @param p_dossier folder id
462 * @param p_table_name
464function ledger_add_row() {
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();
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;
496 new_tt.evalScripts();
498 alert_box(e.message);
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
507function compute_ledger(p_ctl_nb) {
508 var dossier = g("gDossier").value;
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;
514 if (!document.getElementById("e_march" + p_ctl_nb)) {
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;
520 if (qcode.length == 0) {
521 clean_ledger(p_ctl_nb);
526 * if tva_id is empty send a value of -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) == '') {
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;
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;
551 'other_tax_id': other_tax_id
553 var action = new Ajax.Request(
557 parameters: querystring,
558 onFailure: error_compute_ledger,
559 onSuccess: success_compute_ledger
565 * refresh the purchase screen, recompute vat, total...
567function refresh_ledger() {
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;
584 id_other_tax = g("other_tax_amount");
586 id_tva.innerHTML = Math.round(tva * 100) / 100;
588 id_htva.innerHTML = Math.round(htva * 100) / 100;
590 let total_operation = tvac + parseFloat(id_other_tax.value);
591 $('total_operation_other_tax').innerHTML = Math.round(total_operation * 100) / 100;
594 id_tvac.innerHTML = Math.round(tvac * 100) / 100;
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
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")
612 other_tax.value = answer.other_tax;
615 var rhtva = answer.htva * 1;
616 g('htva_march' + ctl).value = rhtva;
617 g('tvac_march' + ctl).value = rtvac;
620 CurrencyCompute('p_currency_rate', 'p_currency_euro');
624 rtva = answer.tva * 1;
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;
632 g('tva_march' + ctl).value = g('e_march' + ctl + '_tva_amount').value;
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;
639 CurrencyCompute('p_currency_rate', 'p_currency_euro');
644 * callback error function for compute_sold
646function error_compute_ledger(request, json) {
647 alert_box('Ajax does not work');
650function compute_all_ledger() {
652 let nb_item = g("nb_item").value;
653 for (loop = 0; loop < nb_item; loop++) {
654 compute_ledger(loop);
660 for (var i = 0; i < nb_item; i++) {
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;
668 id_other_tax = g("other_tax_amount");
670 g('tva').innerHTML = Math.round(tva * 100) / 100;
672 g('htva').innerHTML = Math.round(htva * 100) / 100;
674 tvac += id_other_tax.value;
677 g('tvac').innerHTML = Math.round(tvac * 100) / 100;
682function clean_tva(p_ctl) {
683 if (g('e_march' + p_ctl + '_tva_amount'))
684 g('e_march' + p_ctl + '_tva_amount').value = 0;
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);
691 if (g('e_march' + p_ctl_nb + '_price')) {
692 g('e_march' + p_ctl_nb + '_price').value = '';
694 if (g('e_quant' + p_ctl_nb)) {
695 g('e_quant' + p_ctl_nb).value = '1';
697 if (g('tva_march' + p_ctl_nb + '_show')) {
698 g('tva_march' + p_ctl_nb + '_show').value = '0';
700 if (g('tva_march' + p_ctl_nb)) {
701 g('tva_march' + p_ctl_nb).value = 0;
703 if (g('htva_march' + p_ctl_nb)) {
704 g('htva_march' + p_ctl_nb).value = 0;
706 if (g('tvac_march' + p_ctl_nb)) {
707 g('tvac_march' + p_ctl_nb).value = 0;
713 * add a line in the form for the quick_writing
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");
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();
738 var ck = $('ck' + nb.value);
739 ck.addEventListener('click', function (event) {
740 display_range_dcside(event, ck);
745 $("qc_" + nb.value).value = "";
746 $("amount" + nb.value).value = "";
747 $("poste" + nb.value).value = "";
748 $("ld" + nb.value).value = "";
755function RefreshMe() {
756 window.location.reload();
760function go_next_concerned() {
761 var form = document.forms[1];
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]);
775 * View the history of an account
776 * @param {type} p_value
777 * @param {type} dossier
778 * @returns {undefined}
780function view_history_account(p_value, dossier, p_exercice) {
782 var idbox = 'det' + layer;
783 var popup = {'id': idbox, 'cssclass': 'inner_box', 'html': loading(), 'drag': false};
792 'exercice': p_exercice
796 var action = new Ajax.Request(
800 parameters: querystring,
801 onFailure: error_box,
802 onSuccess: function (req, xml) {
803 remove_waiting_box();
804 if (req.responseText === 'NOCONX') { reconnect();return;}
807 success_box(req, xml);
808 $(idbox).style.top = calcy(140 + (layer * 3)) + "px";
816 * View the history of an account
817 * @param {type} p_value
818 * @param {type} dossier
819 * @returns {undefined}
821function view_history_anc_account(p_value, dossier, p_exercice) {
823 var idbox = 'det' + layer;
824 var popup = {'id': idbox, 'cssclass': 'inner_box', 'html': loading(), 'drag': false};
828 'op': 'history_anc_account',
833 'exercice': p_exercice
837 var action = new Ajax.Request(
841 parameters: querystring,
842 onFailure: error_box,
843 onSuccess: function (req, xml) {
844 remove_waiting_box();
845 if (req.responseText === 'NOCONX') { reconnect();return;}
848 $(idbox).innerHTML = req.responseText;
849 $(idbox).style.top = calcy(140 + (layer * 3)) + "px";
857 * Change the view of account history
861function update_history_account(obj) {
866 "gDossier": obj.gDossier,
867 "pcm_val": obj.pcm_val,
868 "ex": obj.select.options[obj.select.selectedIndex].text,
870 "exercice": obj.exercice
873 var action = new Ajax.Request(
877 parameters: querystring,
878 onFailure: error_box,
879 onSuccess: function (req, xml) {
880 remove_waiting_box();
881 if (req.responseText === 'NOCONX') { reconnect();return;}
883 success_box(req, xml);
884 g(obj.div).style.top = calcy(140 + (layer * 3)) + "px";
888 alert_box("update_history_account error " + e.message);
894/*!\brief Change the view of card history
895 * \param p_value f_id of the card
897function view_history_card(p_value, dossier, p_exercice) {
899 var idbox = 'det' + layer;
902 'cssclass': 'inner_box',
913 "exercice": p_exercice
916 var action = new Ajax.Request(
920 parameters: querystring,
921 onFailure: error_box,
922 onSuccess: function (req, xml) {
923 remove_waiting_box();
924 if (req.responseText === 'NOCONX') { reconnect();return;}
927 success_box(req, xml);
928 g(idbox).style.top = calcy(140 + (layer * 3)) + "px";
934 * \brief list followup of a card
935 * \param p_value int fiche.f_id of the card
937function view_followup_card(p_value, dossier) {
939 var idbox = 'detfu' + layer;
942 'cssclass': 'inner_box',
951 "op": "view_followup_card",
954 var action = new Ajax.Request(
958 parameters: querystring,
959 onFailure: error_box,
960 onSuccess: function (req, xml) {
961 remove_waiting_box();
962 if (req.responseText === 'NOCONX') { reconnect();return;}
965 $(idbox).update(req.responseText);
966 g(idbox).style.top = calcy(140 + (layer * 3)) + "px";
973 * update history view after changing the exercice
977function update_history_card(obj) {
982 "gDossier": obj.gDossier,
984 "ex": obj.select.options[obj.select.selectedIndex].text,
986 "exercice": obj.exercice
989 var action = new Ajax.Request(
993 parameters: querystring,
994 onFailure: error_box,
995 onSuccess: function (req, xml) {
996 if (req.responseText === 'NOCONX') { reconnect();return;}
998 remove_waiting_box();
999 success_box(req, xml);
1000 g(obj.div).style.top = calcy(140 + (layer * 3)) + "px";
1004 alert_box("update_history_account error " + e.message);
1011 * remove an Operation
1012 *@param p_jr_id is the jrn.jr_id
1016function removeOperation(p_jr_id, dossier, div) {
1019 "gDossier": dossier,
1030 onFailure: error_box,
1038 * reverse an Operation
1039 *@param pointer to the FORM
1041function reverseOperation(obj) {
1042 var qs = $(obj).serialize() + "&op=ledger";
1043 g('ext' + obj.divname).style.display = 'none';
1050 onFailure: error_box,
1051 onSuccess: function (req) {
1053 var action = new Ajax.Request(
1058 "gDossier": obj["gDossier"].value,
1061 "div": obj['div'].value,
1062 "jr_id": obj['jr_id'].value
1064 onFailure: error_box,
1065 onSuccess: function (xml, txt) {
1067 success_box(xml, txt);
1072 smoke.alert(ex.message);
1082 * \brief Show the details of an operation
1083 * \param p_value jrn.jr_id
1084 * \param dossier dossier id
1086function modifyOperation(p_value, dossier) {
1088 var id_div = 'det' + layer;
1091 "gDossier": dossier,
1097 var action = new Ajax.Request(
1101 parameters: querystring,
1102 onFailure: error_box,
1103 onSuccess: function (xml, txt) {
1104 if (xml.responseText === 'NOCONX') {
1109 'id': id_div, 'cssclass': 'inner_box'
1110 , 'html': "", 'drag': false
1112 remove_waiting_box();
1114 success_box(xml, txt);
1115 $(id_div).style.position = "absolute";
1116 $(id_div).style.top = calcy(100 + (layer * 3)) + "px";
1123 * \param p_value jrn.jr_id
1126function viewOperation(p_value, p_dossier) {
1127 modifyOperation(p_value, p_dossier)
1130function dropLink(p_dossier, p_div, p_jr_id, p_jr_id2) {
1132 "gDossier": p_dossier,
1139 var action = new Ajax.Request('ajax_misc.php',
1142 parameters: querystring,
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
1156function filter_card(obj, queryString) {
1157 jrn = $('p_jrn').value;
1159 type = $('ledger_type').value;
1160 queryString = queryString + '&type=' + type;
1162 queryString = queryString + '&j=' + jrn;
1168 * to display the lettering for the operation, call
1170 *@param obj object attribut : gDossier,j_id,obj_type
1172function dsp_letter(obj) {
1174 //var queryString = 'gDossier=' + obj.gDossier + '&j_id=' + obj.j_id + '&op=dl' + '&ot=' + obj.obj_type+'&start='+obj.start;
1176 var action = new Ajax.Request(
1181 onFailure: error_dsp_letter,
1182 onSuccess: success_dsp_letter
1185 g('search').style.display = 'none';
1186 g('list').style.display = 'none';
1187 $('detail').innerHTML = loading();
1188 g('detail').style.display = 'block';
1190 alert_box('dsp_letter failed ' + e.message);
1194function success_dsp_letter(req) {
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);
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;
1208 alert_box(e.message);
1211 code_html.evalScripts();
1213 alert_box("DSPLETTER:" + content[48] + e.message);
1218function error_dsp_letter(req) {
1219 alert_box("DSPLETTER:" + content[48]);
1222function search_letter(obj) {
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;
1245 var action = new Ajax.Request(
1249 parameters: str_query,
1250 onFailure: error_dsp_letter,
1251 onSuccess: success_dsp_letter
1256 $('detail').innerHTML = loading();
1259 alert_box('search_letter ' + e.message);
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
1269function op_save(obj) {
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";
1284 * Operation detail is in a new window
1287 var action = new Ajax.Request('ajax_misc.php',
1290 parameters: queryString,
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);
1305 *Operation is in a modal box
1307 var action = new Ajax.Request('ajax_misc.php',
1310 parameters: queryString,
1312 onSuccess: function (req, json) {
1315 if (req.responseXML == null) {
1316 smoke.alert(req.responseText);
1318 new Ajax.Request('ajax_misc.php', {
1320 'gDossier': obj.gDossier.value,
1326 onSuccess: function (xml) {
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();
1334 console.error("D1. op_save")
1335 alert_box("1038" + e.message)
1345 console.error("F1. op_save")
1346 alert_box(e.message);
1350function get_history_account(ctl, dossier) {
1351 if ($(ctl).value != '') {
1352 view_history_account($(ctl).value, dossier);
1357var let_previous = "";
1359function show_reconcile(p_div, p_let) {
1361 if (previous.length != 0 || p_let == let_previous) {
1362 var count_elt = previous.length;
1364 for (i = 0; i < count_elt; i++) {
1365 previous[i].style.backgroundColor = '';
1366 previous[i].style.color = '';
1367 previous[i].style.fontWeight = "";
1370 var name = 'tr_' + p_let + '_' + p_div;
1371 var elt = document.getElementsByName(name);
1372 if (p_let != let_previous) {
1375 var count_elt = elt.length;
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';
1383 let_previous = p_let;
1389 alert_box(e.message);
1396 * add a line in the form for the purchase ledger
1398function gestion_add_row() {
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");
1421 new_tt.evalScripts();
1424 g("e_march" + nb.value + "_label").innerHTML = ' ';
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;
1435 new_tt.evalScripts();
1437 alert_box(e.message);
1442function document_remove(p_dossier, p_div, p_jrid) {
1443 smoke.confirm(content[50], function (e) {
1445 new Ajax.Request('ajax_misc.php',
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;
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
1462function manage_search_filter(p_obj) {
1464 new Ajax.Request("ajax_misc.php", {
1467 "op": "display_search_filter",
1468 "gDossier": p_obj.dossier,
1470 "ledger_type": p_obj.ledger_type,
1471 "all_type": p_obj.all_type
1473 onSuccess: function (req) {
1474 remove_waiting_box();
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',
1484 $('boxfilter' + p_obj.div).show();
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
1493 * @param p_div prefix id of all concerned DOM Element
1495 * @see Acc_Ledger_Search
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'];
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++) {
1510 eltValue[idx] = $(p_div + elt[i]).value;
1513 if (eltValue['amount_min'] == "") eltValue["amount_min"] = 0;
1514 if (eltValue['amount_max'] == "") eltValue["amount_max"] = 0;
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
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;
1531 new Ajax.Request('ajax_misc.php', {
1533 parameters: eltValue,
1534 onSuccess: function (req) {
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 = "";
1545 throw answer.message;
1555 * Load a search filter and fill up the form search
1556 * @param p_div prefix id of all concerned DOM Element
1558 * @param p_filter_id filter id (SQL user_filter.id)
1559 * @see Acc_Ledger_Search
1561function load_filter(p_div, p_dossier, p_filter_id) {
1562 new Ajax.Request('ajax_misc.php', {
1564 parameters: {"gDossier": p_dossier, "div": p_div, "op": "load_filter", "filter_id": p_filter_id},
1565 onSuccess: function (req) {
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++) {
1573 $(p_div + idx).value = answer[elt[i]];
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);
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");
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);
1595 new Ajax.Request("ajax_misc.php", {
1598 "gDossier": p_dossier, "div": p_div, "op": "display_filter_tag", "filter_id": p_filter_id,
1599 uf_tag: answer.uf_tag
1601 onSuccess: function (req) {
1602 $(p_div + 'tag_choose_td').update(req.responseText);
1608 smoke.alert(e.message);
1616 * delete a saved search filter from the db, it is limited to the current
1619 identification des elements LI manageli{div}_{filter_id}
1620 identification element UL manage{div}
1621 @parameter p_filter_id SQL user_filter.id
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"},
1628 onSuccess: function (req) {
1630 var answer = req.evalJSON;
1632 var child = $("manageli" + p_div + "_" + p_filter_id);
1634 $("manage" + p_div).removeChild(child);
1637 console.log(e.message)
1646 * Reset the search_form and reinitialize all the input but ledger_type
1647 * @param p_div prefix for DOM Element
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++) {
1654 $(p_div + idx).value = "";
1656 if ($(p_div + "date_start_hidden")) {
1657 $(p_div + "date_start").value = $(p_div + "date_start_hidden").value;
1659 if ($(p_div + "date_end_hidden")) {
1660 $(p_div + "date_end").value = $(p_div + "date_end_hidden").value;
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);
1672 // By default , unpaid is uncked
1673 $(p_div + "operation_filter").value = "all";
1675function display_list_filter(p_dossier,access_code,ledger_type)
1677 new Ajax.Request("ajax_misc.php",{
1678 parameters:{"gDossier":p_dossier
1679 ,"op":"display_list_filter"
1681 ,'ledger_type':ledger_type
1684 onSuccess: function (responseHtml) {
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);
1692 console.error(e.message);
1699 * propose to duplicate an operation
1701function duplicate_operation(p_dossier, p_jr_id) {
1703 var duplicate_div = create_div({id: "duplicate_operation_div", cssclass: "inner_box"});
1705 new Ajax.Request("ajax_misc.php", {
1708 "gDossier": p_dossier,
1710 "act": "duplicateop",
1711 "div": "duplicate_operation_div"
1713 onSuccess: function (req) {
1714 remove_waiting_box();
1715 var xml = req.responseXML;
1717 if (xml.getElementsByTagName("ctl").length == 0) {
1718 console.log("erreur" + req.responseText);
1720 add_div(duplicate_div);
1722 duplicate_div.setStyle({
1723 "position": "fixed", "top": "15%", "z-index": "999",
1724 "min-width": "30rem",
1728 duplicate_div.innerHTML = getNodeText(xml.getElementsByTagName("code")[0]);
1729 duplicate_div.setStyle({display: "block"});
1736 * For operation_exercice let update periode when changing folder
1737 * @type {{update_periode: operation_exercice.update_periode}}
1739var operation_exercice = {
1740 update_periode: function (dossier_id) {
1744 op: 'operation_exercice+update_periode',
1745 folder: $('dos_id').value,
1746 gDossier: dossier_id
1748 var action = new Ajax.Request(
1752 parameters: queryString,
1753 onFailure: ajax_misc_failure,
1754 onSuccess: function (req) {
1755 remove_waiting_box();
1756 if (req.responseText == 'NOCONX') {
1761 $("select_exercice_id").update(req.responseText);
1767 console.error('oe-update_periode', e.message);
1770 modify_row: function (row_operation_exercice, oe_id) {
1772 var dgbox = "operation_exercice_bx";
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);
1780 op: 'operation_exercice+modify_row',
1782 row_id: row_operation_exercice,
1783 gDossier: $('gDossier').value
1785 var action = new Ajax.Request(
1789 parameters: queryString,
1790 onFailure: ajax_misc_failure,
1791 onSuccess: function (req) {
1792 remove_waiting_box();
1793 if (req.responseText == 'NOCONX') {
1797 console.debug(req.responseText)
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);
1806 console.error('oe-modify_row', e.message);
1810 * Save data from modify_row
1812 save_row: function () {
1814 var dgbox = "operation_exercice_bx";
1817 // For form , most of the parameters are in the FORM
1818 // method is then POST
1819 //var queryString=$(p_form_id).serialize(true);
1821 var queryString = $('operation_exercice_input_row_frm').serialize(true);
1823 var action = new Ajax.Request(
1827 parameters: queryString,
1828 onFailure: ajax_misc_failure,
1829 onSuccess: function (req) {
1830 remove_waiting_box();
1831 if (req.responseText == 'NOCONX') {
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)
1850 $("oe_" + rowid).update(req.responseJSON['content']);
1852 new Effect.Highlight("oe_" + req.responseJSON['row_id'], {
1853 startcolor: '#FAD4D4',
1856 operation_exercice.display_total(rowid)
1861 $(dgbox).update(req.responseText);
1867 console.error('oe-save_row' + e.message);
1871 * display the balance
1873 display_total: function (row_id) {
1875 var dgbox = "tot_ope_exe";
1877 op: 'operation_exercice+display_total',
1879 gDossier: $('gDossier').value
1881 var action = new Ajax.Request(
1885 parameters: queryString,
1886 onFailure: ajax_misc_failure,
1887 onSuccess: function (req) {
1888 remove_waiting_box();
1889 if (req.responseText == 'NOCONX') {
1894 $(dgbox).update(req.responseText);
1900 console.error('oe-display_total' + e.message);
1906 delete_row: function (row_id) {
1909 op: 'operation_exercice+delete_row',
1911 gDossier: $('gDossier').value
1913 var action = new Ajax.Request(
1917 parameters: queryString,
1918 onFailure: ajax_misc_failure,
1919 onSuccess: function (req) {
1920 remove_waiting_box();
1921 if (req.responseText == 'NOCONX') {
1925 if (req.responseJSON["row_id"] != "") {
1926 operation_exercice.display_total(req.responseJSON["row_id"])
1928 $('oe_' + queryString['row_id']).remove();
1929 $('operation_exercice_bx').remove();
1934 alert_box("oe+delete_row", e.message);
1937 click_modify_row: function (item) {
1938 operation_exercice.modify_row(item.getAttribute("oed_id"), item.getAttribute("oe_id"));
1941 * check and transfer if it is good
1943 transfer: function () {
1945 var dgbox = "oe_transfer_div";
1948 var queryString = $("operation_exercice_transfer_frm").serialize(true);
1949 var action = new Ajax.Request(
1953 parameters: queryString,
1954 onFailure: ajax_misc_failure,
1955 onSuccess: function (req) {
1956 remove_waiting_box();
1957 if (req.responseText == 'NOCONX') {
1961 var answer=req.responseJSON;
1962console.debug(answer['content']);
1963 $('operation_exercice_transfer_info').update(answer.content);
1970 alert_box(e.message);