/* * This file is part of NOALYSS. * * NOALYSS is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * NOALYSS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with NOALYSS; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* $Revision$ */ // Copyright Author Dany De Bontridder danydb@aevalys.eu /*! * \file * \brief javascript script for the ledger in accountancy, * compute the sum, add a row at the table.. * */ var layer = 1; /** * \fn * \brief update the list of available predefined operation when we change the ledger. */ function update_predef(p_type, p_direct, p_ac) { var jrn = g("p_jrn").value; var dossier = g("gDossier").value; var querystring = 'gDossier=' + dossier + '&l=' + jrn + '&t=' + p_type + '&d=' + p_direct + "&op=up_predef&ac=" + p_ac; g("p_jrn_predef").value = jrn; var action = new Ajax.Request( "ajax_misc.php", { method: 'get', parameters: querystring, onFailure: error_get_predef, onSuccess: function (req) { try { $('info_div').innerHTML = "ok"; var answer = req.responseXML; var a = answer.getElementsByTagName('code'); var html = answer.getElementsByTagName('value'); if (a.length == 0) { var rec = req.responseText; alert_box(content[48] + rec); } var code_html = getNodeText(html[0]); code_html = unescape_xml(code_html); // document.getElementsByName(name_ctl)[0].value = code_html; $('modele_op_div').innerHTML = code_html; } catch (e) { $('info_div').innerHTML = e.message; } } } ); } /** * update the list of payment method when we change the ledger. */ function update_pay_method() { waiting_box(); var jrn = g("p_jrn").value; var dossier = g("gDossier").value; var querystring = 'gDossier=' + dossier + '&l=' + jrn + "&op=up_pay_method"; var action = new Ajax.Request( "ajax_misc.php", { method: 'get', parameters: querystring, onFailure: error_get_predef, onSuccess: function (req) { remove_waiting_box(); var answer = req.responseText; $('payment').innerHTML = answer; } } ); } /** * update ctl id =jrn_name with the value of p_jrn */ function update_name() { var jrn_id = $('p_jrn').value; var dossier = g("gDossier").value; var querystring = 'gDossier=' + dossier + '&l=' + jrn_id + "&op=ledger_description"; var action = new Ajax.Request( "ajax_misc.php", { method: 'get', parameters: querystring, onFailure: error_get_pj, onSuccess: function (req) { $('jrn_name_div').innerHTML = req.responseText; } } ); } /** * update the field predef */ function error_get_predef(request, json) { alert_box(content[49]); } /** * update the list of available predefined operation when we change the ledger. */ function update_pj() { var jrn = g("p_jrn").value; var dossier = g("gDossier").value; var querystring = 'gDossier=' + dossier + '&l=' + jrn + "&op=upd_receipt"; var action = new Ajax.Request( "ajax_misc.php", { method: 'get', parameters: querystring, onFailure: error_get_pj, onSuccess: success_get_pj } ); } /** * ask the name, quick_code of the bank for the ledger */ function update_bank() { var jrn = g('p_jrn').value; var dossier = g('gDossier').value; var qs = 'gDossier=' + dossier + '&op=bkname&p_jrn=' + jrn; var action = new Ajax.Request( "ajax_misc.php", { method: 'get', parameters: qs, onFailure: error_get_pj, onSuccess: success_update_bank } ); } /** * Update the number of rows when changing of ledger */ function update_row(ctl) { try { var row_to_keep=3; /* Number of row to keep (head and foot)*/ if ( ctl === 'quick_item' ) { row_to_keep=1;} /* for ODS , only 1 rows to keep */ var jrn = g('p_jrn').value; var dossier = g('gDossier').value; var qs = encodeURI('gDossier=' + dossier + '&op=minrow&j=' + jrn + '&ctl=' + ctl); var current_row = parseFloat($('nb_item').value); var action = new Ajax.Request( "ajax_misc.php", { method: 'get', parameters: qs, onFailure: null, onSuccess: function (request, json) { try { var answer = request.responseText.evalJSON(true); var row = parseFloat(answer.row); var table_to_update=$(ctl); if (current_row > row) { // Too many row, we always must keep 2 rows for the sum var delta = $('nb_item').value - row ; var idx = $('nb_item').value; for (var i = 0; i < delta; i++) { var pos_row=table_to_update.rows.length; var cell0 = table_to_update.rows[pos_row-row_to_keep].cells[0]; var cell0Element=cell0.childNodes; var canDelete=true; /** * prevent truncating */ cell0Element.forEach(function (x) { if (canDelete && x.nodeName=='INPUT' && x.type==="text" && x.value) { canDelete=false; }} ); /* * prevent truncating * For ODS we also need to check the second column * */ if ( canDelete && ctl === 'quick_item') { var cell1 = table_to_update.rows[pos_row-row_to_keep].cells[1]; var cell1Element=cell1.childNodes; cell1Element.forEach(function (x) { if (canDelete && x.nodeName=='INPUT' && x.type==="text" && x.value) { canDelete=false; }}); } if ( canDelete ) { table_to_update.deleteRow(pos_row-row_to_keep);idx--;} } $('nb_item').value = table_to_update.rows.length-row_to_keep; } if (current_row < row) { // We need to add rows var delta = row - current_row ; for (var i = 0; i < delta; i++) { if (ctl == 'fin_item') { ledger_fin_add_row(); } if (ctl == 'sold_item') { ledger_add_row(); } if (ctl == 'quick_item') { quick_writing_add_row(); } } } } catch (e) { alert_box("update_row:01"+e.message); } } } ); } catch (e) { alert_box(e.message); } } /** * Put into the span, the name of the bank, the bank account * and the quick_code */ function success_update_bank(req) { try { var answer = req.responseXML; var a = answer.getElementsByTagName('code'); var html = answer.getElementsByTagName('value'); if (a.length == 0) { var rec = req.responseText; alert_box('UPDBK-'+content[48]+ rec); } var name_ctl = a[0].firstChild.nodeValue; var code_html = getNodeText(html[0]); code_html = unescape_xml(code_html); $(name_ctl).innerHTML = code_html; } catch (e) { alert_box("success_update_bank" + e.message); } } /** * call ajax, ask what is the last date for the current ledger */ function get_last_date() { var jrn = g('p_jrn').value; var dossier = g('gDossier').value; var qs = 'gDossier=' + dossier + '&op=lastdate&p_jrn=' + jrn; var action = new Ajax.Request( "ajax_misc.php", { method: 'get', parameters: qs, onFailure: error_get_pj, onSuccess: success_get_last_date } ); } /** * callback ajax, set the ctl with the last date from the ledger */ function success_get_last_date(req) { try { var answer = req.responseXML; var a = answer.getElementsByTagName('code'); var html = answer.getElementsByTagName('value'); if (a.length == 0) { var rec = req.responseText; alert_box('GETLASTDA:'+content[48] + rec); } var name_ctl = a[0].firstChild.nodeValue; var code_html = getNodeText(html[0]); code_html = unescape_xml(code_html); document.getElementsByName(name_ctl)[0].value = code_html; } catch (e) { alert_box(e.message); } } /** * update the field predef */ function success_get_pj(request, json) { var answer = request.responseText.evalJSON(true); var obj = g("e_pj"); obj.value = ''; if (answer.length == 0) return; obj.value = answer.pj; g("e_pj_suggest").value = answer.pj; } /** * update the field predef */ function error_get_pj(request, json) { alert_box("GETPJ:"+content[48]); } /** * add a line in the form for the ledger fin */ function ledger_fin_add_row() { var style = 'class="input_text"'; var mytable = g("fin_item").tBodies[0]; var line = mytable.rows.length; var row = mytable.insertRow(line); var nb = g("nb_item"); var rowToCopy = mytable.rows[1]; var nNumberCell = rowToCopy.cells.length; for (var e = 0; e < nNumberCell; e++) { var newCell = row.insertCell(e); if (e == 0) { newCell.id = 'tdchdate' + nb.value; } var tt = rowToCopy.cells[e].innerHTML; var new_tt = tt.replace(/e_other0/g, "e_other" + nb.value); new_tt = new_tt.replace(/e_other0_comment/g, "e_other" + nb.value + '_comment'); new_tt = new_tt.replace(/e_other_name0/g, "e_other_name" + nb.value); new_tt = new_tt.replace(/e_other0_amount/g, "e_other" + nb.value + '_amount'); new_tt = new_tt.replace(/e_concerned0/g, "e_concerned" + nb.value); new_tt = new_tt.replace(/e_other0_label/g, "e_other" + nb.value + '_label'); new_tt = new_tt.replace(/dateop0/g, "dateop" + nb.value); newCell.innerHTML = new_tt; newCell.className=rowToCopy.cells[e].className; new_tt.evalScripts(); } g("e_other" + nb.value).value = ""; g("e_other_name" + nb.value).value = ""; g("e_other" + nb.value + '_amount').value = "0"; g("e_other" + nb.value + '_comment').value = ""; g("e_concerned" + nb.value).value = ""; var ch = $('chdate').options[$('chdate').selectedIndex].value; if (ch == 1) { $('tdchdate' + nb.value).hide(); } nb.value++; } /** * Add multiple row * @param p_numrow */ function ledger_add_multiple(p_elid) { var nbrow=$(p_elid).value; if (nbrow == NaN) {nbrow=1;} var type_ledger=$(p_elid+"_ledger").value; var i=0; for (i=0;i'; new_tt = new_tt + ''; newCell.innerHTML = new_tt; if (mytable.rows[1].cells[e].hasClassName("num")) { newCell.addClassName("num"); } new_tt.evalScripts(); } g("e_march" + nb.value + "_label").innerHTML = ' '; g("e_march" + nb.value + "_label").value = ''; g("e_march" + nb.value + "_price").value = '0'; g("e_march" + nb.value).value = ""; g("e_quant" + nb.value).value = "1"; g('tvac_march' + nb.value).value = "0"; if ($("e_march" + nb.value + "_tva_amount")) g("e_march" + nb.value + "_tva_amount").value = 0; nb.value++; new_tt.evalScripts(); } catch (e) { alert_box(e.message); } } function document_remove(p_dossier,p_div,p_jrid) { smoke.confirm(content[50], function (e) { if (e) { new Ajax.Request('ajax_misc.php', { parameters:{"op":"ledger","gDossier":p_dossier,"div":p_div,"p_jrid":p_jrid,'act':'rmf'}, onSuccess : function(x) { $('receipt'+p_div).innerHTML=x.responseText; } }) } }); } /*** * receive an object and display a list of filter + form to save one * fill up the span (id : {div}search_filter_span) with the name of the selected filter * Object = '{'div':'','type':'ALL','all_type':1,'dossier':'10104'}' * @see Acc_Ledger_Search */ function manage_search_filter(p_obj) { waiting_box(); new Ajax.Request("ajax_misc.php", { method:'get', parameters:{"op":"display_search_filter","gDossier":p_obj.dossier,"div":p_obj.div,"ledger_type":p_obj.ledger_type,"all_type":p_obj.all_type}, onSuccess:function(req) { remove_waiting_box(); var x=posX; var y=calcy(200) create_div({'id':'boxfilter'+p_obj.div,'cssclass':'inner_box','html':req.responseText,'style':'top:'+y+'px;left:'+x+'px;position:absolute;width:400px',drag:1}); $('boxfilter'+p_obj.div).show(); } }); } /** * Send data from the form and record a new filter , the ajax answer is a json object * with the attribute filter_name,filter_id,status,message * * @param p_div prefix id of all concerned DOM Element * @param p_dossier * @see Acc_Ledger_Search */ function save_filter(p_div,p_dossier) { var elt=['ledger_type','nb_jrn','date_start','date_end', 'date_paid_start','date_paid_end','desc','amount_min','amount_max','qcode','accounting', 'operation_filter','tag_option','p_currency_code']; var eltValue={}; var i =0; eltValue['gDossier']=p_dossier; eltValue['op']="save_filter"; eltValue['div']=p_div; eltValue['filter_name']=$(p_div+"filter_new").value; // Get all elt from the form for ( var i = 0 ; i < elt.length;i++) { var idx=elt[i]; eltValue[idx]=$(p_div+elt[i]).value; } if (eltValue['amount_min']=="") eltValue["amount_min"]=0; if (eltValue['amount_max']=="") eltValue["amount_max"]=0; //ledger's list r_jrn if (eltValue['nb_jrn'] > 0) { eltValue['r_jrn']=[]; for (i=0;i