noalyss  Version-6.9.1.8
 All Data Structures Namespaces Files Functions Variables Pages
class_pre_op_ach.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 require_once NOALYSS_INCLUDE.'/class/class_pre_operation.php';
26 
27 /*---------------------------------------------------------------------- */
28 /*!\brief concerns the predefined operation for ACH ledger
29  */
31 {
32  var $op;
33  function __construct($cn,$p_id=0)
34  {
35  parent::__construct($cn,$p_id);
36 
37  $this->operation->od_direct='f';
38  }
39 
40  function get_post()
41  {
42  parent::get_post();
43  $this->operation->od_direct='f';
44  $this->e_client=$_POST['e_client'];
45  for ($i=0;$i<$this->operation->nb_item;$i++)
46  {
47  $march="e_march".$i;
48  $this->$march=$_POST['e_march'.$i];
49  $this->{"e_march".$i."_price"}=(isset ($_POST['e_march'.$i."_price"]))?$_POST['e_march'.$i."_price"]:0;
50  $this->{"e_march".$i."_price"}=(trim($_POST['e_march'.$i."_price"])=="")?0:$_POST['e_march'.$i."_price"];
51  $this->{"e_march".$i."_tva_id"}=(isset ($_POST['e_march'.$i."_tva_id"]))?$_POST['e_march'.$i."_tva_id"]:0;
52  $this->{"e_march".$i."_tva_amount"}=(isset($_POST['e_march'.$i."_tva_amount"]))?$_POST['e_march'.$i."_tva_amount"]:0;
53  $this->{"e_march".$i."_label"}=(isset($_POST['e_march'.$i."_label"]))?$_POST['e_march'.$i."_label"]:null;
54  $this->{"e_quant".$i}=$_POST['e_quant'.$i];
55 
56  }
57  }
58 
59  /*!
60  * \brief save the detail and op in the database
61  *
62  */
63  function save()
64  {
65  try
66  {
67  $this->db->start();
68  if ($this->operation->save() == false )
69  return;
70  // save the client
71  $sql=sprintf('insert into op_predef_detail (od_id,opd_poste,opd_debit)'.
72  ' values '.
73  "(%d,'%s','%s')",
74  $this->operation->od_id,
75  $this->e_client,
76  "f");
77  $this->db->exec_sql($sql);
78  // save the selling
79  for ($i=0;$i<$this->operation->nb_item;$i++)
80  {
81  if ( strlen(trim($this->{"e_march".$i}))=="") continue;
82  $sql= 'insert into op_predef_detail (opd_poste,'
83  . 'opd_amount,'
84  . 'opd_tva_id,'
85  . 'opd_quantity,'
86  . 'opd_debit,'
87  . 'od_id ,'
88  . 'opd_tva_amount,'
89  . 'opd_comment'.
90  ')'.
91  ' values ($1,$2,$3,$4,$5,$6,$7,$8)';
92  $this->db->exec_sql($sql,
93  array($this->{"e_march".$i},
94  $this->{"e_march".$i."_price"},
95  $this->{"e_march".$i."_tva_id"},
96  $this->{"e_quant".$i},
97  't',
98  $this->operation->od_id,
99  $this->{"e_march".$i."_tva_amount"},
100  $this->{"e_march".$i."_label"},
101  ));
102  }
103  }
104  catch (Exception $e)
105  {
106  echo ($e->getMessage());
107  $this->db->rollback();
108  }
109  $this->db->commit();
110  }
111  /*!\brief compute an array accordingly with the FormVenView function
112  * @return an array for filling the form
113  */
114  function compute_array()
115  {
116  $count=0;
117  $a_op=$this->operation->load();
118  $array=$this->operation->compute_array($a_op);
119  $p_array=$this->load();
120  if ( empty ($p_array)) return array();
121  foreach ($p_array as $row)
122  {
123  if ( $row['opd_debit']=='f')
124  {
125  $array+=array('e_client'=>$row['opd_poste']);
126  }
127  else
128  {
129  if ( trim($row['opd_poste']) !="" )
130  {
131  $array+=array("e_march".$count=>$row['opd_poste'],
132  "e_march".$count."_price"=>$row['opd_amount'],
133  "e_march".$count."_tva_id"=>$row['opd_tva_id'],
134  "e_march".$count."_tva_amount"=>$row['opd_tva_amount'],
135  "e_quant".$count=>$row['opd_quantity']
136  );
137  $count++;
138  }
139  }
140  $array['nb_item']=$count;
141  }
142  return $array;
143  }
144  /**
145  * @brief
146  * load the data from the database and return an array
147  * \return an array
148  */
149  function load()
150  {
151  $sql="select opd_id,opd_poste,opd_amount,opd_tva_id,opd_debit,".
152  " opd_quantity,opd_tva_amount from op_predef_detail where od_id=".$this->operation->od_id.
153  " order by opd_id";
154  $res=$this->db->exec_sql($sql);
156  return $array;
157  }
158  function set_od_id($p_id)
159  {
160  $this->operation->od_id=$p_id;
161  }
162  function display($p_array)
163  {
164  require_once NOALYSS_INCLUDE.'/class/class_acc_ledger_purchase.php';
165  global $g_parameter,$g_user;
166  extract($p_array, EXTR_SKIP);
167  $ledger=new Acc_Ledger_Purchase($this->db,$this->jrn_def_id);
168  if ( $p_array != null ) extract($p_array, EXTR_SKIP);
169 
170  $flag_tva=$g_parameter->MY_TVA_USE;
171  /* Add button */
172  $f_add_button=new IButton('add_card');
173  $f_add_button->label=_('Créer une nouvelle fiche');
174  $f_add_button->tabindex=-1;
175  $f_add_button->set_attribute('ipopup','ipop_newcard');
176  $f_add_button->set_attribute('jrn',$this->jrn_def_id);
177  $f_add_button->javascript=" this.jrn=\$('p_jrn').value;select_card_type(this);";
178 
179  $f_add_button2=new IButton('add_card2');
180  $f_add_button2->tabindex=-1;
181  $f_add_button2->label=_('Créer une nouvelle fiche');
182  $f_add_button2->set_attribute('ipopup','ipop_newcard');
183  $f_add_button2->set_attribute('filter',$ledger->get_all_fiche_def ());
184  // $f_add_button2->set_attribute('jrn',$ledger->id);
185  $f_add_button2->javascript=" this.jrn=\$('p_jrn').value;select_card_type(this);";
186  $str_add_button="";
187  $str_add_button2="";
188  if ($g_user->check_action(FICADD)==1)
189  {
190  $str_add_button=$f_add_button->input();
191  $str_add_button2=$f_add_button2->input();
192  }
193 
194  $r="";
195  $r.=dossier::hidden();
196  $f_legend=_("En-tête facture fournisseur");
197  $f_legend_detail=_("Détail articles acheté");
198 
199  // Ledger (p_jrn)
200  //--
201  /* if we suggest the next pj, then we need a javascript */
202  $add_js="";
203 
204  // Display the customer
205  //--
206  $fiche='cred';
207 
208  // Save old value and set a new one
209  //--
210  $e_client=( isset ($e_client) )?$e_client:"";
211  $e_client_label="&nbsp;";//str_pad("",100,".");
212 
213 
214  // retrieve e_client_label
215  //--
216 
217  if ( strlen(trim($e_client)) != 0)
218  {
219  $fClient=new Fiche($ledger->db);
220  $fClient->get_by_qcode($e_client);
221  $e_client_label=$fClient->strAttribut(ATTR_DEF_NAME).' '.
222  ' Adresse : '.$fClient->strAttribut(ATTR_DEF_ADRESS).' '.
223  $fClient->strAttribut(ATTR_DEF_CP).' '.
224  $fClient->strAttribut(ATTR_DEF_CITY).' ';
225 
226 
227  }
228 
229  $W1=new ICard();
230  $W1->label=_("Fournisseur ").HtmlInput::infobulle(0) ;
231  $W1->name="e_client";
232  $W1->tabindex=3;
233  $W1->value=$e_client;
234  $W1->table=0;
235  $W1->set_dblclick("fill_ipopcard(this);");
236  $W1->set_attribute('ipopup','ipopcard');
237 
238  // name of the field to update with the name of the card
239  $W1->set_attribute('label','e_client_label');
240  // name of the field to update with the name of the card
241  $W1->set_attribute('typecard','cred');
242 
243  // Add the callback function to filter the card on the jrn
244  $W1->set_callback('filter_card');
245  $W1->set_function('fill_data');
246  $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
247  $W1->name);
248  $f_client_qcode=$W1->input();
249  $client_label=new ISpan();
250  $client_label->table=0;
251  $f_client=$client_label->input("e_client_label",$e_client_label);
252  $f_client_bt=$W1->search();
253 
254 
255  // Record the current number of article
256  $min=$ledger->get_min_row();
257  $p_article= ( isset ($nb_item))?$nb_item:$min;
258  $max=($p_article < $min)?$min:$p_article;
259 
260  $e_comment=(isset($e_comment))?$e_comment:"";
261  $Hid=new IHidden();
262  $r.=$Hid->input("nb_item",$p_article);
263  // For each article
264  //--
265  for ($i=0;$i< $max ;$i++)
266  {
267  // Code id, price & vat code
268  //--
269  $march=(isset(${"e_march$i"}))?${"e_march$i"}:"" ;
270  $march_price=(isset(${"e_march".$i."_price"}))?${"e_march".$i."_price"}:""
271  ;
272  /* use vat */
273  if ( $g_parameter->MY_TVA_USE=='Y')
274  {
275  $march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:"";
276  $march_tva_amount=(isset(${"e_march$i"."_tva_amount"}))?${"e_march$i"."_tva_amount"}:"";
277  }
278 
279 
280 
281  $march_label=(isset(${"e_march".$i."_label"}))?${"e_march".$i."_label"}:"";
282  // retrieve the tva label and name
283  //--
284  if ( strlen(trim($march))!=0 && strlen(trim($march_label))==0 )
285  {
286  $fMarch=new Fiche($ledger->db);
287  $fMarch->get_by_qcode($march);
288  $march_label=$fMarch->strAttribut(ATTR_DEF_NAME);
289  /* vat use */
290  if ( ! isset($march_tva_id) && $g_parameter->MY_TVA_USE=='Y' )
291  $march_tva_id=$fMarch->strAttribut(ATTR_DEF_TVA);
292  }
293  // Show input
294  //--
295  $W1=new ICard();
296  $W1->label="";
297  $W1->name="e_march".$i;
298  $W1->value=$march;
299  $W1->table=1;
300  $W1->set_dblclick("fill_ipopcard(this);");
301  $W1->set_attribute('ipopup','ipopcard');
302 
303  $W1->set_attribute('typecard','deb');
304 
305  // name of the field to update with the name of the card
306  $W1->set_attribute('label','e_march'.$i.'_label');
307  // name of the field with the price
308  $W1->set_attribute('purchase','e_march'.$i.'_price'); /* autocomplete */
309  $W1->set_attribute('price','e_march'.$i.'_price'); /* via search */
310 
311  // name of the field with the TVA_ID
312  $W1->set_attribute('tvaid','e_march'.$i.'_tva_id');
313  // Add the callback function to filter the card on the jrn
314  $W1->set_callback('filter_card');
315  $W1->set_function('fill_data');
316  $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
317  $W1->name);
318  $W1->readonly=false;
319  $array[$i]['quick_code']=$W1->input();
320  $array[$i]['bt']=$W1->search();
321 
322  $array[$i]['hidden']='';
323  // For computing we need some hidden field for holding the value
324  if ( $g_parameter->MY_TVA_USE=='Y')
325  {
326  $array[$i]['hidden'].=HtmlInput::hidden('tva_march'.$i,0);
327  }
328 
329  if ( $g_parameter->MY_TVA_USE=='Y')
330  $tvac=new INum('tvac_march'.$i);
331  else
332  $tvac=new IHidden('tvac_march'.$i);
333 
334  $tvac->readOnly=1;
335  $tvac->value=0;
336  $array[$i]['tvac']=$tvac->input();
337 
338  $htva=new INum('htva_march'.$i);
339  $htva->readOnly=1;
340 
341  $htva->value=0;
342  $array[$i]['htva']=$htva->input();
343 
344  if ( $g_parameter->MY_UPDLAB == 'Y')
345  {
346  $Span=new IText("e_march".$i."_label");
347  $Span->css_size="100%";
348  } else
349  {
350  $Span=new ISpan("e_march".$i."_label");
351  }
352  $Span->value=$march_label;
353  $Span->setReadOnly(false);
354  // card's name, price
355  //--
356  $array[$i]['denom']=$Span->input("e_march".$i."_label",$march_label);
357  // price
358  $Price=new INum();
359  $Price->prec=4;
360  $Price->setReadOnly(false);
361  $Price->size=9;
362  $Price->javascript="onBlur='format_number(this);clean_tva($i);compute_ledger($i)'";
363  $array[$i]['pu']=$Price->input("e_march".$i."_price",$march_price);
364  if ( $g_parameter->MY_TVA_USE=='Y')
365  {
366 
367  // vat label
368  //--
369  $Tva=new ITva_Popup($ledger->db);
370  $Tva->js="onblur=\"format_number(this);onChange=clean_tva($i);compute_ledger($i)\"";
371  $Tva->in_table=true;
372  $Tva->set_attribute('compute',$i);
373  $Tva->value=$march_tva_id;
374  $array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
375 
376  // Tva_amount
377 
378  // price
379  $Tva_amount=new INum();
380  $Tva_amount->setReadOnly(false);
381  $Tva_amount->size=9;
382  $Tva_amount->javascript="onBlur='format_number(this);compute_ledger($i)'";
383  $array[$i]['amount_tva']=$Tva_amount->input("e_march".$i."_tva_amount",$march_tva_amount);
384  }
385  // quantity
386  //--
387  $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"1"
388  ;
389  $Quantity=new INum();
390  $Quantity->setReadOnly(false);
391  $Quantity->size=9;
392  $Quantity->javascript="onChange=format_number(this);clean_tva($i);compute_ledger($i)";
393  $array[$i]['quantity']=$Quantity->input("e_quant".$i,$quant);
394 
395  }
396  $f_type=_('Fournisseur');
397 
398  ob_start();
399  require_once NOALYSS_TEMPLATE.'/predf_ledger_detail.php';
400  $r.=ob_get_contents();
401  ob_end_clean();
402 
403  // Set correctly the REQUEST param for jrn_type
404  $r.= HtmlInput::hidden('jrn_type','ACH');
405  $r.= HtmlInput::button('add_item',_('Ajout article'), ' onClick="ledger_add_row()"');
406 
407  return $r;
408  }
409 }
$_POST['ac']
Definition: do.php:279
static fetch_all($ret)
wrapper for the function pg_fetch_all
const ATTR_DEF_TVA
Definition: constant.php:190
const ATTR_DEF_ADRESS
Definition: constant.php:192
const FICADD
Handle the ledger of purchase,.
const ATTR_DEF_CP
Definition: constant.php:193
let you choose a TVA in a popup
static button($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
compute_array()
compute an array accordingly with the FormVenView function
if(!isset($_REQUEST['act'])||!isset($_REQUEST['jr_id'])||!isset($_REQUEST['div'])) global $g_parameter
Definition: ajax_ledger.php:46
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: class_fiche.php:44
concerns the predefined operation for ACH ledger
global $g_user
Find the default module or the first one.
Definition: action.inc.php:24
function trim(s)
remove trailing and heading space
Definition: scripts.js:95
mother of the pre_op_XXX, it contains only one data : an object Pre_Operation. The child class contai...
load()
load the data from the database and return an array
$count
Definition: modele.inc.php:255
const ATTR_DEF_CITY
Definition: constant.php:198
save()
save the detail and op in the database
Input HTML for the card show buttons, in the file, you have to add card.js How to use : ...
display($p_array)
return false
$SecUser db
const ATTR_DEF_NAME
Definition: constant.php:185
static hidden($p_name, $p_value, $p_id="")
__construct($cn, $p_id=0)
This class handles only the numeric input, the input will call a javascript to change comma to period...
Definition: class_inum.php:40