/* * This file is part of PhpCompta. * * PhpCompta 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. * * PhpCompta 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 PhpCompta; 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 ddebontridder@yahoo.fr /*!\file * \brief javascript script for the ledger in accountancy, * compute the sum, add a row at the table.. * */ var layer=1; /** * @brief update the list of available predefined operation when we change the ledger. */ function update_predef(p_type,p_direct) { 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"; g("p_jrn_predef").value=jrn; var action=new Ajax.Request( "ajax_misc.php", { method:'get', parameters:querystring, onFailure:error_get_predef, onSuccess:success_get_predef } ); } /** * @brief 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; } } ); } /** *@brief update ctl id =jrn_name with the value of p_jrn */ function update_name() { $('jrn_name').innerHTML=$('p_jrn').options[$('p_jrn').selectedIndex].innerHTML; } /** * @brief update the field predef */ function success_get_predef(request,json) { var i=0; var answer=request.responseText.evalJSON(true); obj=g("pre_def"); obj.innerHTML=''; if ( answer.count == 0 ) return; for ( i = 0 ; i < answer.count;i++) { value=answer['value'+i]; label=answer['label'+i]; obj.options[obj.options.length]=new Option(label,value); } } /** * @brief update the field predef */ function error_get_predef(request,json) { alert ("Erreur mise à jour champs non possible"); } /** * @brief 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 } ); } /** * 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 ('erreur :'+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("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 ('erreur :'+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(e.message); } } /** * @brief update the field predef */ function success_get_pj(request,json) { var answer=request.responseText.evalJSON(true); obj=g("e_pj"); obj.value=''; if ( answer.count == 0 ) return; obj.value=answer.pj; g("e_pj_suggest").value=answer.pj; } /** * @brief update the field predef */ function error_get_pj(request,json) { alert("Ajax a echoue"); } /** * @brief 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; 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++; } /** * @brief add a line in the form for the purchase ledger */ function ledger_add_row() { try{ style='class="input_text"'; var mytable=g("sold_item").tBodies[0]; var ofirstRow=mytable.rows[1]; var line=mytable.rows.length; var nCell=mytable.rows[1].cells.length; var row=mytable.insertRow(line); var nb=g("nb_item"); for (var e=0;e