noalyss Version-9
pre_op_ach.class.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!\file
23 * \brief definition of the class pre_op_ach
24 */
25
26/*---------------------------------------------------------------------- */
27/*!\brief concerns the predefined operation for ACH ledger
28 */
30{
31 function __construct($cn)
32 {
33 parent::__construct($cn);
34 }
35 /**
36 * @brief get the post and stove them into data member , before saving them in the db
37 * @see save
38 */
39 function get_post()
40 {
41 $http = new \HttpInput();
42 $nb = $http->post("nb_item", "number");
43 $this->e_client=$http->post('e_client');
44 for ($i = 0; $i < $nb; $i++) {
45 $march = "e_march" . $i;
46 $http->set_empty("");
47 $this->$march = $http->post('e_march' . $i);
48 $this->{"e_march" . $i . "_label"} = $http->post('e_march' . $i . "_label", "string", "");
49
50 $http->set_empty(0);
51
52 $this->{"e_march" . $i . "_tva_id"} = $http->post('e_march' . $i . "_tva_id", "string", 0);
53 $this->{"e_march" . $i . "_tva_id"} =(empty($this->{"e_march" . $i . "_tva_id"}))?null:$this->{"e_march" . $i . "_tva_id"} ;
54 $this->{"e_march" . $i . "_price"} = $http->post('e_march' . $i . "_price","number");
55 $this->{"e_march" . $i . "_tva_amount"} = $http->post('e_march' . $i . "_tva_amount", "string", "0");
56 $this->{"e_march" . $i . "_tva_amount"} = (empty( $this->{"e_march" . $i . "_tva_amount"} ))?0: $this->{"e_march" . $i . "_tva_amount"} ;
57 $this->{"e_quant" . $i} = $http->post('e_quant' . $i, "number");
58 }
59 }
60 /*!
61 * \brief save the detail and op in the database
62 *
63 */
64 function save($p_od_id,$p_nb_item)
65 {
66 try
67 {
68 // save the client
69 $sql=sprintf('insert into op_predef_detail (od_id,opd_poste,opd_debit)'.
70 ' values '.
71 "(%d,'%s','%s')",
72 $p_od_id,
73 $this->e_client,
74 "f");
75 $this->db->exec_sql($sql);
76
77 for ($i=0;$i<$p_nb_item;$i++)
78 {
79 if ( noalyss_strlentrim($this->{"e_march".$i})==0) continue;
80 $sql= 'insert into op_predef_detail (opd_poste,'
81 . 'opd_amount,'
82 . 'opd_tva_id,'
83 . 'opd_quantity,'
84 . 'opd_debit,'
85 . 'od_id ,'
86 . 'opd_tva_amount,'
87 . 'opd_comment'.
88 ')'.
89 ' values ($1,$2,$3,$4,$5,$6,$7,$8)';
90// if (DEBUGNOALYSS >2 ) {
91// var_dump(array($this->{"e_march".$i},
92// $this->{"e_march".$i."_price"},
93// $this->{"e_march".$i."_tva_id"},
94// $this->{"e_quant".$i},
95// 't',
96// $p_od_id,
97// $this->{"e_march".$i."_tva_amount"},
98// $this->{"e_march".$i."_label"}));
99// }
100 $this->db->exec_sql($sql,
101 array($this->{"e_march".$i},
102 $this->{"e_march".$i."_price"},
103 $this->{"e_march".$i."_tva_id"},
104 $this->{"e_quant".$i},
105 't',
106 $p_od_id,
107 $this->{"e_march".$i."_tva_amount"},
108 $this->{"e_march".$i."_label"}
109 ));
110 }
111 }
112 catch (Exception $e)
113 {
114 record_log("PREOPACH01".$e->getMessage().$e->getTraceAsString());
115 throw $e;
116 }
117 }
118 /**
119 * @brief compute an array accordingly with the FormVenView function, first the data is fetched (via load)
120 * to the database and turns into an array to be use with Pre_Op_Ach::display
121 * @return an array for filling the form
122 * @see load
123 */
124 function compute_array($p_od_id)
125 {
126 $count=0;
127 $array=array();
128 $p_array=$this->load($p_od_id);
129 if (empty($p_array)) return array();
130 foreach ($p_array as $row)
131 {
132 if ( $row['opd_debit']=='f')
133 {
134 $array+=array('e_client'=>$row['opd_poste']);
135 }
136 else
137 {
138 if ( trim($row['opd_poste']) != "")
139 {
140 $array+=array("e_march".$count=>$row['opd_poste'],
141 "e_march".$count."_price"=>$row['opd_amount'],
142 "e_march".$count."_tva_id"=>$row['opd_tva_id'],
143 "e_quant".$count=>$row['opd_quantity'],
144 "e_march".$count."_label"=>$row['opd_comment'],
145 "e_march".$count."_tva_amount"=>$row['opd_tva_amount'],
146 );
147 $count++;
148 }
149 }
150 }
151
152 return $array;
153 }
154 /**
155 * @brief
156 * load the data from the database and return an array
157 * \return an array
158 */
159 function load($p_od_id)
160 {
161 $sql="select opd_id,opd_poste,opd_amount,opd_tva_id,opd_debit,".
162 " opd_quantity , opd_comment,opd_tva_amount from op_predef_detail where od_id= $1 ".
163 " order by opd_id";
164 $res=$this->db->exec_sql($sql,[$p_od_id]);
165 if ($res == false) return array();
167 return $array;
168 }
169
170 /**
171 * Display the form for modifying or adding new predefined operation
172 * @param array $p_array is the result of compute_array or blank
173 * @return string containing HTML code of the form
174 * @throws Exception
175 * @see compute_array
176 * @see load
177 *
178 */
180 {
181 global $g_parameter,$g_user;
182 $ledger=new Acc_Ledger_Purchase($this->db,$p_array['p_jrn']);
183
184 $flag_tva=$g_parameter->MY_TVA_USE;
185 /* Add button */
186 $f_add_button=new IButton('add_card');
187 $f_add_button->tabindex=-1;
188 $f_add_button->label=_('Créer une nouvelle fiche');
189 $f_add_button->set_attribute('ipopup','ipop_newcard');
190 $f_add_button->set_attribute('jrn',$p_array['p_jrn']);
191 $f_add_button->javascript="this.jrn=\$('p_jrn').value; select_card_type(this);";
192
193 $f_add_button2=new IButton('add_card2');
194 $f_add_button2->tabindex=-1;
195 $f_add_button2->label=_('Créer une nouvelle fiche');
196 $f_add_button2->set_attribute('ipopup','ipop_newcard');
197 $f_add_button2->set_attribute('filter',$ledger->get_all_fiche_def ());
198 // $f_add_button2->set_attribute('jrn',$ledger->id);
199 $f_add_button2->javascript=" this.jrn=\$('p_jrn').value;select_card_type(this);";
200
201 $str_add_button="";
202 $str_add_button2="";
203 if ($g_user->check_action(FICADD)==1)
204 {
205 $str_add_button=$f_add_button->input();
206 $str_add_button2=$f_add_button2->input();
207 }
208
209 $r='';
210 $r.=dossier::hidden();
211 $f_legend=_('En-tête facture fournisseur');
212
213
214 // Display the customer
215 //--
216 $fiche='deb';
217
218 // Save old value and set a new one
219 //--
220 $e_client=( isset ($p_array["e_client"]) )?$p_array["e_client"]:"";
221 $e_client_label="&nbsp;";//str_pad("",100,".");
222
223
224 // retrieve e_client_label
225 //--
226
227 if ( noalyss_strlentrim($e_client) != 0)
228 {
229 $fClient=new Fiche($ledger->db);
230 $fClient->get_by_qcode($e_client);
231 $e_client_label=$fClient->strAttribut(ATTR_DEF_NAME).' '.
232 ' Adresse : '.$fClient->strAttribut(ATTR_DEF_ADRESS).' '.
233 $fClient->strAttribut(ATTR_DEF_CP).' '.
234 $fClient->strAttribut(ATTR_DEF_CITY).' ';
235
236
237 }
238
239 $W1=new ICard();
240 $W1->label="Client ".Icon_Action::infobulle(0) ;
241 $W1->name="e_client";
242 $W1->tabindex=3;
243 $W1->value=$e_client;
244 $W1->table=0;
245 $W1->set_dblclick("fill_ipopcard(this);");
246 $W1->set_attribute('ipopup','ipopcard');
247
248 // name of the field to update with the name of the card
249 $W1->set_attribute('label','e_client_label');
250 // name of the field to update with the name of the card
251 $W1->set_attribute('typecard','cred');
252
253 // Add the callback function to filter the card on the jrn
254 $W1->set_callback('filter_card');
255 $W1->set_function('fill_data');
256 $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
257 $W1->name);
258 $f_client_qcode=$W1->input();
259 $client_label=new ISpan();
260 $client_label->table=0;
261 $f_client=$client_label->input("e_client_label",$e_client_label);
262 $f_client_bt=$W1->search();
263
264
265 // Record the current number of article
266 $min=$ledger->get_min_row();
267 $p_article= ( isset ($p_array["nb_item"]))?$p_array["nb_item"]:$min;
268 $max=($p_article < $min)?$min:$p_article;
269
270 $e_comment=(isset($p_array["e_comment"]))?$p_array["e_comment"]:"";
271 $Hid=new IHidden();
272 $r.=$Hid->input("nb_item",$p_article);
273
274 $f_legend_detail=_("Détail articles achetés");
275
276 // For each article
277 //--
278 for ($i=0;$i< $max;$i++)
279 {
280 // Code id, price & vat code
281 //--
282 $march=(isset($p_array["e_march$i"]))?$p_array["e_march$i"]:""
283 ;
284 $march_price=(isset($p_array["e_march".$i."_price"]))?$p_array["e_march".$i."_price"]:""
285 ;
286 if ( $flag_tva=='Y')
287 {
288 $march_tva_id=(isset($p_array["e_march$i"."_tva_id"]))?$p_array["e_march$i"."_tva_id"]:"";
289 $march_tva_amount=(isset($p_array["e_march$i"."_tva_amount"]))?$p_array["e_march$i"."_tva_amount"]:"";
290 }
291 $march_label=(isset($p_array["e_march".$i."_label"]))?$p_array["e_march".$i."_label"]:"";
292
293 // retrieve the tva label and name
294 //--
295 if ( noalyss_strlentrim($march)!=0 && noalyss_strlentrim($march_label)==0)
296 {
297 $fMarch=new Fiche($ledger->db);
298 $fMarch->get_by_qcode($march);
299 $march_label=$fMarch->strAttribut(ATTR_DEF_NAME);
300 if ( $flag_tva=='Y')
301 {
302 if ( ! (isset($p_array["e_march$i"."_tva_id"])))
303 $march_tva_id=$fMarch->strAttribut(ATTR_DEF_TVA);
304 }
305 }
306 // Show input
307 //--
308 $W1=new ICard();
309 $W1->label="";
310 $W1->name="e_march".$i;
311 $W1->value=$march;
312 $W1->table=1;
313 $W1->set_attribute('typecard','deb');
314 $W1->set_dblclick("fill_ipopcard(this);");
315 $W1->set_attribute('ipopup','ipopcard');
316
317 // name of the field to update with the name of the card
318 $W1->set_attribute('label','e_march'.$i.'_label');
319 // name of the field with the price
320 $W1->set_attribute('price','e_march'.$i.'_price');
321 // name of the field with the TVA_ID
322 $W1->set_attribute('tvaid','e_march'.$i.'_tva_id');
323 // Add the callback function to filter the card on the jrn
324 $W1->set_callback('filter_card');
325 $W1->set_function('fill_data');
326 $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
327 $W1->name);
328
329 $W1->readonly=false;
330
331 $array[$i]['quick_code']=$W1->input();
332 $array[$i]['bt']=$W1->search();
333 // For computing we need some hidden field for holding the value
334 $array[$i]['hidden']='';
335 if ( $flag_tva=='Y') $array[$i]['hidden'].=HtmlInput::hidden('tva_march'.$i,0);
336
337 $htva=new INum('htva_march'.$i);
338 $htva->readOnly=1;
339 $htva->value=0;
340 $array[$i]['htva']=$htva->input();
341
342 if ( $g_parameter->MY_TVA_USE=='Y')
343 $tvac=new INum('tvac_march'.$i);
344 else
345 $tvac=new IHidden('tvac_march'.$i);
346
347 $tvac->readOnly=1;
348 $tvac->value=0;
349 $array[$i]['tvac']=$tvac->input();
350
351 if ( $g_parameter->MY_UPDLAB == 'Y')
352 {
353 $Span=new IText("e_march".$i."_label");
354
355 $Span->css_size="100%";
356 } else
357 {
358 $Span=new ISpan("e_march".$i."_label");
359 }
360 $Span->value=$march_label;
361 $Span->setReadOnly(false);
362 // card's name, price
363 //--
364 $array[$i]['denom']=$Span->input("e_march".$i."_label",$march_label);
365 // price
366 $Price=new INum();
367 $Price->setReadOnly(false);
368 $Price->prec=4;
369 $Price->size=9;
370 $Price->javascript="onBlur='format_number(this);clean_tva($i);compute_ledger($i)'";
371 $array[$i]['pu']=$Price->input("e_march".$i."_price",$march_price);
372 $array[$i]['tva']='';
373 $array[$i]['amount_tva']='';
374 // if tva is not needed then no tva field
375 if ( $flag_tva == 'Y' )
376 {
377 // vat label
378 //--
379 $Tva=new ITva_Popup($ledger->db);
380 $Tva->in_table=true;
381 $Tva->set_attribute('compute',$i);
382
383 $Tva->js='onblur="format_number(this);clean_tva('.$i.');compute_ledger('.$i.')"';
384 $Tva->value=$march_tva_id;
385 $array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
386 // vat amount
387 //--
388 $wTva_amount=new INum();
389 $wTva_amount->readOnly=false;
390 $wTva_amount->size=6;
391 $wTva_amount->javascript="onBlur='format_number(this);compute_ledger($i)'";
392 $array[$i]['amount_tva']=$wTva_amount->input("e_march".$i."_tva_amount",$march_tva_amount);
393 }
394 // quantity
395 //--
396 $quant=(isset($p_array["e_quant$i"]))?$p_array["e_quant$i"]:"1"
397 ;
398 $Quantity=new INum();
399 $Quantity->setReadOnly(false);
400 $Quantity->prec=4;
401 $Quantity->size=8;
402 $Quantity->javascript="onChange='format_number(this);clean_tva($i);compute_ledger($i)'";
403 $array[$i]['quantity']=$Quantity->input("e_quant".$i,$quant);
404
405 }// foreach article
406 $f_type=_('Client');
407
408
409 ob_start();
410 require_once NOALYSS_TEMPLATE.'/predf_ledger_detail.php';
411 $r.=ob_get_contents();
412 ob_end_clean();
413
414
415
416 // Set correctly the REQUEST param for jrn_type
417 $r.=HtmlInput::hidden('jrn_type','ACH');
419
420 return $r;
421
422 }
423}
noalyss_strlentrim($p_string)
Definition: ac_common.php:1549
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342
global $g_parameter
global $g_user
if no group available , then stop
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
if(!headers_sent())
– pour utiliser unoconv démarrer un server libreoffice commande libreoffice –headless –accept="socket...
Handle the ledger of purchase,.
static fetch_all($ret)
wrapper for the function pg_fetch_all
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: fiche.class.php:38
static ledger_add_item($p_ledger)
Build a HTML string for adding multiple rows.
static hidden($p_name, $p_value, $p_id="")
Html Input.
Input HTML for the card show buttons, in the file, you have to add card.js How to use :
Html Input.
This class handles only the numeric input, the input will call a javascript to change comma to period...
Definition: inum.class.php:42
Html Input.
Definition: ispan.class.php:32
Html Input.
Definition: itext.class.php:30
let you choose a TVA in a popup
concerns the predefined operation for ACH ledger
get_post()
get the post and stove them into data member , before saving them in the db
load($p_od_id)
load the data from the database and return an array
compute_array($p_od_id)
compute an array accordingly with the FormVenView function, first the data is fetched (via load) to t...
display($p_array)
Display the form for modifying or adding new predefined operation.
save($p_od_id, $p_nb_item)
save the detail and op in the database
mother of the pre_op_XXX, it contains only one data : an object Pre_Operation. The child class contai...
const ATTR_DEF_ADRESS
Definition: constant.php:223
const ATTR_DEF_NAME
Definition: constant.php:216
const ATTR_DEF_CP
Definition: constant.php:224
const ATTR_DEF_TVA
Definition: constant.php:221
const ATTR_DEF_CITY
Definition: constant.php:229
const FICADD
$count
$SecUser db