noalyss Version-9
accounting_item.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 * show the popup for search an accounting item
23 *@param object this, it must contains some attribute as
24 * - jrn if set and different to 0, will filter the accounting item for a
25 * ledger
26 * - account the tag which will contains the number
27 * - label the tag which will contains the label
28 * - bracket if the value must be surrounded by [ ]
29 * - acc_query for the initial query
30 *@see ajax_poste.php
31 */
32function search_accounting(obj)
33{
34 var sx=0;
35 if ( window.scrollY)
36 {
37 sx=window.scrollY+40;
38 }
39 else
40 {
41 sx=document.body.scrollTop+60;
42 }
43
44 var div_style="top:"+sx+"px";
45 removeDiv('search_account');
46 add_div({id:'search_account',cssclass:'inner_box',html:loading(),style:div_style,drag:false});
47
48 var dossier=$('gDossier').value;
49
50 var queryString="gDossier="+dossier;
51
52 queryString+="&op2=sf";
53 queryString+="&op=account";
54 try
55 {
56 if ( obj.jrn)
57 {
58 queryString+="&j="+obj.jrn;
59 }else {
60 if ($("p_jrn")) {
61 queryString+="&j="+$("p_jrn").value;
62 }
63 }
64 if ( obj.account)
65 {
66 queryString+="&c="+obj.account;
67 }
68 if ( obj.label)
69 {
70 queryString+="&l="+obj.label;
71 }
72 if ( obj.bracket)
73 {
74 queryString+="&b="+obj.bracket;
75 }
76 if( obj.noquery)
77 {
78 queryString+="&nq";
79 }
80 if( obj.no_overwrite)
81 {
82 queryString+="&nover";
83 }
84 if( obj.bracket)
85 {
86 queryString+="&bracket";
87 }
88 if ( ! obj.noquery)
89 {
90 if( obj.acc_query)
91 {
92 queryString+="&q="+obj.acc_query;
93 }
94 else
95 {
96 if ($(obj).account)
97 {
98 var e=$(obj).account;
99 var str_account=$(e).value;
100 queryString+="&q="+str_account;
101 }
102 }
103 }
104
105 queryString+="&ctl="+'search_account';
106 queryString=encodeURI(queryString);
107 var action=new Ajax.Request ( 'ajax_misc.php',
108 {
109 method:'get',
110 parameters:queryString,
111 onFailure:errorPoste,
112 onSuccess:result_poste_search
113 }
114 );
115 }
116 catch (e)
117 {
118 alert_box(e.message);
119 }
120}
121/**
122 * when you submit the form for searching a accounting item
123 *@param obj form
124 *@note the same as search_poste, except it answer to a FORM and not
125 * to a click event
126 */
127function search_get_poste(obj)
128{
129 var dossier=$('gDossier').value;
130 var queryString="gDossier="+dossier;
131
132 queryString+="&op=account";
133 queryString+="&op2=sf";
134
135 if ( obj.elements['jrn'] )
136 {
137 queryString+="&j="+$F('jrn');
138 }
139 if ( obj.elements['account'])
140 {
141 queryString+="&c="+$F('account');
142 }
143 if ( obj.elements['label'])
144 {
145 queryString+="&l="+$F('label');
146 }
147 if( obj.elements['acc_query'])
148 {
149 queryString+="&q="+$F('acc_query');
150 }
151 if (obj.ctl )
152 {
153 queryString+="&ctl="+obj.ctl;
154 }
155 if( obj.elements['nosearch'])
156 {
157 queryString+="&nq";
158 }
159 if( obj.elements['nover'])
160 {
161 queryString+="&nover";
162 }
163 if( obj.elements['bracket'])
164 {
165 queryString+="&bracket";
166 }
167
168 $('asearch').innerHTML=loading();
169 var action=new Ajax.Request ( 'ajax_misc.php',
170 {
171 method:'get',
172 parameters:queryString,
173 onFailure:errorPoste,
174 onSuccess:result_poste_search
175 }
176 );
177}
178
179/**
180 * show the answer of ajax request
181 *@param answer in XML
182 */
183function result_poste_search(req)
184{
185 try
186 {
187 var answer=req.responseXML;
188 var a=answer.getElementsByTagName('ctl');
189 if ( a.length == 0 )
190 {
191 var rec=req.responseText;
192 alert_box ('erreur :'+rec);
193 }
194 var html=answer.getElementsByTagName('code');
195
196 var name_ctl=a[0].firstChild.nodeValue;
197 var nodeXml=html[0];
198 var code_html=getNodeText(nodeXml);
199 code_html=unescape_xml(code_html);
200 $('search_account').innerHTML=code_html;
201 }
202 catch (e)
203 {
204 alert_box(e.message);
205 }
206 try
207 {
208 code_html.evalScripts();
209 }
210 catch(e)
211 {
212 alert_box("RESPOSEAR"+content[48]+e.message);
213 }
214
215}
216/**
217* error for ajax
218*/
219function errorPoste()
220{
221 alert_box(content[53]);
222}
223
224/**
225 * Display the list of card using a given accounting
226 * @param dossier
227 * @param accounting
228 *
229 */
230function display_all_card(p_dossier,p_accounting)
231{
232 waiting_box();
233 var div_dest=add_div({id:'info_card_accounting',cssclass:"inner_box",style:fixed_position(100,250)+";width:auto"});
234 var action=new Ajax.Request ( 'ajax_misc.php',
235 {
236 method:'get',
237 parameters:{op:"display_all_card",
238 gDossier:p_dossier,
239 p_accounting:p_accounting
240 },
241 onSuccess:function (req)
242 {
243 div_dest.innerHTML=req.responseText;
244 remove_waiting_box();
245 }
246 }
247 );
248}
249
250/**
251 * Search an account or an analytic account or a card, used in REPORT
252 * @param {json} p_obj ,
253 * property : - op for ajax_misc ,
254 * - gDossier,
255 * - target DOM element to update with the result
256 * - query for the search
257 * @returns {void}
258 */
259function search_account_card(p_obj)
260{
261 p_obj['op']=p_obj['op']||"search_account_card";
262 var query=p_obj;
263 if (p_obj.tagName && p_obj.tagName=='FORM') {
264 query=p_obj.serialize(true);
265 }
266
267 waiting_box();
268 new Ajax.Request("ajax_misc.php",{method:"get",parameters:query,
269 onSuccess: function (req){
270
271 var pos=calcy(50);
272 var obj={id:"search_account_div",cssclass:"inner_box",style:"top:"+pos+"px",
273 html:req.responseText};
274 add_div(obj);
275 remove_waiting_box();
276 }
277 });
278 return false;
279}