noalyss  Version-6.9.1.8
 All Data Structures Namespaces Files Functions Variables Pages
class_acc_ledger_purchase.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 class for the purchase, herits from acc_ledger
24  */
25 require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
26 require_once NOALYSS_INCLUDE.'/lib/class_icard.php';
27 require_once NOALYSS_INCLUDE.'/lib/class_ispan.php';
28 require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
29 require_once NOALYSS_INCLUDE.'/lib/class_iperiod.php';
30 require_once NOALYSS_INCLUDE.'/lib/class_idate.php';
31 require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
32 require_once NOALYSS_INCLUDE.'/lib/class_ifile.php';
33 require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
34 require_once NOALYSS_INCLUDE.'/class/class_acc_compute.php';
35 require_once NOALYSS_INCLUDE.'/class/class_anc_operation.php';
36 require_once NOALYSS_INCLUDE.'/lib/user_common.php';
37 require_once NOALYSS_INCLUDE.'/class/class_acc_parm_code.php';
38 require_once NOALYSS_INCLUDE.'/class/class_acc_payment.php';
39 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
40 require_once NOALYSS_INCLUDE.'/lib/class_itva_popup.php';
41 require_once NOALYSS_INCLUDE.'/class/class_acc_ledger_info.php';
42 require_once NOALYSS_INCLUDE.'/class/class_acc_ledger_fin.php';
43 require_once NOALYSS_INCLUDE.'/class/class_stock_goods.php';
44 
45 /*!\brief Handle the ledger of purchase,
46  *
47  *
48  */
50 {
51  function __construct ($p_cn,$p_init)
52  {
53  $this->type='ACH';
54  parent::__construct($p_cn,$p_init);
55  }
56  /*!\brief verify that the data are correct before inserting or confirming
57  *\param an array (usually $_POST)
58  *\return String
59  *\throw Exception if an error occurs
60  */
61  public function verify($p_array)
62  {
63  global $g_parameter,$g_user;
64 
65  if (is_array($p_array ) == false || empty($p_array))
66  throw new Exception ("Array empty");
67  /*
68  * Check needed value
69  */
70  check_parameter($p_array,'p_jrn,e_date,e_client');
71 
72  extract ($p_array, EXTR_SKIP);
73  /* check if we can write into this ledger */
74  if ( $g_user->check_jrn($p_jrn) != 'W' )
75  throw new Exception (_('Accès interdit'),20);
76 
77 
78  /* check for a double reload */
79  if ( isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1',array($mt)) != 0 )
80  throw new Exception (_('Double Encodage'),5);
81 
82  /* check if there is a customer */
83  if ( strlen(trim($e_client)) == 0 )
84  throw new Exception(_('Vous n\'avez pas donné de fournisseur'),11);
85 
86  /* check if the date is valid */
87  if ( isDate($e_date) == null )
88  {
89  throw new Exception(_('Date invalide'), 2);
90  }
91  $oPeriode=new Periode($this->db);
92  if ( $this->check_periode() == false || ! isset($p_array['period']))
93  {
94  $tperiode=$oPeriode->find_periode($e_date);
95  }
96  else
97  {
98  $tperiode=$period;
99  $oPeriode->p_id=$tperiode;
100  /* check that the datum is in the choosen periode */
101  list ($min,$max)=$oPeriode->get_date_limit($tperiode);
102  if ( cmpDate($e_date,$min) < 0 ||
103  cmpDate($e_date,$max) > 0)
104  throw new Exception(_('Date et periode ne correspondent pas'),6);
105  }
106  /* check if the periode is closed */
107  if ( $this->is_closed($tperiode)==1 )
108  {
109  throw new Exception(_('Periode fermee'),6);
110  }
111 
112  /* check if we are using the strict mode */
113  if( $this->check_strict() == true)
114  {
115  /* if we use the strict mode, we get the date of the last
116  operation */
117  $last_date=$this->get_last_date();
118  if ( $last_date != null && cmpDate($e_date,$last_date) < 0 )
119  throw new Exception(_('Vous utilisez le mode strict la dernière operation est à la date du ')
120  .$last_date._(' vous ne pouvez pas encoder à une '.
121  ' date antérieure dans ce journal'),13);
122 
123  }
124 
125  /* check the account */
126  $fiche=new Fiche($this->db);
127  $fiche->get_by_qcode($e_client);
128 
129  if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
130  throw new Exception(_('La fiche ').$e_client._('n\'a pas de poste comptable'),8);
131 
132  /* get the account and explode if necessary */
133  $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
134  // if 2 accounts, take only the credit one for supplier
135  if ( strpos($sposte,',') != 0 )
136  {
137  $array=explode(',',$sposte);
138  $poste_val=$array[1];
139  }
140  else
141  {
142  $poste_val=$sposte;
143  }
144 
145  /* The account exists */
146  $poste=new Acc_Account_Ledger($this->db,$poste_val);
147  if ( $poste->load() == false )
148  {
149  throw new Exception(_('Pour la fiche ').$e_client._(' le poste comptable [').$poste->id.'] '._('n\'existe pas'),9);
150  }
151  /* Check if the card belong to the ledger */
152  $fiche=new Fiche ($this->db);
153  $fiche->get_by_qcode($e_client,'cred');
154  if ( $fiche->belong_ledger($p_jrn) !=1 )
155  throw new Exception(_('La fiche ').$e_client._('n\'est pas accessible à ce journal'),10);
156 
157  $nb=0;
158  //------------------------------------------------------
159  // The "Paid By" check
160  //------------------------------------------------------
161  if ($e_mp != 0 ) $this->check_payment($e_mp,${"e_mp_qcode_".$e_mp});
162 
163 
164  //----------------------------------------
165  // foreach item
166  //----------------------------------------
167  for ($i=0;$i< $nb_item;$i++)
168  {
169  if ( strlen(trim(${'e_march'.$i}))== 0) continue;
170  /* check if amount are numeric and */
171  if ( isNumber(${'e_march'.$i.'_price'}) == 0 )
172  throw new Exception(_('La fiche ').${'e_march'.$i}._('a un montant invalide').' ['.${'e_march'.$i}.']',6);
173  if ( isNumber(${'e_quant'.$i}) == 0 )
174  throw new Exception(_('La fiche ').${'e_march'.$i}._('a une quantité invalide').' ['.${'e_quant'.$i}.']',7);
175 
176  // Check if the given tva id is valid
177  if ( $g_parameter->MY_TVA_USE=='Y')
178  {
179  if (${'e_march'.$i.'_tva_id'} == 0 )
180  throw new Exception(_('La fiche ').${'e_march'.$i}._('a un code tva invalide').' ['.${'e_march'.$i.'_tva_id'}.']',13);
181  $tva_rate=new Acc_Tva($this->db);
182  $tva_rate->set_parameter('id',${'e_march'.$i.'_tva_id'});
183 
184  if ( $tva_rate->load() != 0 )
185  throw new Exception(_('La fiche ').${'e_march'.$i}._('a un code tva invalide').' ['.${'e_march'.$i.'_tva_id'}.']',13);
186  /*
187  * check if the accounting for VAT are valid
188  */
189  $a_poste=explode(',',$tva_rate->tva_poste);
190 
191  if (
192  $this->db->get_value('select count(*) from tmp_pcmn where pcm_val=$1',array($a_poste[0])) == 0 ||
193  $this->db->get_value('select count(*) from tmp_pcmn where pcm_val=$1',array($a_poste[1])) == 0 )
194  throw new Exception(_(" La TVA ".$tva_rate->tva_label." utilise des postes comptables inexistants"));
195 
196  }
197  /* check if all card has a ATTR_DEF_ACCOUNT*/
198  $fiche=new Fiche($this->db);
199  $fiche->get_by_qcode(${'e_march'.$i});
200  if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
201  throw new Exception(_('La fiche ').${'e_march'.$i}._('n\'a pas de poste comptable'),8);
202 
203  /* get the account and explode if necessary */
204  $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
205  // if 2 accounts, take only the debit
206  if ( strpos($sposte,',') != 0 )
207  {
208  $array=explode(',',$sposte);
209  $poste_val=$array[0];
210  }
211  else
212  {
213  $poste_val=$sposte;
214  }
215 
216  /* The account exists */
217  $poste=new Acc_Account_Ledger($this->db,$poste_val);
218  if ( $poste->load() == false )
219  {
220  throw new Exception(_('Pour la fiche ').${'e_march'.$i}._(' le poste comptable').' ['.$poste->id._('n\'existe pas'),9);
221  }
222  /* Check if the card belong to the ledger */
223  $fiche=new Fiche ($this->db);
224  $fiche->get_by_qcode(${'e_march'.$i});
225  if ( $fiche->belong_ledger($p_jrn,'deb') !=1 )
226  throw new Exception(_('La fiche ').${'e_march'.$i}._('n\'est pas accessible à ce journal'),10);
227  /**
228  * we have to check also if the different accountings exist
229  "ATTR_DEF_DEP_PRIV"
230  "ATTR_DEF_DEPENSE_NON_DEDUCTIBLE"
231  "ATTR_DEF_TVA_NON_DEDUCTIBLE"
232  "ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP"
233  */
234  foreach (array(
239  {
240  if ( ! $fiche->empty_attribute($key[0]) && $fiche->empty_attribute($key[2]))
241  {
242  $a=new Acc_Parm_Code($this->db,$key[1]);
243  if ( $this->db->count_sql('select pcm_val from tmp_pcmn where pcm_val=$1',array($a->p_value))==0)
244  throw new Exception ($key[1]._("ce code n'a pas de poste comptable, créez ce poste : [".$a->p_value."]"));
245  }
246  if ( ! $fiche->empty_attribute($key[0]) && ! $fiche->empty_attribute($key[2]))
247  {
248  $nd_str=$fiche->strAttribut($key[2]);
249  if ( $nd_str != '')
250  {
251  $poste_nd=new Acc_Account_Ledger($this->db,$nd_str);
252  if ( $poste_nd->load() == false)
253  {
254  $nd_msg=sprintf(_("Pour la fiche %s, le compte contrepartie %s n'existe pas"),
255  $fiche->getName(),$poste_nd->id);
256  $nd_msg=h($nd_msg);
257  throw new Exception ($nd_msg);
258  }
259  }
260  }
261  }
262  $nb++;
263  }
264 
265  if ( $nb == 0 )
266  throw new Exception(_('Il n\'y a aucune marchandise'),12);
267 
268  }
269  /**
270  * Compute the ND amount thanks the attribute of the concerned card. The object
271  * $p_nd_amount will changed
272  *
273  * @param Acc_Compute $p_nd_amount object with ND amount
274  * @param Fiche $p_fiche Concerned Card (purchase items)
275  * @param type $p_tva_bot 0 TVA on one side, 1 TVA on both side
276  */
277  private function compute_no_deductible(Acc_Compute $p_nd_amount, Fiche $p_fiche)
278  {
280  {
281  $p_nd_amount->amount_nd_rate = $p_fiche->strAttribut(ATTR_DEF_DEPENSE_NON_DEDUCTIBLE);
282  $p_nd_amount->compute_nd();
283  }
285  {
286  $p_nd_amount->nd_vat_rate = $p_fiche->strAttribut(ATTR_DEF_TVA_NON_DEDUCTIBLE);
287  $p_nd_amount->compute_nd_vat();
288  }
290  {
291  $p_nd_amount->nd_ded_vat_rate = $p_fiche->strAttribut(ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP);
292  $p_nd_amount->compute_ndded_vat();
293  }
294 
295  if (!$p_fiche->empty_attribute(ATTR_DEF_DEP_PRIV))
296  {
297  $p_nd_amount->amount_perso_rate = $p_fiche->strAttribut(ATTR_DEF_DEP_PRIV);
298  $p_nd_amount->compute_perso();
299  }
300 
301  }
302 
303  /**
304  * Insert into JRNX the No Deductible amount and into Analytic Accountancy for the ND VAT
305  * @param Acc_Compute $p_nd_amount content ND amount
306  * @param Fiche $p_fiche Card of the Service
307  * @param type $p_tva_both 0 if TVA is normal or 1 if on both side
308  * @param type $p_tot_debit total debit
309  * @param $p_acc_operation Acc_Operation for inserting into jrnx
310  * @param $p_group group for AC
311  * @param $idx row number
312  *
313  * @see Acc_Ledger_Purchase::insert
314  */
315  private function insert_no_deductible(Acc_Compute $p_nd_amount, Fiche $p_fiche, $p_tva_both,&$p_tot_debit,Acc_Operation $p_acc_operation,$p_group,$idx)
316  {
317  global $g_parameter;
318  if ($p_acc_operation->jrnx_id == 0) {
319  throw new Exception(__FILE__.__LINE__.'invalid acc_operation.j_id');
320  }
321  $source_j_id=$p_acc_operation->jrnx_id ;
322  /*
323  * Save all the no deductible
324  * ATTR_DEF_ACCOUNT_ND_TVA,ATTR_DEF_ACCOUNT_ND_TVA_ND,ATTR_DEF_ACCOUNT_ND_PERSO,ATTR_DEF_ACCOUNT_ND
325  */
326  if ($p_nd_amount->amount_nd_rate != 0)
327  {
328  $dna_default = new Acc_Parm_Code($this->db, 'DNA');
329 
330  /* save op. */
331  if (!$p_fiche->empty_attribute(ATTR_DEF_ACCOUNT_ND))
332  {
333  $dna = $p_fiche->strAttribut(ATTR_DEF_ACCOUNT_ND);
334  } else
335  {
336  $dna = $dna_default->p_value;
337  }
338  $dna = ($dna == '') ? $dna_default->p_value : $dna;
339 
340  $p_acc_operation->type = 'd';
341  $p_acc_operation->amount = $p_nd_amount->amount_nd;
342  $p_acc_operation->poste = $dna;
343  $p_acc_operation->qcode = '';
344  $p_acc_operation->desc=$this->find_label($dna)." ND ".$p_fiche->strAttribut(ATTR_DEF_QUICKCODE);
345  if ($p_nd_amount->amount_nd > 0)
346  $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->amount_nd );
347  $j_id = $p_acc_operation->insert_jrnx();
348  }
349  /*
350  * ATTR_DEF_ACCOUNT_ND_PERSO
351  */
352  if ($p_nd_amount->amount_perso != 0)
353  {
354  $dna_default = new Acc_Parm_Code($this->db, 'DEP_PRIV');
355 
356  /* save op. */
357  $p_acc_operation->type = 'd';
359  {
360  $dna = $p_fiche->strAttribut(ATTR_DEF_ACCOUNT_ND_PERSO);
361  } else
362  {
363  $dna = $dna_default->p_value;
364  }
365  $dna = ($dna == '') ? $dna_default->p_value : $dna;
366 
367  $p_acc_operation->amount = $p_nd_amount->amount_perso ;
368  $p_acc_operation->poste = $dna;
369  $p_acc_operation->qcode = '';
370  $p_acc_operation->desc=$this->find_label($dna)." ND_PRIV ".$p_fiche->strAttribut(ATTR_DEF_QUICKCODE);
371  if ($p_nd_amount->amount_perso> 0)
372  $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->amount_perso);
373  $j_id = $p_acc_operation->insert_jrnx();
374  }
375  if ($p_nd_amount->nd_vat != 0)
376  {
377  $dna_default = new Acc_Parm_Code($this->db, 'TVA_DNA');
378 
379  /* save op. */
380  $p_acc_operation->type = 'd';
381  $p_acc_operation->qcode = '';
383  {
384  $dna = $p_fiche->strAttribut(ATTR_DEF_ACCOUNT_ND_TVA_ND);
385  } else
386  {
387  $dna = $dna_default->p_value;
388  }
389  $dna = ($dna == '') ? $dna_default->p_value : $dna;
390 
391  $p_acc_operation->amount = $p_nd_amount->nd_vat;
392  $p_acc_operation->poste = $dna;
393  $p_acc_operation->desc=$this->find_label($dna)." ND_TVA ".$p_fiche->strAttribut(ATTR_DEF_QUICKCODE);
394  $j_id = $p_acc_operation->insert_jrnx();
395  if ( $g_parameter->MY_ANALYTIC != "nu" )
396  {
397  $op=new Anc_Operation($this->db);
398  $op->oa_group=$p_group;
399  $op->j_id=$j_id;
400  $op->oa_date=$p_acc_operation->date;
401 
402  $op->oa_debit='t';
403  $op->oa_description=sql_string('ND_TVA');
404  $op->oa_jrnx_id_source=$source_j_id;
405  $op->save_form_plan_vat_nd($_POST,$idx,$j_id,$p_nd_amount->nd_vat,$p_acc_operation->jrnx_id);
406  }
407  if ($p_nd_amount->nd_vat> 0)
408  $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->nd_vat);
409 
410  }
411  if ($p_nd_amount->nd_ded_vat != 0)
412  {
413  $dna_default = new Acc_Parm_Code($this->db, 'TVA_DED_IMPOT');
414  /* save op. */
415  if (!$p_fiche->empty_attribute(ATTR_DEF_ACCOUNT_ND_TVA) )
416  {
417  $dna = $p_fiche->strAttribut(ATTR_DEF_ACCOUNT_ND_TVA);
418  } else
419  {
420  $dna = $dna_default->p_value;
421  }
422  $dna = ($dna == '') ? $dna_default->value : $dna;
423 
424 
425 
426  $p_acc_operation->type = 'd';
427  $p_acc_operation->qcode = '';
428  $p_acc_operation->amount = $p_nd_amount->nd_ded_vat;
429  $p_acc_operation->poste = $dna;
430  $p_acc_operation->desc=$this->find_label($dna)." DED_TVA ".$p_fiche->strAttribut(ATTR_DEF_QUICKCODE);
431  if ($p_nd_amount->nd_ded_vat > 0)
432  $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->nd_ded_vat);
433  $j_id = $p_acc_operation->insert_jrnx();
434  if ( $g_parameter->MY_ANALYTIC != "nu" )
435  {
436  $op=new Anc_Operation($this->db);
437  $op->oa_group=$p_group;
438  $op->j_id=$j_id;
439  $op->oa_date=$p_acc_operation->date;
440 
441  $op->oa_debit='t';
442  $op->oa_description=sql_string('DED_TVA ');
443  $op->oa_jrnx_id_source=$source_j_id;
444  $op->save_form_plan_vat_nd($_POST,$idx,$j_id,$p_nd_amount->nd_ded_vat);
445  }
446  }
447  }
448 
449  /*!\brief insert into the database, it calls first the verify function
450  * change the value of this->jr_id and this->jr_internal.
451  * It generates the document and save the middle of payment, if 'gen_invoice is set
452  * and e_mp
453  *\param $p_array is usually $_POST or a predefined operation
454  \code
455  Array
456  (
457 
458  [e_client] =>BELGACOM
459  [nb_item] =>9
460  [p_jrn] =>3
461  [period] =>117
462  [e_comm] =>Frais de téléphone
463  [e_date] =>01.09.2009
464  [e_ech] =>
465  [jrn_type] =>ACH
466  [e_pj] =>ACH53
467  [e_pj_suggest] =>ACH53
468  [mt] =>1265318941.39
469  [e_mp] =>0
470  [e_march0] =>TEL
471  [e_march0_price] =>63.6700
472  [e_march0_tva_id] =>1
473  [e_march0_tva_amount] =>13.3700
474  [e_quant0] =>1.000
475  ...
476  [bon_comm] =>
477  [other_info] =>
478  [record] =>Enregistrement
479  )
480  \endcode
481  *\return string
482  *\note throw an Exception
483  */
484  public function insert($p_array=null)
485  {
486  global $g_parameter;
487  extract ($p_array, EXTR_SKIP);
488  $this->verify($p_array) ;
489 
490  $group=$this->db->get_next_seq("s_oa_group"); /* for analytic */
491  $seq=$this->db->get_next_seq('s_grpt');
492  $this->id=$p_jrn;
493 
494  $internal=$this->compute_internal_code($seq);
495  $this->internal=$internal;
496 
497  $cust=new Fiche($this->db);
498  $cust->get_by_qcode($e_client);
499  $sposte=$cust->strAttribut(ATTR_DEF_ACCOUNT);
500  // if 2 accounts, take only the credit Supplier
501  if ( strpos($sposte,',') != 0 )
502  {
503  $array=explode(',',$sposte);
504  $poste=$array[1];
505  }
506  else
507  {
508  $poste=$sposte;
509  }
510 
511  $oPeriode=new Periode($this->db);
512  $check_periode=$this->check_periode();
513 
514  if ( $check_periode == true && isset($p_array['period']) )
515  $tperiode=$period;
516  else
517  $tperiode=$oPeriode->find_periode($e_date);
518 
519 
520  try
521  {
522  bcscale(4);
523  $tot_amount=0;
524  $tot_tva=0;
525  $tot_debit=0;
526  $this->db->start();
527  $tot_nd=0;
528  $tot_perso=0;
529  $tot_tva_nd=0;
530  $tot_tva_ndded=0;
531  $tot_tva_reversed=0;
532  $tva=array();
533  /* Save all the items without vat and no deductible vat and expense*/
534  for ($i=0;$i< $nb_item;$i++)
535  {
536  $n_both=0;
537  if ( strlen(trim(${'e_march'.$i})) == 0 ) continue;
538 
539  /* First we save all the items without vat */
540  $fiche=new Fiche($this->db);
541  $fiche->get_by_qcode(${"e_march".$i});
542  $tva_both=0;
543  /* tva */
544  if ($g_parameter->MY_TVA_USE=='Y')
545  {
546  $idx_tva=${'e_march'.$i.'_tva_id'};
547  $oTva=new Acc_Tva($this->db);
548  $oTva->set_parameter('id',$idx_tva);
549  $oTva->load();
550  $tva_both=$oTva->get_parameter("both_side");
551  }
552  /* -- Create acc_operation -- */
553  $acc_operation=new Acc_Operation($this->db);
554  $acc_operation->date=$e_date;
555  $acc_operation->grpt=$seq;
556  $acc_operation->jrn=$p_jrn;
557  $acc_operation->type='d';
558  $acc_operation->periode=$tperiode;
559  $acc_operation->qcode="";
560  $amount_4=bcmul(${'e_march'.$i.'_price'},${'e_quant'.$i});
561  /* We have to compute all the amount thanks Acc_Compute */
562  $amount=round($amount_4,2);
563 
564  $acc_amount=new Acc_Compute();
565  $acc_amount->check=false;
566  $acc_amount->set_parameter('amount',$amount);
567 
568  // Compute VAT or take the given one
569  if ( $g_parameter->MY_TVA_USE=='Y')
570  {
571  $acc_amount->set_parameter('amount_vat_rate',$oTva->get_parameter('rate'));
572  if ( strlen(trim(${'e_march'.$i.'_tva_amount'})) ==0 || ${'e_march'.$i.'_tva_amount'} == 0)
573  {
574  $acc_amount->compute_vat();
575 
576  }
577  else
578  {
579  $acc_amount->amount_vat= ${'e_march'.$i.'_tva_amount'};
580 
581  }
582  $tot_tva=bcadd($tot_tva,$acc_amount->amount_vat);
583  }
584 
585 
586  /* compute ND */
587  $save_amount_vat=$acc_amount->amount_vat;
588  $this->compute_no_deductible($acc_amount, $fiche);
589  $acc_amount->correct();
590  // TVA which avoid
591  $acc_amount->amount_unpaid=($tva_both == 1 ) ? $save_amount_vat :0 ;
592  $tot_tva_reversed=bcadd($tot_tva_reversed,$acc_amount->amount_unpaid);
593 
594 
595 
596  $tot_amount=round(bcadd($tot_amount,$amount),2);
597 
598  /* get the account and explode if necessary */
599  $sposte=$fiche->strAttribut(ATTR_DEF_ACCOUNT);
600  // if 2 accounts, take only the debit one for customer
601  if ( strpos($sposte,',') != 0 )
602  {
603  $array=explode(',',$sposte);
604  $poste_val=$array[0];
605  }
606  else
607  {
608  $poste_val=$sposte;
609  }
610  if ( $g_parameter->MY_UPDLAB=='Y')
611  $acc_operation->desc=strip_tags(${"e_march".$i."_label"});
612  else
613  $acc_operation->desc=null;
614  $acc_operation->poste=$poste_val;
615  $acc_operation->amount=$acc_amount->amount;
616  $acc_operation->qcode=${"e_march".$i};
617  if( $acc_amount->amount > 0 ) $tot_debit=bcadd($tot_debit,$acc_amount->amount);
618  $j_id=$acc_operation->insert_jrnx();
619 
620  /* insert ND */
621  $this->insert_no_deductible($acc_amount, $fiche, $tva_both, $tot_debit,$acc_operation,$group,$i);
622 
623 
624  /* Compute sum vat */
625  if ( $g_parameter->MY_TVA_USE=='Y')
626  {
627  $tva_item=$acc_amount->amount_vat;
628 
629  if (isset($tva[$idx_tva] ) )
630  $tva[$idx_tva]=bcadd($tva[$idx_tva],$tva_item);
631  else
632  $tva[$idx_tva]=$tva_item;
633 
634  }
635  /* Save the stock */
636  /* if the quantity is < 0 then the stock increase (return of
637  * material)
638  */
639  $nNeg=(${"e_quant" . $i}< 0) ? -1 : 1;
640 
641  // always save quantity but in withStock we can find
642  // what card need a stock management
643  if ( $g_parameter->MY_STOCK='Y'&& isset ($repo))
644  {
645  $dir=(${'e_quant'.$i} < 0 ) ? 'c':'d';
646  Stock_Goods::insert_goods($this->db,array('j_id'=>$j_id,'goods'=>${'e_march'.$i},'quant'=>$nNeg*${'e_quant'.$i},'dir'=>$dir,'repo'=>$repo)) ;
647  }
648 
649  if ( $g_parameter->MY_ANALYTIC != "nu" )
650  {
651  // for each item, insert into operation_analytique */
652  $op=new Anc_Operation($this->db);
653  $op->oa_group=$group;
654  $op->j_id=$j_id;
655  $op->oa_date=$e_date;
656  $op->oa_debit='t';
657  $op->oa_description=sql_string($e_comm);
658  $op->save_form_plan($_POST,$i,$j_id);
659  }
660  // insert into quant_purchase
661  //-----
662  if ( $g_parameter->MY_TVA_USE=='Y')
663  {
664 
665  $r=$this->db->exec_sql("select insert_quant_purchase ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)",
666  array(
667  null /*1*/
668  ,$j_id /* 2 */
669  ,${"e_march".$i} /* 3 */
670  ,${"e_quant".$i} /* 4 */
671  ,round($amount,2) /* 5 */
672  ,$acc_amount->amount_vat /* 6 */
673  ,$oTva->get_parameter('id') /* 7 */
674  ,$acc_amount->amount_nd /* 8 */
675  ,$acc_amount->nd_vat /* 9 */
676  ,$acc_amount->nd_ded_vat /* 10 */
677  ,$acc_amount->amount_perso /* 11 */
678  ,$e_client /* 12 */
679  , $acc_amount->amount_unpaid /*13*/
680  ,${'e_march'.$i.'_price'} /* 14 */
681  ));
682 
683 
684  }
685  else
686  {
687  $r=$this->db->exec_sql("select insert_quant_purchase ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)",
688  array(
689  null /*1*/
690  ,$j_id /* 2 */
691  ,${"e_march".$i} /* 3 */
692  ,${"e_quant".$i} /* 4 */
693  ,round($amount,2) /* 5 */
694  ,0 /* 6 */
695  ,null/* 7 */
696  ,$acc_amount->amount_nd /* 8 */
697  ,0 /* 9 */
698  ,$acc_amount->nd_ded_vat /* 10 */
699  ,$acc_amount->amount_perso /* 11 */
700  ,$e_client /* 12 */
701  , $acc_amount->amount_unpaid /*13*/
702  ,${'e_march'.$i.'_price'} /* 14 */
703  ));
704  }
705 
706  } // end loop : save all items
707  /* save total customer */
708  $cust_amount=round(bcadd($tot_amount,$tot_tva),2);
709  $acc_operation=new Acc_Operation($this->db);
710  $acc_operation->date=$e_date;
711  $acc_operation->poste=$poste;
712  $acc_operation->amount=bcsub($cust_amount,$tot_tva_reversed);
713  $acc_operation->grpt=$seq;
714  $acc_operation->jrn=$p_jrn;
715  $acc_operation->type='c';
716  $acc_operation->periode=$tperiode;
717  $acc_operation->qcode=${"e_client"};
718  if ( $cust_amount < 0 )
719  $tot_debit=bcadd($tot_debit,abs($cust_amount));
720  $let_client=$acc_operation->insert_jrnx();
721 
722 
723  if ( $g_parameter->MY_TVA_USE=='Y')
724  {
725  /* save all vat
726  * $i contains the tva_id and value contains the vat amount
727  */
728  foreach ($tva as $i => $value)
729  {
730  $oTva=new Acc_Tva($this->db);
731  $oTva->set_parameter('id',$i);
732  $oTva->load();
733 
734  $poste_vat=$oTva->get_side('d');
735 
736  $cust_amount=bcadd($tot_amount,$tot_tva);
737  $acc_operation=new Acc_Operation($this->db);
738  $acc_operation->date=$e_date;
739  $acc_operation->poste=$poste_vat;
740  $acc_operation->amount=$value;
741  $acc_operation->grpt=$seq;
742  $acc_operation->jrn=$p_jrn;
743  $acc_operation->type='d';
744  $acc_operation->periode=$tperiode;
745  if ( $value > 0 ) $tot_debit=bcadd($tot_debit,abs($value));
746  $acc_operation->insert_jrnx();
747  // if TVA is on both side, we deduce it immediately
748  if ( $oTva->get_parameter("both_side")==1)
749  {
750  $poste_vat=$oTva->get_side('c');
751 
752  $acc_operation=new Acc_Operation($this->db);
753  $acc_operation->date=$e_date;
754  $acc_operation->poste=$poste_vat;
755  $acc_operation->amount=$tot_tva_reversed;
756  $acc_operation->grpt=$seq;
757  $acc_operation->jrn=$p_jrn;
758  $acc_operation->type='c';
759  $acc_operation->periode=$tperiode;
760  $acc_operation->insert_jrnx();
761  if ( $value < 0 ) $tot_debit=bcadd($tot_debit,abs($value));
762  }
763 
764  }
765  }
766  /* insert into jrn */
767  $acc_operation=new Acc_Operation($this->db);
768  $acc_operation->date=$e_date;
769  $acc_operation->echeance=$e_ech;
770  // Total DEB
771  $acc_operation->amount=$this->db->get_value("select sum(j_montant) from jrnx where j_grpt = $1 and j_debit='t'",
772  array($seq));
773  $acc_operation->desc=$e_comm;
774  $acc_operation->grpt=$seq;
775  $acc_operation->jrn=$p_jrn;
776  $acc_operation->periode=$tperiode;
777  $acc_operation->pj=$e_pj;
778  $acc_operation->mt=$mt;
779  $this->jr_id=$acc_operation->insert_jrn();
780  $this->pj=$acc_operation->set_pj();
781 
782  // Set Internal code
783  $this->grpt_id=$seq;
784  $this->update_internal_code($internal);
785  /* update quant_purchase */
786  $this->db->exec_sql('update quant_purchase set qp_internal = $1 where j_id in (select j_id from jrnx where j_grpt=$2)',
787  array($internal,$seq));
788 
789  /**= e_pj then do not increment sequence */
790  if ( strcmp($e_pj,$e_pj_suggest) == 0 && strlen(trim($e_pj)) != 0 )
791  {
792  $this->inc_seq_pj();
793  }
794 
795  /* Save the attachment */
796  if ( isset ($_FILES))
797  {
798  if ( sizeof($_FILES) != 0 )
799  $this->db->save_receipt($seq);
800  }
801  $str_file="";
802  /* Generate an document and save it into the database (Note de frais only)
803  */
804  if ( isset($_POST['gen_invoice']) )
805  {
806  $ref_doc= $this->create_document($internal,$p_array);
807  $this->doc=HtmlInput::show_receipt_document($this->jr_id,h($ref_doc));
808  }
809 
810  //----------------------------------------
811  // Save the payer
812  //----------------------------------------
813  if ( $e_mp != 0 )
814  {
815  /* mp */
816  $mp=new Acc_Payment($this->db,$e_mp);
817  $mp->load();
818 
819  /* fiche */
820  if ($mp->get_parameter('qcode') == '')
821  $fqcode=${'e_mp_qcode_'.$e_mp};
822  else
823  $fqcode=$mp->get_parameter('qcode');
824 
825  $acfiche = new Fiche($this->db);
826  $acfiche->get_by_qcode($fqcode);
827 
828  /* jrnx */
829  $acseq=$this->db->get_next_seq('s_grpt');
830  $acjrn=new Acc_Ledger($this->db,$mp->get_parameter('ledger_target'));
831  $acinternal=$acjrn->compute_internal_code($acseq);
832 
833  /* Insert paid by */
834  $acc_pay=new Acc_Operation($this->db);
835  $acc_pay->date=$e_date;
836 
837  /* get the account and explode if necessary */
838  $sposte=$acfiche->strAttribut(ATTR_DEF_ACCOUNT);
839  // if 2 accounts, take only the debit one for customer
840  if ( strpos($sposte,',') != 0 )
841  {
842  $array=explode(',',$sposte);
843  $poste_val=$array[1];
844  }
845  else
846  {
847  $poste_val=$sposte;
848  }
849  // remove the VAT autoliquidation
850  $cust_amount=bcsub($cust_amount, $tot_tva_reversed);
851  $famount=bcsub($cust_amount,$acompte);
852  $acc_pay->poste=$poste_val;
853  $acc_pay->qcode=$fqcode;
854  $acc_pay->amount=abs(round($famount,2));
855  $acc_pay->desc='';
856  $acc_pay->grpt=$acseq;
857  $acc_pay->jrn=$mp->get_parameter('ledger_target');
858  $acc_pay->periode=$tperiode;
859  $acc_pay->type=($famount>=0)?'c':'d';
860  $acc_pay->insert_jrnx();
861 
862  /* Insert supplier */
863  $acc_pay=new Acc_Operation($this->db);
864  $acc_pay->date=$e_date;
865  $acc_pay->poste=$poste;
866  $acc_pay->qcode=$e_client;
867  $acc_pay->amount=abs(round($famount,2));
868  $acc_pay->desc='';
869  $acc_pay->grpt=$acseq;
870  $acc_pay->jrn=$mp->get_parameter('ledger_target');
871  $acc_pay->periode=$tperiode;
872  $acc_pay->type=($famount>=0)?'d':'c';
873  $let_other=$acc_pay->insert_jrnx();
874 
875  /* insert into jrn */
876  $acc_pay->mt=$mt;
877  $acc_pay->desc=(!isset($e_comm_paiement) || strlen(trim($e_comm_paiement)) == 0) ?$e_comm:$e_comm_paiement;
878  $mp_jr_id=$acc_pay->insert_jrn();
879  $acjrn->grpt_id=$acseq;
880  $acjrn->update_internal_code($acinternal);
881 
882  $r1=$this->get_id($internal);
883  $r2=$this->get_id($acinternal);
884 
885  /*
886  * add lettering
887  */
888  $oletter=new Lettering($this->db);
889  $oletter->insert_couple($let_client,$let_other);
890 
891  /* set the flag paid */
892  $Res=$this->db->exec_sql("update jrn set jr_rapt='paid' where jr_id=$1",array($r1));
893 
894  /* Reconcialiation */
895  $rec=new Acc_Reconciliation($this->db);
896  $rec->set_jr_id($r1);
897  $rec->insert($r2);
898  /*
899  * save also into quant_fin
900  */
901 
902  /* get ledger property */
903  $ledger=new Acc_Ledger_Fin($this->db,$acc_pay->jrn);
904  $prop=$ledger->get_propertie();
905 
906  /* if ledger is FIN then insert into quant_fin */
907  if ( $prop['jrn_def_type'] == 'FIN' )
908  {
909  $ledger->insert_quant_fin($acfiche->id,$mp_jr_id,$cust->id,bcmul($famount,-1));
910  }
911 
912 
913  }
914  }//end try
915  catch (Exception $e)
916  {
917  echo '<span class="error">'.
918  'Erreur dans l\'enregistrement '.
919  __FILE__.':'.__LINE__.' '.
920  $e->getMessage().$e->getMessage();
921  error_log($e->getMessage());
922  $this->db->rollback();
923  throw new Exception($e);
924  }
925  $this->db->commit();
926  return $internal;
927  }
928 
929  /*!\brief display the form for entering data for invoice
930  *\param $p_array is null or you can put the predef operation or the $_POST
931  \code
932  array
933  'sa' => string 'n' (length=1)
934  'p_action' => string 'ach' (length=3)
935  'gDossier' => string '28' (length=2)
936  'e_client' => string 'ASEKURA' (length=7)
937  'nb_item' => string '9' (length=1)
938  'p_jrn' => string '3' (length=1)
939  'period' => string '126' (length=3)
940  'e_comm' => string 'descriptio' (length=10)
941  'e_date' => string '01.05.2010' (length=10)
942  'e_ech' => string '' (length=0)
943  'jrn_type' => string 'ACH' (length=3)
944  'e_pj' => string 'ACH37' (length=5)
945  'e_pj_suggest' => string 'ACH37' (length=5)
946  'mt' => string '1273759434.5701' (length=15)
947  'e_mp' => string '0' (length=1)
948  'e_march0' => string 'DOC' (length=3)
949  'e_march0_price' => string '2000' (length=4)
950  'e_march0_tva_id' => string '3' (length=1)
951  'e_march0_tva_amount' => string '120' (length=3)
952  'e_quant0' => string '1' (length=1)
953  'gen_invoice' => string 'on' (length=2)
954  'gen_doc' => string '7' (length=1)
955  'bon_comm' => string '' (length=0)
956  'other_info' => string '' (length=0)
957  'correct' => string 'Corriger' (length=8)
958  \endcode
959  *\return HTML string
960  */
961  public function input($p_array=null,$p_readonly=0)
962  {
963  global $g_parameter,$g_user;
964  if ( $p_array != null ) extract($p_array, EXTR_SKIP);
965 
966  $flag_tva=$g_parameter->MY_TVA_USE;
967  /* Add button */
968  $f_add_button=new IButton('add_card');
969  $f_add_button->label=_('Créer une nouvelle fiche');
970  $f_add_button->tabindex=-1;
971  $f_add_button->set_attribute('jrn',$this->id);
972  $f_add_button->javascript=" this.jrn=\$('p_jrn').value;select_card_type(this);";
973 
974  $str_add_button="";
975  if ($g_user->check_action(FICADD)==1)
976  {
977  $str_add_button=$f_add_button->input();
978  }
979  // The first day of the periode
980  $oPeriode=new Periode($this->db);
981  list ($l_date_start,$l_date_end)=$oPeriode->get_date_limit($g_user->get_periode());
982  if ( $g_parameter->MY_DATE_SUGGEST=='Y' )
983  $op_date=( ! isset($e_date) ) ?$l_date_start:$e_date;
984  else
985  $op_date=( ! isset($e_date) ) ?'':$e_date;
986 
987  $e_ech=(isset($e_ech))?$e_ech:"";
988  $e_comm=(isset($e_comm))?$e_comm:"";
989 
990  $r="";
991  $r.=dossier::hidden();
992  $f_legend_detail=_("Détail articles achetés");
993 
994  // Date
995  //--
996  $Date=new IDate();
997  $Date->setReadOnly(false);
998  $Date->table=1;
999  $Date->tabindex=1;
1000  $f_date=$Date->input("e_date",$op_date);
1001  // Payment limit
1002  //--
1003  $Echeance=new IDate();
1004  $Echeance->setReadOnly(false);
1005  $Echeance->tabindex=2;
1007  $f_echeance=$Echeance->input('e_ech',$e_ech,'Echéance'.$label);
1008  $f_periode="";
1009  if ($this->check_periode() == true)
1010  {
1011  // Periode
1012  //--
1013  $l_user_per=$g_user->get_periode();
1014  $def=(isset($periode))?$periode:$l_user_per;
1015 
1016  $period=new IPeriod("period");
1017  $period->user=$g_user;
1018  $period->cn=$this->db;
1019  $period->value=$def;
1020  $period->type=OPEN;
1021  try
1022  {
1023  $l_form_per=$period->input();
1024  }
1025  catch (Exception $e)
1026  {
1027  if ($e->getCode() == 1 )
1028  {
1029  throw new Exception( _("Aucune période ouverte"));
1030  }
1031  }
1032 
1033  $r.="<td>";
1035  $f_periode=td(_("Période comptable")." $label ").td($l_form_per);
1036  }
1037  // Ledger (p_jrn)
1038  //--
1039  /* if we suggest the next pj, then we need a javascript */
1040  $add_js="";
1041  if ( $g_parameter->MY_PJ_SUGGEST=='Y')
1042  {
1043  $add_js="update_pj();";
1044 }
1045  if ($g_parameter->MY_DATE_SUGGEST == 'Y')
1046  {
1047  $add_js.='get_last_date();';
1048  }
1049  $add_js.='update_name();';
1050  $add_js.='update_pay_method();';
1051  $add_js.='update_row("sold_item");';
1052 
1053  $wLedger=$this->select_ledger('ACH',2);
1054 
1055  if ($wLedger == null) throw new Exception(_('Pas de journal disponible'));
1056  $wLedger->javascript="onChange='update_predef(\"ach\",\"f\",\"".$_REQUEST['ac']."\");$add_js'";
1057  $wLedger->table=1;
1058  $f_jrn=$wLedger->input();
1059 
1060  // Comment
1061  //--
1062  $Commentaire=new IText();
1063  $Commentaire->table=0;
1064  $Commentaire->setReadOnly(false);
1065  $Commentaire->size=60;
1066  $Commentaire->tabindex=3;
1068  $f_desc=$Commentaire->input("e_comm",h($e_comm));
1069 
1070  // PJ
1071  //--
1072  /* suggest PJ ? */
1073  $default_pj='';
1074  if ( $g_parameter->MY_PJ_SUGGEST=='Y')
1075  {
1076  $default_pj=$this->guess_pj();
1077  }
1078 
1079  $pj=new IText();
1080  $pj->value=(isset($e_pj))?$e_pj:$default_pj;
1081 
1082 
1083  $pj->table=0;
1084  $pj->name="e_pj";
1085  $pj->size=10;
1086  $pj->readonly=false;
1087 
1088  $f_pj=$pj->input().HtmlInput::hidden('e_pj_suggest',$default_pj);
1089 
1090  // Display the customer
1091  //--
1092  $fiche='cred';
1093 
1094  // Save old value and set a new one
1095  //--
1096  $e_client=( isset ($e_client) )?$e_client:"";
1097  $e_client_label="&nbsp;";//str_pad("",100,".");
1098 
1099 
1100  // retrieve e_client_label
1101  //--
1102 
1103  if ( strlen(trim($e_client)) != 0)
1104  {
1105  $fClient=new Fiche($this->db);
1106  $fClient->get_by_qcode($e_client);
1107  $e_client_label=$fClient->strAttribut(ATTR_DEF_NAME).' '.
1108  ' Adresse : '.$fClient->strAttribut(ATTR_DEF_ADRESS).' '.
1109  $fClient->strAttribut(ATTR_DEF_CP).' '.
1110  $fClient->strAttribut(ATTR_DEF_CITY).' ';
1111 
1112 
1113  }
1114 
1115  $W1=new ICard();
1116  $W1->label=_("Fournisseur ").HtmlInput::infobulle(0) ;
1117  $W1->name="e_client";
1118  $W1->tabindex=3;
1119  $W1->value=$e_client;
1120  $W1->table=0;
1121  $W1->set_dblclick("fill_ipopcard(this);");
1122  $W1->set_attribute('ipopup','ipopcard');
1123 
1124  // name of the field to update with the name of the card
1125  $W1->set_attribute('label','e_client_label');
1126  // name of the field to update with the name of the card
1127  $W1->set_attribute('typecard','cred');
1128 
1129  // Add the callback function to filter the card on the jrn
1130  $W1->set_callback('filter_card');
1131  $W1->set_function('fill_data');
1132  $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
1133  $W1->name);
1134  $f_client_qcode=$W1->input();
1135  $client_label=new ISpan();
1136  $client_label->table=0;
1137  $f_client=$client_label->input("e_client_label",$e_client_label);
1138  $f_client_bt=$W1->search();
1139 
1140 
1141  // Record the current number of article
1142 
1143  $e_comment=(isset($e_comment))?$e_comment:"";
1144  $p_article= ( isset ($nb_item))?$nb_item:$this->get_min_row();
1145  $p_article=($p_article < $this->get_min_row())?$this->get_min_row():$p_article;
1146 
1147  $Hid=new IHidden();
1148  $r.=$Hid->input("nb_item",$p_article);
1149 
1150  // For each article
1151  //--
1152  for ($i=0;$i< $p_article ;$i++)
1153  {
1154  // Code id, price & vat code
1155  //--
1156  $march=(isset(${"e_march$i"}))?${"e_march$i"}:"" ;
1157  $march_price=(isset(${"e_march".$i."_price"}))?${"e_march".$i."_price"}:""
1158  ;
1159  /* use vat */
1160  if ( $g_parameter->MY_TVA_USE=='Y')
1161  {
1162  $march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:"";
1163  $march_tva_amount=(isset(${"e_march$i"."_tva_amount"}))?${"e_march$i"."_tva_amount"}:"";
1164  }
1165 
1166 
1167 
1168  $march_label=(isset(${"e_march".$i."_label"}))?${"e_march".$i."_label"}:"";
1169  // retrieve the tva label and name
1170  //--
1171  if ( strlen(trim($march))!=0 && strlen(trim($march_label))==0 )
1172  {
1173  $fMarch=new Fiche($this->db);
1174  $fMarch->get_by_qcode($march);
1175  $march_label=$fMarch->strAttribut(ATTR_DEF_NAME);
1176  /* vat use */
1177  if ( ! isset($march_tva_id) && $g_parameter->MY_TVA_USE=='Y' )
1178  $march_tva_id=$fMarch->strAttribut(ATTR_DEF_TVA);
1179  }
1180  // Show input
1181  //--
1182  $W1=new ICard();
1183  $W1->label="";
1184  $W1->name="e_march".$i;
1185  $W1->value=$march;
1186  $W1->table=1;
1187  $W1->set_dblclick("fill_ipopcard(this);");
1188  $W1->set_attribute('ipopup','ipopcard');
1189 
1190  $W1->set_attribute('typecard','deb');
1191 
1192  // name of the field to update with the name of the card
1193  $W1->set_attribute('label','e_march'.$i.'_label');
1194  // name of the field with the price
1195  $W1->set_attribute('purchase','e_march'.$i.'_price'); /* autocomplete */
1196  $W1->set_attribute('price','e_march'.$i.'_price'); /* via search */
1197 
1198  // name of the field with the TVA_ID
1199  $W1->set_attribute('tvaid','e_march'.$i.'_tva_id');
1200  // Add the callback function to filter the card on the jrn
1201  $W1->set_callback('filter_card');
1202  $W1->set_function('fill_data');
1203  $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
1204  $W1->name);
1205  $W1->readonly=false;
1206  $array[$i]['quick_code']=$W1->input();
1207  $array[$i]['bt']=$W1->search();
1208 
1209  $array[$i]['hidden']='';
1210  // For computing we need some hidden field for holding the value
1211  if ( $g_parameter->MY_TVA_USE=='Y')
1212  {
1213  $array[$i]['hidden'].=HtmlInput::hidden('tva_march'.$i,0);
1214  }
1215 
1216  if ( $g_parameter->MY_TVA_USE=='Y')
1217  $tvac=new INum('tvac_march'.$i);
1218  else
1219  $tvac=new IHidden('tvac_march'.$i);
1220 
1221  $tvac->readOnly=1;
1222  $tvac->value=0;
1223  $array[$i]['tvac']=$tvac->input();
1224 
1225  $htva=new INum('htva_march'.$i);
1226  $htva->readOnly=1;
1227 
1228  $htva->value=0;
1229  $array[$i]['htva']=$htva->input();
1230 
1231  if ( $g_parameter->MY_UPDLAB == 'Y')
1232  {
1233  $Span=new IText("e_march".$i."_label");
1234  $Span->css_size="100%";
1235  } else
1236  {
1237  $Span=new ISpan("e_march".$i."_label");
1238  }
1239  $Span->value=$march_label;
1240  $Span->setReadOnly(false);
1241  // card's name, price
1242  //--
1243  $array[$i]['denom']=$Span->input("e_march".$i."_label",$march_label);
1244  // price
1245  $Price=new INum();
1246  $Price->setReadOnly(false);
1247  $Price->size=9;
1248  $Price->javascript="onBlur='format_number(this,4);clean_tva($i);compute_ledger($i)'";
1249  $array[$i]['pu']=$Price->input("e_march".$i."_price",$march_price);
1250  if ( $g_parameter->MY_TVA_USE=='Y')
1251  {
1252 
1253  // vat label
1254  //--
1255  $Tva=new ITva_Popup($this->db);
1256  $Tva->js="onblur=\"format_number(this);onChange=clean_tva($i);compute_ledger($i)\"";
1257  $Tva->in_table=true;
1258  $Tva->set_attribute('compute',$i);
1259  $Tva->value=$march_tva_id;
1260  $array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
1261 
1262  // Tva_amount
1263 
1264  // price
1265  $Tva_amount=new INum();
1266  $Tva_amount->setReadOnly(false);
1267  $Tva_amount->size=9;
1268  $Tva_amount->javascript="onBlur='format_number(this);compute_ledger($i)'";
1269  $array[$i]['amount_tva']=$Tva_amount->input("e_march".$i."_tva_amount",$march_tva_amount);
1270  }
1271  // quantity
1272  //--
1273  $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"1"
1274  ;
1275  $Quantity=new INum();
1276  $Quantity->setReadOnly(false);
1277  $Quantity->size=9;
1278  $Quantity->javascript="onChange=format_number(this);clean_tva($i);compute_ledger($i)";
1279  $array[$i]['quantity']=$Quantity->input("e_quant".$i,$quant);
1280 
1281  }
1282  $f_type=_('Fournisseur');
1283 
1284  ob_start();
1285  require_once NOALYSS_TEMPLATE.'/form_ledger_detail.php';
1286  $r.=ob_get_contents();
1287  ob_end_clean();
1288 
1289  // Set correctly the REQUEST param for jrn_type
1290  $r.= HtmlInput::hidden('jrn_type','ACH');
1291  $r.= HtmlInput::button('add_item',_('Ajout article'), ' onClick="ledger_add_row()"');
1292 
1293 
1294 
1295  /* if we suggest the pj n# the run the script */
1296  if ( $g_parameter->MY_PJ_SUGGEST=='Y')
1297  {
1298  $r.='<script> update_pj();</script>';
1299  }
1300  // set focus on date
1301  $r.= create_script("$('".$Date->id."').focus()");
1302  return $r;
1303  }
1304 
1305  /*!@brief show the summary of the operation and propose to save it
1306  *@param array contains normally $_POST. It proposes also to save
1307  * the Analytic accountancy
1308  * @param $p_summary true to confirm false, show only the result in RO
1309  *@return string
1310  */
1311  function confirm($p_array,$p_summary=false)
1312  {
1313  global $g_parameter;
1314  extract ($p_array);
1315 
1316  // we don't need to verify if we need only a feedback
1317  if ( ! $p_summary )
1318  $this->verify($p_array) ;
1319 
1320  $anc=null;
1321  // to show a select list for the analytic
1322  // if analytic is op (optionnel) there is a blank line
1323 
1324  bcscale(4);
1325  $client=new Fiche($this->db);
1326  $client->get_by_qcode($e_client,true);
1327 
1328  $client_name=h($client->getName().
1329  ' '.$client->strAttribut(ATTR_DEF_ADRESS).' '.
1330  $client->strAttribut(ATTR_DEF_CP).' '.
1331  $client->strAttribut(ATTR_DEF_CITY));
1332  $lPeriode=new Periode($this->db);
1333  if ($this->check_periode() == true)
1334  {
1335  $lPeriode->p_id=$period;
1336  }
1337  else
1338  {
1339  $lPeriode->find_periode($e_date);
1340  }
1341  $date_limit=$lPeriode->get_date_limit();
1342  $r="";
1343  $r .= '<div id="summary_op1">';
1344  $r.='<TABLE>';
1345  if ( $p_summary ) {
1346  $jr_id=$this->db->get_value('select jr_id from jrn where jr_internal=$1',array($this->internal));
1347  $r.="<tr>";
1348  $r.='<td>';
1349  $r.=_('Détail opération ');
1350  $r.='</td>';
1351  $r.='<td>';
1352  $r.=sprintf ('<a class="line" style="display:inline" href="javascript:modifyOperation(%d,%d)">%s</a>',
1353  $jr_id,dossier::id(),$this->internal);
1354  $r.='</td>';
1355  $r.="</tr>";
1356  }
1357  $r.='<tr>';
1358  if ( ! $p_summary) {
1359  $r.='<td>' . _('Numéro Pièce') .'</td><td>'. hb($e_pj) . '</td>';
1360  } else {
1361 
1362  if ( strcmp($this->pj,$e_pj) != 0 )
1363  {
1364  $r.='<td>' . _('Numéro Pièce') .'</td><td>'. hb($this->pj) .
1365  '<span class="notice"> '._('Attention numéro pièce existante, elle a du être adaptée').'</span></td>';
1366  } else {
1367  $r.='<td>' . _('Numéro Pièce') .'</td><td>'. hb($this->pj) . '</td>';
1368  }
1369  }
1370  $r.='</tr>';
1371  $r.='<td> ' . _('Date') . '</td><td> ' . hb($e_date) . '</td>';
1372  $r.='</tr>';
1373  $r.='<tr>';
1374  $r.='<td>' . _('Echeance') . '</td><td> ' . hb($e_ech) . '</td>';
1375  $r.='</tr>';
1376 
1377 
1378  $r.='<tr>';
1379  $r.='<td> ' . _('Période Comptable') . '</td><td> ' .hb( $date_limit['p_start'] . '-' . $date_limit['p_end']) . '</td>';
1380  $r.='</tr>';
1381  $r.='</table>';
1382  $r.='</div>';
1383  $r .= '<div id="summary_op2">';
1384  $r.='<table>';
1385  $r.='<tr>';
1386  $r.='<td> ' . _('Journal') . '</td><td> ' . hb($this->get_name()) . '</td>';
1387  $r.='</tr>';
1388  $r.='<tr>';
1389  $r.='<td> ' . _('Libellé') . '</td><td> ' . hb($e_comm) . '</td>';
1390  $r.='</tr>';
1391  $r.='<tr>';
1392 
1393  $r.='<tr>';
1394  $r.='<td> ' . _('Fournisseur') . '</td><td> ' . hb($e_client . ':' . $client_name) . '</td>';
1395  $r.='</tr>';
1396  $r.='</table>';
1397  $r.='</div>';
1398  $r.='<div style="position:float;clear:both">';
1399  $r.='</div>';
1400  $r.='<h2>' . _('Détail articles achetés') . '</h2>';
1401  $r.='<p class="decale">';
1402  $r.='<table class="result" >';
1403  $r.='<TR>';
1404  $r.="<th>" . _('Code') . "</th>";
1405  $r.="<th>" . _('Dénomination') . "</th>";
1406  $r.="<th style=\"text-align:right\">" . _('prix') . "</th>";
1407  $r.="<th style=\"text-align:right\">" . _('quantité') . "</th>";
1408 
1409 
1410  if ($g_parameter->MY_TVA_USE == 'Y') {
1411  $r.="<th style=\"text-align:right\">" . _('tva') . "</th>";
1412  $r.='<th style="text-align:right"> ' . _('Montant TVA') . '</th>';
1413  $r.='<th style="text-align:right">' . _('Montant HTVA') . '</th>';
1414  $r.='<th style="text-align:right">' . _('Montant TVAC') . '</th>';
1415  } else {
1416  $r.='<th style="text-align:right">' . _('Montant') . '</th>';
1417  }
1418 
1419  /* if we use the AC */
1420  if ($g_parameter->MY_ANALYTIC!='nu')
1421  {
1422  $anc=new Anc_Plan($this->db);
1423  $a_anc=$anc->get_list();
1424  $x=count($a_anc);
1425  /* set the width of the col */
1426  $r.='<th colspan="'.$x.'">'._('Compt. Analytique').'</th>';
1427 
1428  /* add hidden variables pa[] to hold the value of pa_id */
1429  $r.=Anc_Plan::hidden($a_anc);
1430  }
1431 
1432  $r.='</tr>';
1433  $tot_amount=0.0;
1434  $tot_tva=0.0;
1435  //--
1436  // For each item
1437  //--
1438  for ($i = 0; $i < $nb_item;$i++)
1439  {
1440  $tot_row=0;
1441  if ( strlen(trim(${"e_march".$i})) == 0 ) continue;
1442 
1443  /* retrieve information for card */
1444  $fiche=new Fiche($this->db);
1445  $fiche->get_by_qcode(${"e_march".$i});
1446  if ( $g_parameter->MY_UPDLAB=='Y')
1447  $fiche_name=h(${"e_march".$i."_label"});
1448  else
1449  $fiche_name=$fiche->strAttribut (ATTR_DEF_NAME);
1450  $amount=bcmul(${"e_march".$i."_price"},${'e_quant'.$i});
1451  if ( $g_parameter->MY_TVA_USE=='Y')
1452  {
1453  $idx_tva=${"e_march".$i."_tva_id"};
1454  $oTva=new Acc_Tva($this->db);
1455  $oTva->set_parameter('id',$idx_tva);
1456  $oTva->load();
1457  $op=new Acc_Compute();
1458 
1459  $op->set_parameter("amount",$amount);
1460  $op->set_parameter('amount_vat_rate',$oTva->get_parameter('rate'));
1461  $op->compute_vat();
1462  $tva_computed=$op->get_parameter('amount_vat');
1463  //----- if tva_amount is not given we compute the vat ----
1464  if ( strlen (trim (${'e_march'.$i.'_tva_amount'})) == 0)
1465  {
1466  $tva_item=$op->get_parameter('amount_vat');
1467  }
1468  else
1469  $tva_item=round(${'e_march'.$i.'_tva_amount'},2);
1470 
1471  if (isset($tva[$idx_tva] ) )
1472  $tva[$idx_tva]=bcadd($tva_item,$tva[$idx_tva]);
1473  else
1474  $tva[$idx_tva]=$tva_item;
1475 
1476 
1477 
1478  }
1479  $tot_amount=round(bcadd($tot_amount,$amount),2);
1480  $tot_row=round(bcadd($tot_row,$amount),2);
1481  $r.='<tr>';
1482  $r.='<td>';
1483  $r.=${"e_march".$i};
1484  $r.='</td>';
1485  $r.='<TD style="border-bottom:1px dotted grey;">';
1486  $r.=$fiche_name;
1487  $r.='</td>';
1488  $r.='<td class="num">';
1489  $r.=nbm(${"e_march".$i."_price"},4);
1490  $r.='</td>';
1491  $r.='<td class="num">';
1492  $r.=nbm(${"e_quant".$i});
1493  $r.='</td>';
1494  $both_side=0;
1495  if ($g_parameter->MY_TVA_USE == 'Y')
1496  {
1497  $r.='<td class="num">';
1498  $r.=$oTva->get_parameter('label');
1499  $both_side=$oTva->get_parameter("both_side");
1500  if ( $both_side == 0) {
1501  $tot_row=bcadd($tot_row,$tva_item);
1502  $tot_tva=round(bcadd($tva_item,$tot_tva),2);
1503  }
1504  $r.='</td>';
1505  /* warning if tva_computed and given are not the
1506  same */
1507  $css_void_tva=($both_side == 1)?'style="text-decoration:line-through"':'';
1508  if ( bcsub($tva_item,$tva_computed) != 0 && ! ($tva_item == 0 && $both_side == 1))
1509  {
1510 
1511  $r.='<td style="background-color:red" class="num" '.$css_void_tva.'>';
1512  $r.=HtmlInput::infobulle(28);
1513  $r.='<a href="#" class="error" style="display:inline" title="'. _("Attention Différence entre TVA calculée et donnée").'">'
1514  .nbm($tva_item).'<a>';
1515  }
1516  else{
1517  $r.='<td class="num" '.$css_void_tva.'>';
1518  $r.=nbm($tva_item);
1519  }
1520  $r.='</td>';
1521  $r.='<td class="num"> ';
1522  $r.=nbm(round($amount,2));
1523  $r.='</td>';
1524  }
1525  $r.='<td class="num">';
1526  $r.=nbm(round($tot_row,2));
1527  $r.='</td>';
1528  // encode the pa
1529  if ( $g_parameter->MY_ANALYTIC!='nu') // use of AA
1530  {
1531  // show form
1532  $anc_op=new Anc_Operation($this->db);
1533  $null=($g_parameter->MY_ANALYTIC=='op')?1:0;
1534  $r.='<td>';
1535  $p_mode=($p_summary==false)?1:0;
1536  $p_array['pa_id']=$a_anc;
1537  /* op is the operation it contains either a sequence or a jrnx.j_id */
1538  $r.=HtmlInput::hidden('op[]=',$i);
1539  $r.=$anc_op->display_form_plan($p_array,$null,$p_mode,$i,round($amount,2));
1540  $r.='</td>';
1541  }
1542 
1543 
1544  $r.='</tr>';
1545 
1546  }
1547  // Add the sum
1548  $decalage=($g_parameter->MY_TVA_USE == 'Y')?'<td></td><td></td><td></td><td></td>':'<td></td>';
1549  $tot = round(bcadd($tot_amount, $tot_tva), 2);
1550  $tot_tva=nbm($tot_tva);
1551  $tot=nbm($tot);
1552  $str_tot=_('Totaux');
1553  $tot_amount=nbm($tot_amount);
1554  $r.=<<<EOF
1555 <tr class="highlight">
1556  {$decalage}
1557  <td>
1558  {$str_tot}
1559  </td>
1560  <td class="num">
1561  {$tot_tva}
1562  </td>
1563  <td class="num">
1564  {$tot_amount}
1565  </td>
1566  <td class="num">
1567  {$tot}
1568  </td>
1569 EOF;
1570 
1571  $r.='</table>';
1572  $r.='</p>';
1573  if ( $g_parameter->MY_ANALYTIC!='nu' && !$p_summary) // use of AA
1574  $r.='<input type="button" class="button" value="'._('Vérifiez imputation analytique').'" onClick="verify_ca(\'\');">';
1575 
1576  $r.=(! $p_summary )?'<div id="total_div_id" >':'<div>';
1577  $r.='<h2>Totaux</h2>';
1578  /* use VAT */
1579  if ($g_parameter->MY_TVA_USE == 'Y') {
1580  $r.='<table>';
1581  $r.='<tr><td>Total HTVA</td>';
1582  $r.=td(hb($tot_amount ),'class="num"');
1583  foreach ($tva as $i => $value) {
1584  $oTva->set_parameter('id', $i);
1585  $oTva->load();
1586 
1587  $r.='<tr><td> TVA ' . $oTva->get_parameter('label').'</td>';
1588  $r.=td(hb(nbm($tva[$i])),'class="num"');
1589  }
1590  $r.='<tr>'.td(_('Total TVA')).td(hb($tot_tva),'class="num"');
1591  $r.='<tr>'.td(_('Total TVAC')).td(hb($tot),'class="num"');
1592  $r.='</table>';
1593  } else {
1594  $r.='<br>Total '.hb($tot);
1595  }
1596  $r.='</div>';
1597  /* Add hidden */
1598  $r.=HtmlInput::hidden('e_client',$e_client);
1599  $r.=HtmlInput::hidden('nb_item',$nb_item);
1600  $r.=HtmlInput::hidden('p_jrn',$p_jrn);
1601  if ( isset($period))
1602  $r.=HtmlInput::hidden('period',$period);
1603  $r.=HtmlInput::hidden('e_comm',$e_comm);
1604  $r.=HtmlInput::hidden('e_date',$e_date);
1605  $r.=HtmlInput::hidden('e_ech',$e_ech);
1606  $r.=HtmlInput::hidden('jrn_type',$jrn_type);
1607  $r.=HtmlInput::hidden('e_pj',$e_pj);
1608  $r.=HtmlInput::hidden('e_pj_suggest',$e_pj_suggest);
1609  $mt=microtime(true);
1610  $r.=HtmlInput::hidden('mt',$mt);
1611 
1612  $e_mp=(isset($e_mp))?$e_mp:0;
1613  $r.=HtmlInput::hidden('e_mp',$e_mp);
1614  /* Paid by */
1615  /* if the paymethod is not 0 and if a quick code is given */
1616 
1617 
1618  for ($i=0;$i < $nb_item;$i++)
1619  {
1620  $r.=HtmlInput::hidden("e_march".$i,${"e_march".$i});
1621  if (isset (${"e_march".$i."_label"})) $r.=HtmlInput::hidden("e_march".$i."_label",${"e_march".$i."_label"});
1622  $r.=HtmlInput::hidden("e_march".$i."_price",${"e_march".$i."_price"});
1623  if ( $g_parameter->MY_TVA_USE=='Y' )
1624  {
1625  $r.=HtmlInput::hidden("e_march".$i."_tva_id",${"e_march".$i."_tva_id"});
1626  $r.=HtmlInput::hidden('e_march'.$i.'_tva_amount', ${'e_march'.$i.'_tva_amount'});
1627  }
1628  $r.=HtmlInput::hidden("e_quant".$i,${"e_quant".$i});
1629 
1630  }
1631 
1632  /**
1633  *
1634  */
1635  if ( $e_mp!=0 && strlen (trim (${'e_mp_qcode_'.$e_mp})) != 0 )
1636  {
1637  $r.=HtmlInput::hidden('e_mp_qcode_'.$e_mp,${'e_mp_qcode_'.$e_mp});
1638  $r.=HtmlInput::hidden('acompte',$acompte);
1639  $r.=HtmlInput::hidden('e_comm_paiement',$e_comm_paiement);
1640  /* needed for generating a invoice */
1641  $r.=HtmlInput::hidden('qcode_benef', ${'e_mp_qcode_' . $e_mp});
1642  $fname = new Fiche($this->db);
1643  $fname->get_by_qcode(${'e_mp_qcode_' . $e_mp});
1644  $r.='<h2>' . _("Payé par")." " . ${'e_mp_qcode_' . $e_mp} .
1645  " " . $fname->getName() . '</h2> ' . '<p class="decale">' . _('Déduction acompte ') . h($acompte) . '</p>' .
1646  _('Libellé :') . h($e_comm_paiement) ;
1647  $r.='<br>';
1648  $r.='<br>';
1649  }
1650  // check for upload piece
1651 
1652  return $r;
1653  }
1654 
1655  /*!\brief the function extra info allows to
1656  * - add a attachment
1657  * - generate an invoice
1658  * - insert extra info
1659  *\return html string
1660  */
1661  public function extra_info()
1662  {
1663  $r="";
1664  $r = '<div id="facturation_div_id" style="height:185px;height:10rem">';
1665  $r.='<p class="decale">';
1666  // check for upload piece
1667  $file=new IFile();
1668  $file->table=0;
1669  $r.=_("Ajoutez une pièce justificative ");
1670  $r.=$file->input("pj","");
1671 
1672  if ( $this->db->count_sql("select md_id,md_name from document_modele where md_affect='ACH'") > 0 )
1673  {
1674 
1675  $r.=_('ou générer un document').' <input type="checkbox" name="gen_invoice" >';
1676  // We propose to generate the fee note
1677  $doc_gen=new ISelect();
1678  $doc_gen->name="gen_doc";
1679  $doc_gen->value=$this->db->make_array(
1680  "select md_id,md_name ".
1681  " from document_modele where md_affect='ACH'");
1682  $r.=$doc_gen->input().'<br>';
1683  }
1684  $r.='<br>';
1685  $obj=new IText();
1686  $r.=_('Numero de bon de commande : ').$obj->input('bon_comm').'<br>';
1687  $r.=_('Autre information : ').$obj->input('other_info').'<br>';
1688  $r.='</p>';
1689  $r.='</div>';
1690  return $r;
1691  }
1692 
1693 
1694  /**
1695  * @brief update the payment
1696  * @todo to remove, obsolete
1697  * @deprecated
1698  */
1700  {
1701  // Show list of unpaid sell
1702  // Date - date of payment - Customer - amount
1703  // Nav. bar
1704  $step=$_SESSION['g_pagesize'];
1705  $page=(isset($_GET['offset']))?$_GET['page']:1;
1706  $offset=(isset($_GET['offset']))?$_GET['offset']:0;
1707 
1708 
1710  list($max_line,$list)=$this->list_operation($sql,null,$offset,1);
1711  $sql=SQL_LIST_UNPAID_INVOICE." and jr_def_id=".$this->id ;
1712  list($max_line2,$list2)=$this->list_operation($sql,null,$offset,1);
1713 
1714  // Get the max line
1715  $m=($max_line2>$max_line)?$max_line2:$max_line;
1717 
1718  echo $bar2;
1719  echo '<h2 class="info"> '._('Echeance dépassée').' </h2>';
1720  echo $list;
1721  echo '<h2 class="info"> '._('Non Payée').' </h2>';
1722  echo $list2;
1723  echo $bar2;
1724  // Add hidden parameter
1725  $hid=new IHidden();
1726 
1727  echo '<hr>';
1728 
1729  if ( $m != 0 )
1730  echo HtmlInput::submit('paid',_('Mise à jour paiement'));
1731 
1732 
1733  }
1734  /**
1735  * Retrieve data from the view v_detail_purchase
1736  * @note $g_user connected user
1737  * @param $p_from jrn.jr_tech_per from
1738  * @param $p_end jrn.jr_tech_per to
1739  * @return handle to database result
1740  */
1741  function get_detail_purchase($p_from,$p_end)
1742  {
1743  global $g_user;
1744  // Journal valide
1745  if ( $this->id == 0 ) die (__FILE__.":".__LINE__." Journal invalide");
1746 
1747  // Securite
1748  if ( $g_user->get_ledger_access($this->id) == 'X' ) return null;
1749 
1750  // get the data from the view
1751  $sql = "select *
1752  from v_detail_purchase
1753  where
1754  jr_def_id = $1
1755  and jr_date >= (select p_start from parm_periode where p_id = $2)
1756  and jr_date <= (select p_end from parm_periode where p_id = $3) "
1757  .' order by jr_date,substring(jr_pj_number,\'[0-9]+$\')::numeric asc ';
1758  $ret = $this->db->exec_sql($sql, array($this->id,$p_from, $p_end));
1759  return $ret;
1760  }
1761  /**
1762  * @brief compute an array with the heading cells for the
1763  * details, used for the export in CSV
1764  * @return array
1765  */
1766  static function heading_detail_purchase()
1767  {
1768  $array['jr_id'] = _('Numéro opération');
1769  $array['jr_date'] = _('Date');
1770  $array['jr_date_paid'] = _('Date paiement');
1771  $array['jr_ech'] = _('Date échéance');
1772  $array['jr_tech_per'] = _('Période');
1773  $array['jr_comment'] = _('Libellé');
1774  $array['jr_pj_number'] = _('Pièce');
1775  $array['jr_internal'] = _('Interne');
1776  $array['jr_def_id'] = _('Code journal');
1777  $array['j_poste'] = _('Poste');
1778  $array['j_text'] = _('Commentaire');
1779  $array['j_qcode'] = _('Code Item');
1780  $array['item_card'] = _('N° fiche');
1781  $array['item_name'] = _('Nom fiche');
1782  $array['qp_supplier'] = _('N° fiche fournisseur');
1783  $array['tiers_name'] = _('Nom fournisseur');
1784  $array['quick_code'] = _('Code fournisseur');
1785  $array['tva_label'] = _('Nom TVA');
1786  $array['tva_comment'] = _('Commentaire TVA');
1787  $array['tva_both_side'] = _('TVA annulée');
1788  $array['vat_sided'] = _('TVA Non Payé');
1789  $array['vat_code'] = _('Code TVA');
1790  $array['vat'] = _('Montant TVA');
1791  $array['price'] = _('Total HTVA');
1792  $array['quantity'] = _('quantité');
1793  $array['price_per_unit'] = _('PU');
1794  $array['non_ded_amount'] = _('Montant ND');
1795  $array['non_ded_tva'] = _('Montant TVA ND');
1796  $array['non_ded_tva_recup'] = _('TVA récup.');
1797  $array['htva'] = _('HTVA Opération');
1798  $array['tot_vat'] = _('TVA Opération');
1799  $array['tot_tva_np'] = _('TVA NP opération');
1800  return $array;
1801  }
1802 
1803 }
1804 
1805 
1806 
1807 
1808 
const ATTR_DEF_ACCOUNT_ND_TVA
Definition: constant.php:209
hb($p_string)
Definition: ac_common.php:53
get_name()
Return the name of a ledger.
$_GET['qcode']
$_POST['ac']
Definition: do.php:279
get_last_date()
get the date of the last operation
Generate the form for the periode Data Members.
if($g_user->check_dossier(dossier::id(), true)=='X') $op
Definition: ajax_ledger.php:89
this class is used to show the form for entering an operation only FOR analytic operation to save it...
mother class for the lettering by account and by card use the tables jnt_letter, letter_deb and lette...
check_payment($e_mp, $e_mp_qcode)
check if the payment method is valid
const ATTR_DEF_ACCOUNT_ND_TVA_ND
Definition: constant.php:210
const ATTR_DEF_TVA
Definition: constant.php:190
Manage the table parm_code which contains the custom parameter for the module accountancy.
const ATTR_DEF_ADRESS
Definition: constant.php:192
sql_string($p_string)
Fix the problem with the quote char for the database.
Definition: ac_common.php:457
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
const ATTR_DEF_ACCOUNT_ND
Definition: constant.php:212
static infobulle($p_comment)
const FICADD
show_unpaid_deprecated()
update the payment
const SQL_LIST_UNPAID_INVOICE_DATE_LIMIT
Definition: constant.php:299
verify($p_array)
verify that the data are correct before inserting or confirming
compute_no_deductible(Acc_Compute $p_nd_amount, Fiche $p_fiche)
Compute the ND amount thanks the attribute of the concerned card.
nbm($p_number, $p_dec=2)
format the number with a sep.
Definition: ac_common.php:121
Handle the ledger of purchase,.
create_document($internal, $p_array)
create the invoice and saved it as attachment to the operation,
static hidden($p_array)
return an HTML string containing hidden input type to hold the differant PA_ID
Concerns the Analytic plan (table plan_analytique)
Manage the account from the table jrn, jrnx or tmp_pcmn.
const ATTR_DEF_CP
Definition: constant.php:193
let you choose a TVA in a popup
isNumber(&$p_int)
Definition: ac_common.php:202
input($p_array=null, $p_readonly=0)
display the form for entering data for invoice
$value
static button($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
$a_poste
$idx
update_internal_code($p_internal)
$def
show a form for quick_writing
Acc_Tva is used for to map the table tva_rate parameter are.
compute_internal_code($p_grpt)
compute the internal code of the saved operation and set the $this->jr_internal to the computed value...
guess_pj()
guess what the next pj should be
const ATTR_DEF_DEPENSE_NON_DEDUCTIBLE
Definition: constant.php:203
select_ledger($p_type="ALL", $p_access=3)
Show a select list of the ledgers you can access in writing, reading or simply accessing.
if(!isset($_REQUEST['act'])||!isset($_REQUEST['jr_id'])||!isset($_REQUEST['div'])) global $g_parameter
Definition: ajax_ledger.php:46
const OPEN
Definition: constant.php:170
navigation_bar($p_offset, $p_line, $p_size=0, $p_page=1, $p_javascript="")
Create a navigation_bar (pagesize)
Definition: user_common.php:81
check_strict()
Check if a Dossier is using the strict mode or not.
insert($p_array=null)
insert into the database, it calls first the verify function change the value of this->jr_id and this-...
confirm($p_array, $p_summary=false)
show the summary of the operation and propose to save it
For the periode tables parm_periode and jrn_periode.
if(isset($_POST['confirm_rm'])) $both_side
Definition: tva.inc.php:38
is_closed($p_periode)
check if the current ledger is closed
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: class_fiche.php:44
const SQL_LIST_UNPAID_INVOICE
Definition: constant.php:295
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
insert_no_deductible(Acc_Compute $p_nd_amount, Fiche $p_fiche, $p_tva_both, &$p_tot_debit, Acc_Operation $p_acc_operation, $p_group, $idx)
Insert into JRNX the No Deductible amount and into Analytic Accountancy for the ND VAT...
static heading_detail_purchase()
compute an array with the heading cells for the details, used for the export in CSV ...
get_id($p_internal)
retrieve the jr_id thanks the internal code, do not change anything to the current object ...
global $g_user
Find the default module or the first one.
Definition: action.inc.php:24
$date_limit
Class for jrn, class acc_ledger for manipulating the ledger.
if($ck==0) $anc
empty_attribute($p_attr)
check if an attribute is empty
function trim(s)
remove trailing and heading space
Definition: scripts.js:95
new class for managing the reconciliation it must be used instead of the function InsertRapt...
strAttribut($p_ad_id, $p_return=1)
cmpDate($p_date, $p_date_oth)
Compare 2 dates.
Definition: ac_common.php:175
if(!isset($_REQUEST['p_jrn'])) else $Ledger id
h($p_string)
to protect again bad characters which can lead to a cross scripting attack the string to be diplayed ...
Definition: ac_common.php:38
this file match the tables jrn & jrnx the purpose is to remove or save accountant writing to these ta...
isDate($p_date)
Definition: ac_common.php:223
$input_from type
Definition: balance.inc.php:70
const ATTR_DEF_ACCOUNT_ND_PERSO
Definition: constant.php:211
const ATTR_DEF_QUICKCODE
Definition: constant.php:206
const ATTR_DEF_CITY
Definition: constant.php:198
const ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP
Definition: constant.php:205
static show_receipt_document($p_jr_id, $p_name="")
Returns HTML code for displaying a icon with a link to a receipt document from the ledger...
Input HTML for the card show buttons, in the file, you have to add card.js How to use : ...
const ATTR_DEF_DEP_PRIV
Definition: constant.php:202
$check_periode
Definition: company.inc.php:93
this class aims to compute different amount
$dir
Definition: file-dir.php:3
static insert_goods(&$p_cn, $p_array)
Insert into stock_goods from ACH and VEN.
$jr_id
Definition: ajax_ledger.php:56
const ATTR_DEF_TVA_NON_DEDUCTIBLE
Definition: constant.php:204
$db
database connextion
$nb
default number of rows by default 10
extra_info()
the function extra info allows to
tr($p_string, $p_extra='')
Definition: ac_common.php:88
return false
$SecUser db
Handle the table mod_payment.
check_periode()
Check if a Dossier is using the check on the periode, if true than the user has to enter the date and...
get_detail_purchase($p_from, $p_end)
Retrieve data from the view v_detail_purchase.
const ATTR_DEF_NAME
Definition: constant.php:185
inc_seq_pj()
increment the sequence for the pj
insert_jrnx()
Insert into the table Jrn The needed data are :
compute_nd()
Compute the no deductible part of the amount, it reduce also the vat.
if(isset($_REQUEST['gDossier'])&&$_REQUEST['gDossier']<>0) $repo
const ATTR_DEF_ACCOUNT
Definition: constant.php:184
static hidden($p_name, $p_value, $p_id="")
$oPeriode
Definition: do.php:177
$op jr_id
Definition: ajax_ledger.php:90
create_script($p_string)
create the HTML for adding the script tags around of the script
check_parameter($p_array, $p_needed)
Check that all the index are in the array, used by function to check if the array contains the needed...
Html Input : Input a date format dd.mm.yyyy The property title should be set to indicate what it is e...
Definition: class_idate.php:31
This class handles only the numeric input, the input will call a javascript to change comma to period...
Definition: class_inum.php:40
$obj