noalyss  Version-9
acc_ledger_sold.class.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of NOALYSS.
5  *
6  * NOALYSS is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * NOALYSS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with NOALYSS; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 // Copyright Author Dany De Bontridder danydb@aevalys.eu
22 
23 /*!
24  * \file
25  * \brief class for the sold, herits from acc_ledger
26  */
27 require_once NOALYSS_INCLUDE.'/lib/user_common.php';
28 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
29 
30 /*!
31  * \brief Handle the ledger of sold,
32  *
33  * @exception throw an exception is something is wrong
34  */
35 
36 class Acc_Ledger_Sold extends Acc_Ledger {
37 
38  function __construct($p_cn, $p_init) {
39  parent::__construct($p_cn, $p_init);
40  $this->ledger_type = 'VEN';
41  }
42 
43  /*!\brief verify that the data are correct before inserting or confirming
44  * \param an array (usually $_POST)
45  * \return String
46  * \throw Exception if an error occurs
47  */
48 
49  public function verify_operation($p_array) {
50  global $g_parameter, $g_user;
51 
52  if (is_array($p_array ) == false || empty($p_array))
53  throw new Exception ("Array empty");
54 
55  extract($p_array, EXTR_SKIP);
56 
57  /*
58  * Check needed value
59  */
60  check_parameter($p_array,'p_jrn,e_date,e_client');
61 
62  /* check for a double reload */
63  if (isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1', array($mt)) != 0)
64  throw new Exception(_('Double Encodage'), 5);
65 
66  /* check if we can write into this ledger */
67  if ($g_user->check_jrn($p_jrn) != 'W')
68  throw new Exception(_('Accès interdit'), 20);
69 
70  /* check if there is a customer */
71  if (strlen(trim($e_client)) == 0)
72  throw new Exception(_('Vous n\'avez pas donné de client'), 11);
73 
74  /* check if the date is valid */
75  if (isDate($e_date) == null) {
76  throw new Exception(_('Date invalide'), 2);
77  }
78 
79  $oPeriode = new Periode($this->db);
80  if ($this->check_periode() == true && isset($p_array['period'])) {
81  $tperiode = $period;
82  /* check that the datum is in the choosen periode */
83  $oPeriode->p_id = $period;
84  list ($min, $max) = $oPeriode->get_date_limit();
85 
86  if (cmpDate($e_date, $min) < 0 ||
87  cmpDate($e_date, $max) > 0)
88  throw new Exception(_('Date et periode ne correspondent pas'), 6);
89  }
90  else {
91  $per = new Periode($this->db);
92  $tperiode = $per->find_periode($e_date);
93  }
94 
95  /* check if the periode is closed */
96  if ($this->is_closed($tperiode) == 1) {
97  throw new Exception(_('Periode fermee'), 6);
98  }
99  /* check if we are using the strict mode */
100  if ($this->check_strict() == true) {
101  /* if we use the strict mode, we get the date of the last
102  operation */
103  $last_date = $this->get_last_date();
104  if ($last_date != null && cmpDate($e_date, $last_date) < 0)
105  throw new Exception(_('Vous utilisez le mode strict la dernière operation est date du ')
106  . $last_date . _(' vous ne pouvez pas encoder à une date antérieure'), 13);
107  }
108 
109 
110  $fiche = new Fiche($this->db);
111  $fiche->get_by_qcode($e_client);
112  if ($fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
113  throw new Exception(_('La fiche ') . $e_client . _('n\'a pas de poste comptable'), 8);
114 
115  /* get the account and explode if necessary */
116  $sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
117  // if 2 accounts, take only the debit one for customer
118  if (strpos($sposte, ',') != 0) {
119  $array = explode(',', $sposte);
120  $poste_val = $array[0];
121  } else {
122  $poste_val = $sposte;
123  }
124  /* The account exists */
125 
126  $poste = new Acc_Account_Ledger($this->db, $poste_val);
127 
128  if ($poste->load() == false) {
129  throw new Exception(_('Pour la fiche ') . $e_client . _(' le poste comptable [') . $poste->id . _('] n\'existe pas'), 9);
130  }
131 
132  /* Check if the card belong to the ledger */
133  $fiche = new Fiche($this->db);
134  $fiche->get_by_qcode($e_client, 'deb');
135  if ($fiche->belong_ledger($p_jrn) != 1)
136  throw new Exception(_('La fiche ') . $e_client . _('n\'est pas accessible à ce journal'), 10);
137 
138  $nb = 0;
139 
140  //----------------------------------------
141  // foreach item
142  //----------------------------------------
143  for ($i = 0; $i < $nb_item; $i++) {
144  if (! isset (${'e_march' . $i}) || strlen(trim(${'e_march' . $i})) == 0)
145  continue;
146  /* check if amount are numeric and */
147  if (isNumber(${'e_march' . $i . '_price'}) == 0)
148  throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a un montant invalide [') . ${'e_march' . $i} . ']', 6);
149  if (isNumber(${'e_quant' . $i}) == 0)
150  throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a une quantité invalide [') . ${'e_quant' . $i} . ']', 7);
151  /* check if all card has a ATTR_DEF_ACCOUNT */
152  $fiche = new Fiche($this->db);
153  $fiche->get_by_qcode(${'e_march' . $i});
154  if ($fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
155  throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('n\'a pas de poste comptable'), 8);
156 
157  // Check if the given tva id is valid
158  if ($g_parameter->MY_TVA_USE == 'Y') {
159  if (isNumber(${'e_march' . $i . '_tva_id'}) == 0)
160  throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a un code tva invalide') . ' [' . ${'e_march' . $i . '_tva_id'} . ']', 13);
161  $tva_rate = new Acc_Tva($this->db);
162  $tva_rate->set_parameter('id', ${'e_march' . $i . '_tva_id'});
163  if ($tva_rate->load() != 0)
164  throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a un code tva invalide') . ' [' . ${'e_march' . $i . '_tva_id'} . ']', 13);
165 
166  /*
167  * check if the accounting for VAT are valid
168  */
169  $a_poste = explode(',', $tva_rate->tva_poste);
170 
171  if (
172 
173  $this->db->get_value('select count(*) from tmp_pcmn where pcm_val=$1', array($a_poste[1])) == 0)
174  throw new Exception(_(" La TVA " . $tva_rate->tva_label . " utilise des postes comptables inexistants"));
175  }
176  // if 2 accounts, take only the credit one
177  /* The account exists */
178  $sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
179 
180  if (strpos($sposte, ',') != 0) {
181  $array = explode(',', $sposte);
182  $poste_val = $array[1];
183  } else {
184  $poste_val = $sposte;
185  }
186  $poste = new Acc_Account_Ledger($this->db, $poste_val);
187  if ($poste->load() == false) {
188  throw new Exception(_('Pour la fiche ') . ${'e_march' . $i} . _(' le poste comptable [') . $poste->id . _('n\'existe pas'), 9);
189  }
190  /* Check if the card belong to the ledger */
191  $fiche = new Fiche($this->db);
192  $fiche->get_by_qcode(${'e_march' . $i});
193  if ($fiche->belong_ledger($p_jrn, 'cred') != 1)
194  throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('n\'est pas accessible à ce journal'), 10);
195 
196  if ( ${"e_quant".$i} != 0 && trim(${"e_quant".$i}) !="" ) {$nb++;}
197 
198  }
199  if ($nb == 0)
200  throw new Exception(_('Il n\'y a aucune marchandise'), 12);
201  //------------------------------------------------------
202  // The "Paid By" check
203  //------------------------------------------------------
204 
205  if ($e_mp != 0) {
206  $this->check_payment($e_mp, ${"e_mp_qcode_" . $e_mp});
207  // check for the currency , if we use a financial ledger and a card which is a bank account (with his own
208  // ledger , then the currency of the operation must be the same
209  $this->check_currency(${"e_mp_qcode_" . $e_mp},$p_currency_code);
210  }
211 
212 
213 
214 
215  //
216  // Check payment date
217  if ( isset ($mp_date) && trim ($mp_date) != "" && isDate($mp_date) == null) {
218  throw new Exception(_('Date de paiement invalide'),13);
219 
220  }
221 
222  // check limit date
223  if ( isset ($e_ech) && trim ($e_ech)!="" && isDate($e_ech) == null )
224  {
225  throw new Exception(_('Date échéance invalide'),14);
226 
227  }
228  // Check currency_rate if valid
229  if ( isNumber($p_currency_rate) == 0 || $p_currency_rate <=0 ) {
230  throw new Exception(_('Taux devise invalide'),15);
231  }
232  $this->check_currency_setting($p_currency_code);
233  }
234 
235  /*!\brief insert into the database, it calls first the verify function,
236  * change the value of this->jr_id and this->jr_internal
237  * * It generates the document if gen_invoice is set and save the middle of payment if any ($e_mp)
238  *
239  * \param $p_array is usually $_POST or a predefined operation
240  * \return string : internal number
241  * \note throw an Exception
242  */
243 
244  public function insert($p_array = null) {
245  global $g_parameter;
246  extract($p_array, EXTR_SKIP);
247  $this->verify($p_array);
248 
249  $group = $this->db->get_next_seq("s_oa_group"); /* for analytic */
250  $seq = $this->db->get_next_seq('s_grpt');
251  $this->id = $p_jrn;
252  $internal = $this->compute_internal_code($seq);
253  $this->internal = $internal;
254 
255  $oPeriode = new Periode($this->db);
256  $check_periode = $this->check_periode();
257 
258  if ($check_periode == true && isset($p_array['period']))
259  $tperiode = $period;
260  else
261  $tperiode = $oPeriode->find_periode($e_date);
262 
263  $cust = new Fiche($this->db);
264  $cust->get_by_qcode($e_client);
265  $sposte = $cust->strAttribut(ATTR_DEF_ACCOUNT);
266 
267  // if 2 accounts, take only the debit one for the customer
268  //
269  if (strpos($sposte, ',') != 0) {
270  $array = explode(',', $sposte);
271  $poste = $array[0];
272  } else {
273  $poste = $sposte;
274  }
275 
276  bcscale(4);
277  try {
278  $tot_amount = 0;
279  $tot_tva = 0;
280  $tot_debit = 0;
281  $tot_amount_cur=0;
282 
283  $this->db->start();
284  $tva = array();
285  // find the currency from v_currency_last_value
286  $currency_rate_ref=new Acc_Currency($this->db, $p_currency_code);
287  /* Save all the items without vat */
288  for ($i = 0; $i < $nb_item; $i++) {
289  $n_both = 0;
290  if ( empty(${'e_march'.$i}) || empty(${'e_quant'.$i}) ) continue;
291 
292  /* First we save all the items without vat */
293  $fiche = new Fiche($this->db);
294  $fiche->get_by_qcode(${"e_march" . $i});
295  $amount_currency = bcmul(${'e_march' . $i . '_price'}, ${'e_quant' . $i});
296 
297  // convert amount to currency
298  $amount=bcdiv($amount_currency,$p_currency_rate);
299 
300  $tot_amount = bcadd($tot_amount, $amount);
301  $tot_amount = round($tot_amount, 2);
302  if ( DEBUGNOALYSS > 1 ) { echo __LINE__." tot_amount $tot_amount<br>";}
303  $acc_operation = new Acc_Operation($this->db);
304  $acc_operation->date = $e_date;
305  $sposte = $fiche->strAttribut(ATTR_DEF_ACCOUNT);
306 
307  // if 2 accounts, take only the credit one
308  if (strpos($sposte, ',') != 0) {
309  $array = explode(',', $sposte);
310  $poste_val = $array[1];
311  } else {
312  $poste_val = $sposte;
313  }
314 
315  $acc_operation->poste = $poste_val;
316  $acc_operation->amount = $amount;
317  $acc_operation->grpt = $seq;
318  $acc_operation->jrn = $p_jrn;
319  $acc_operation->type = 'c';
320  $acc_operation->periode = $tperiode;
321  if ($g_parameter->MY_UPDLAB=='Y')
322  {
323  $acc_operation->desc=strip_tags(${"e_march".$i."_label"});
324  }
325  else
326  {
327  $acc_operation->desc=null;
328  }
329 
330  $acc_operation->qcode = ${"e_march" . $i};
331  if ($amount<0)
332  {
333  $tot_debit=round(bcadd($tot_debit, abs($amount)),2);
334  }
335 
336  $j_id = $acc_operation->insert_jrnx();
337 
338  if ($g_parameter->MY_TVA_USE == 'Y') {
339  /* Compute sum vat */
340  $oTva = new Acc_Tva($this->db);
341  $idx_tva = ${'e_march' . $i . '_tva_id'};
342  $tva_item_currency = ${'e_march' . $i . '_tva_amount'};
343  $oTva->set_parameter("id", $idx_tva);
344  $oTva->load();
345  /* if empty then we need to compute it */
346  if (trim($tva_item_currency) == '' || ${'e_march'.$i.'_tva_amount'} == 0) {
347  /* retrieve tva */
348  $l = new Acc_Tva($this->db, $idx_tva);
349  $l->load();
350  $tva_item_currency = bcmul($amount, $l->get_parameter('rate'));
351  $tva_item=round($tva_item_currency,2);
352  }
353  $tva_item=bcdiv($tva_item_currency,$p_currency_rate);
354  $tva_item=round($tva_item,2);
355  if (isset($tva[$idx_tva]))
356  {
357  $tva[$idx_tva]=bcadd($tva_item,$tva[$idx_tva]);
358  $tva[$idx_tva]=round($tva[$idx_tva],2);
359  }
360  else
361  {
362  $tva[$idx_tva]=$tva_item;
363  }
364  if ($oTva->get_parameter("both_side") == 0) {
365  $tot_tva = bcadd($tva_item, $tot_tva);
366  $tot_tva = round($tot_tva, 2);
367  } else {
368  $n_both = $tva_item;
369  $tva_item_currency = 0;
370  if ($n_both<0)
371  {
372  $tot_debit=round(bcadd($tot_debit, abs($n_both)),2);
373  }
374  }
375  }
376 
377  /* Save the stock */
378  /* if the quantity is < 0 then the stock increase (return of
379  * material)
380  */
381  $nNeg = (${"e_quant" . $i} < 0) ? -1 : 1;
382 
383  // always save quantity but in withStock we can find
384  // what card need a stock management
385  if ($g_parameter->MY_STOCK = 'Y' && isset($repo))
386  {
387  $dir=(${'e_quant'.$i} < 0 ) ? 'd':'c';
388  Stock_Goods::insert_goods($this->db, array('j_id' => $j_id, 'goods' => ${'e_march' . $i}, 'quant' => $nNeg * ${'e_quant' . $i}, 'dir' => $dir, 'repo' => $repo));
389  }
390 
391 
392  if ($g_parameter->MY_ANALYTIC != "nu" && $g_parameter->match_analytic($poste_val)) {
393  // for each item, insert into operation_analytique */
394  $op = new Anc_Operation($this->db);
395  $op->set_currency_rate($p_currency_rate);
396  $op->oa_group = $group;
397  $op->j_id = $j_id;
398  $op->oa_date = $e_date;
399  $op->oa_debit = 'f';
400  $op->oa_description = sql_string($e_comm);
401  $op->save_form_plan($_POST, $i, $j_id);
402  }
403  if (empty( ${'e_march' . $i . '_price'} ) ) ${'e_march' . $i . '_price'} = 0;
404  if (empty( ${'e_march' . $i } ) ) ${'e_march' . $i } = 0;
405  if (empty( ${'e_quant' . $i } ) ) ${'e_quant' . $i } = 0;
406 
407  $price_euro=bcdiv(${'e_march'.$i.'_price'}, $p_currency_rate);
408 
409  if ($g_parameter->MY_TVA_USE == 'Y') {
410  /* save into quant_sold */
411  $r = $this->db->exec_sql("select insert_quant_sold ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)", array(null, /* 1 */
412  $j_id, /* 2 */
413  ${'e_march' . $i}, /* 3 */
414  ${'e_quant' . $i}, /* 4 */
415  round($amount, 2), /* 5 */
416  $tva_item, /* 6 */
417  $idx_tva, /* 7 */
418  $e_client, /* 8 */
419  $n_both, /* 9 */
420  $price_euro/* Price /unit */
421  ));
422  } else {
423  $r = $this->db->exec_sql("select insert_quant_sold ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10) ", array(null, /* 1 */
424  $j_id, /* 2 */
425  ${'e_march' . $i}, /* 3 */
426  ${'e_quant' . $i}, /* 4 */
427  $amount, // 5
428  0,
429  null,
430  $e_client,
431  0, /* 9 */
432  $price_euro /* Price /unit */
433  ));
434  } // if ( $g_parameter->MY_TVA_USE=='Y') {
435  /*
436  * Insert also in operation_currency
437  */
438  $operation_currency=new Operation_currency_SQL($this->db);
439  $operation_currency->oc_amount=$amount_currency;
440  $operation_currency->oc_vat_amount=$tva_item_currency;
441  $operation_currency->oc_price_unit=${'e_march'.$i.'_price'};
442  $operation_currency->j_id=$j_id;
443  $operation_currency->insert();
444  $tot_amount_cur=round(bcadd($tot_amount_cur,$amount_currency),2);
445  $tot_amount_cur=round(bcadd($tot_amount_cur,$tva_item_currency),2);
446  }// end loop : save all items
447 
448  /* save total customer */
449  $cust_amount = bcadd($tot_amount, $tot_tva);
450  $cust_amount = round($cust_amount,2);
451  if ( DEBUGNOALYSS > 1 ) {
452  echo __LINE__." cust_amount $cust_amount<br>";
453  echo __LINE__." tot_amount $tot_amount<br>";
454  echo __LINE__." tot_tva $tot_tva<br>";
455 
456  }
457 
458  $acc_operation = new Acc_Operation($this->db);
459  $acc_operation->date = $e_date;
460  $acc_operation->poste = $poste;
461  $acc_operation->amount = $cust_amount;
462  $acc_operation->grpt = $seq;
463  $acc_operation->jrn = $p_jrn;
464  $acc_operation->type = 'd';
465  $acc_operation->periode = $tperiode;
466  $acc_operation->qcode = ${"e_client"};
467  if ($cust_amount>0)
468  {
469  $tot_debit=bcadd($tot_debit, $cust_amount);
470  $tot_debit=round($tot_debit, 2);
471  }
472  $let_tiers = $acc_operation->insert_jrnx();
473 
474  // --- insert also the currency amount for the customer
475  $operation_currency=new Operation_currency_SQL($this->db);
476  $operation_currency->oc_amount=$tot_amount_cur;
477  $operation_currency->oc_vat_amount=0;
478  $operation_currency->oc_price_unit=0;
479  $operation_currency->j_id=$let_tiers ;
480  $operation_currency->insert();
481 
482 
483  /** save all vat
484  * $i contains the tva_id and value contains the vat amount
485  * if if ($g_parameter->MY_TVA_USE == 'Y' )
486  */
487  if ($g_parameter->MY_TVA_USE == 'Y') {
488  if ( DEBUGNOALYSS > 1 ) {
489  var_dump($tva);
490  }
491  foreach ($tva as $i => $value) {
492  $oTva = new Acc_Tva($this->db);
493  $oTva->set_parameter('id', $i);
494  $oTva->load();
495 
496  $poste_vat = $oTva->get_side('c');
497 
498  $cust_amount = bcadd($tot_amount, $tot_tva);
499  $acc_operation = new Acc_Operation($this->db);
500  $acc_operation->date = $e_date;
501  $acc_operation->poste = $poste_vat;
502  $acc_operation->amount = $value;
503  $acc_operation->grpt = $seq;
504  $acc_operation->jrn = $p_jrn;
505  $acc_operation->type = 'c';
506  $acc_operation->periode = $tperiode;
507  if ($value<0)
508  {
509  $tot_debit=bcadd($tot_debit, abs($value));
510  $tot_debit=round($tot_debit, 2);
511  }
512  $acc_operation->insert_jrnx();
513  if ( DEBUGNOALYSS > 1 ) {
514  echo __LINE__." tot_tva $tot_tva<br>";
515 
516  }
517  // if TVA is on both side, we deduce it immediately
518  if ($oTva->get_parameter("both_side") == 1) {
519  $poste_vat = $oTva->get_side('d');
520  $cust_amount = bcadd($tot_amount, $tot_tva);
521  $acc_operation = new Acc_Operation($this->db);
522  $acc_operation->date = $e_date;
523  $acc_operation->poste = $poste_vat;
524  $acc_operation->amount = $value;
525  $acc_operation->grpt = $seq;
526  $acc_operation->jrn = $p_jrn;
527  $acc_operation->type = 'd';
528  $acc_operation->periode = $tperiode;
529  $acc_operation->insert_jrnx();
530  $tot_debit = bcadd($tot_debit, $value);
531  $tot_debit = round($tot_debit, 2);
532  $n_both = $value;
533  }
534  }
535  } // if ($g_parameter->MY_TVA_USE=='Y')
536  /*
537  * Balance the amount on D and C , the difference must be inserted as "difference due to a rounded value"
538  * Value are retrieve thanks $seq
539  */
540 
541  /* insert into jrn */
542  if ( DEBUGNOALYSS > 1 ) { echo __LINE__." tot_debit ".round($tot_debit,2)."<br>"; }
543  $acc_operation = new Acc_Operation($this->db);
544  $acc_operation->date = $e_date;
545  $acc_operation->echeance = $e_ech;
546  $acc_operation->amount = abs(round($tot_debit, 2));
547  $acc_operation->desc = $e_comm;
548  $acc_operation->grpt = $seq;
549  $acc_operation->jrn = $p_jrn;
550  $acc_operation->periode = $tperiode;
551  $acc_operation->pj = $e_pj;
552  $acc_operation->mt = $mt;
553  $acc_operation->currency_id=$p_currency_code;
554  $acc_operation->currency_rate=$p_currency_rate;
555  $acc_operation->currency_rate_ref=$currency_rate_ref->get_rate();
556 
557  if ( ! $this->jr_id=$acc_operation->insert_jrn() ) {
558  throw new Exception (_("Erreur de balance"));
559  }
560 
561  $this->pj = $acc_operation->set_pj();
562 
563  /* * = e_pj then do not increment sequence */
564  /* and e_pj is not null */
565  if (strcmp($e_pj, $e_pj_suggest) == 0 && strlen(trim($e_pj)) != 0) {
566  $this->inc_seq_pj();
567  }
568 
569  $this->db->exec_sql("update jrn set jr_internal=$1 where jr_grpt_id = $2" ,[$internal,$seq]);
570 
571 
572  /* update quant_sold */
573  $this->db->exec_sql('update quant_sold set qs_internal = $1
574  where j_id in (select j_id from jrnx where j_grpt=$2)'
575  , array($internal, $seq));
576 
577  /* Save the attachment or generate doc */
578  if (isset($_FILES['pj'])) {
579  if (strlen(trim($_FILES['pj']['name'])) != 0)
580  $this->db->save_receipt($seq);
581  else
582  /* Generate an invoice and save it into the database */
583  if (isset($_POST['gen_invoice'])) {
584  $file = $this->create_document($internal, $p_array);
585  $this->doc=HtmlInput::show_receipt_document($this->jr_id,h($file));
586  }
587  }
588  //----------------------------------------
589  // Save the payer
590  //----------------------------------------
591  if ($e_mp != 0) {
592  /**
593  * Date
594  */
595  $pay_date=($mp_date=="")?$e_date:$mp_date;
596 
597  /* mp */
598  $mp = new Acc_Payment($this->db, $e_mp);
599  $mp->load();
600 
601  /* fiche */
602  $fqcode = ${'e_mp_qcode_' . $e_mp};
603  $acfiche = new Fiche($this->db);
604  $acfiche->get_by_qcode($fqcode);
605 
606  /* jrnx */
607  $acseq = $this->db->get_next_seq('s_grpt');
608  $acjrn = new Acc_Ledger($this->db, $mp->get_parameter('ledger_target'));
609  $acinternal = $acjrn->compute_internal_code($acseq);
610 
611  /* Insert paid by */
612  $acc_pay = new Acc_Operation($this->db);
613  $acc_pay->date = $pay_date;
614  /* get the account and explode if necessary */
615  $sposte = $acfiche->strAttribut(ATTR_DEF_ACCOUNT);
616  // if 2 accounts, take only the debit one for customer
617  if (strpos($sposte, ',') != 0) {
618  $array = explode(',', $sposte);
619  $poste_val = $array[0];
620  } else {
621  $poste_val = $sposte;
622  }
623  // Convert paid amount in EUR
624  $acompte_eur=bcdiv($acompte, $p_currency_rate);
625 
626  $famount=bcsub($cust_amount,$acompte_eur);
627  $acc_pay->poste = $poste_val;
628  $acc_pay->qcode = $fqcode;
629  $acc_pay->amount = abs(round($famount, 2));
630  $acc_pay->desc = null;
631 
632  $acc_pay->grpt = $acseq;
633  $acc_pay->jrn = $mp->get_parameter('ledger_target');
634  $acc_pay->periode = $tperiode;
635  $acc_pay->type = ($famount >= 0) ? 'd' : 'c';
636  $let_pay=$acc_pay->insert_jrnx();
637 
638  /* Insert supplier */
639  $acc_pay = new Acc_Operation($this->db);
640  $acc_pay->date = $pay_date;
641  $acc_pay->poste = $poste;
642  $acc_pay->qcode = $e_client;
643  $acc_pay->amount = abs(round($famount, 2));
644  $acc_pay->desc = null;
645  $acc_pay->grpt = $acseq;
646  $acc_pay->jrn = $mp->get_parameter('ledger_target');
647  $acc_pay->periode = $tperiode;
648  $acc_pay->type = ($famount >= 0) ? 'c' : 'd';
649  $let_other = $acc_pay->insert_jrnx();
650 
651  // insert into operation_currency customer
652  $operation_currency=new Operation_currency_SQL($this->db);
653  $operation_currency->oc_amount=bcsub($tot_amount_cur,$acompte);
654  $operation_currency->oc_vat_amount=0;
655  $operation_currency->oc_price_unit=0;
656  $operation_currency->j_id=$let_other;
657  $operation_currency->insert();
658 
659  // insert into operation_currency bank
660  $operation_currency=new Operation_currency_SQL($this->db);
661  $operation_currency->oc_amount=bcsub($tot_amount_cur,$acompte);
662  $operation_currency->oc_vat_amount=0;
663  $operation_currency->oc_price_unit=0;
664  $operation_currency->j_id=$let_pay;
665  $operation_currency->insert();
666 
667  // Add info for currency
668  $acc_pay->currency_id=$p_currency_code;
669  $acc_pay->currency_rate=$p_currency_rate;
670  $acc_pay->currency_rate_ref=$currency_rate_ref->get_rate();
671 
672 
673  /* insert into jrn */
674  $acc_pay->mt = $mt;
675  $acjrn->grpt_id = $acseq;
676  $acc_pay->desc = (!isset($e_comm_paiement) || strlen(trim($e_comm_paiement)) == 0) ? $e_comm : $e_comm_paiement;
677  $mp_jr_id = $acc_pay->insert_jrn();
678  $acjrn->update_internal_code($acinternal);
679  // add an automatic PJ if ODS
680  if ($acjrn->get_type()=="ODS") {
681  $acc_pay->pj=$acjrn->guess_pj();
682  $acc_pay->set_pj();
683  }
684  $r1 = $this->get_id($internal);
685  $r2 = $this->get_id($acinternal);
686 
687  /*
688  * add lettering
689  */
690  $oletter = new Lettering($this->db);
691  $oletter->insert_couple($let_tiers, $let_other);
692 
693 
694  /* set the flag paid */
695  $Res = $this->db->exec_sql("update jrn set jr_rapt='paid' where jr_id=$1", array($r1));
696 
697  /* Reconcialiation */
698  $rec = new Acc_Reconciliation($this->db);
699  $rec->set_jr_id($r1);
700  $rec->insert($r2);
701 
702 
703  /*
704  * save also into quant_fin
705  */
706 
707  /* get ledger property */
708  $ledger = new Acc_Ledger_Fin($this->db, $acc_pay->jrn);
709  $prop = $ledger->get_propertie();
710 
711  /* if ledger is FIN then insert into quant_fin */
712  if ($prop['jrn_def_type'] == 'FIN') {
713  $ledger->insert_quant_fin($acfiche->id, $mp_jr_id, $cust->id, bcmul($famount, 1),$let_other);
714  }
715  }
716  } catch (Exception $e) {
717  record_log($e);
718  echo '<span class="error">' .
719  'Erreur dans l\'enregistrement ' .
720  __FILE__ . ':' . __LINE__ . ' ' .
721  $e->getMessage();
722  echo $e->getTraceAsString();
723 
724  $this->db->rollback();
725  throw new Exception ($e);
726  }
727  $this->db->commit();
728 
729  return $internal;
730  }
731 
732  /*!
733  * @brief show the summary of the operation and propose to save it
734  * @param array contains normally $_POST. It proposes also to save
735  * the Analytic accountancy
736  * @param $p_summary false for the feedback, true to show the summary
737  * @return string
738  *
739  */
740 
741  function confirm($p_array, $p_summary = false) {
742  global $g_parameter;
743  extract($p_array, EXTR_SKIP);
744 
745  // don't need to verify for a summary
746  if (!$p_summary)
747  {
748  $this->verify($p_array);
749  }
750  $anc = null;
751  // to show a select list for the analytic & VAT USE
752  // if analytic is op (optionnel) there is a blank line
753 
754  bcscale(4);
755  $client = new Fiche($this->db);
756  $client->get_by_qcode($e_client, true);
757 
758  $client_name = $client->getName() .
759  ' ' . $client->strAttribut(ATTR_DEF_ADRESS) . ' ' .
760  $client->strAttribut(ATTR_DEF_CP) . ' ' .
761  $client->strAttribut(ATTR_DEF_CITY);
762  $lPeriode = new Periode($this->db);
763  if ($this->check_periode() == true) {
764  $lPeriode->p_id = $period;
765  } else {
766  $lPeriode->find_periode($e_date);
767  }
768  $date_limit = $lPeriode->get_date_limit();
769  $r = "";
770  $r .= '<div id="summary_op1" >';
771  $r.='<TABLE>';
772  if ( $p_summary ) {
773  $jr_id=$this->db->get_value('select jr_id from jrn where jr_internal=$1',array($this->internal));
774  $r.="<tr>";
775  $r.='<td>';
776  $r.=_('Détail opération ');
777  $r.='</td>';
778  $r.='<td>';
779  $r.=sprintf ('<a class="line" style="display:inline" href="javascript:modifyOperation(%d,%d)">%s</a>',
780  $jr_id,dossier::id(),$this->internal);
781  $r.='</td>';
782  $r.="</tr>";
783  }
784  $r.='<tr>';
785  if ( ! $p_summary) {
786  $r.='<td>' . _('Numéro Pièce') .'</td><td>'. hb($e_pj) . '</td>';
787  } else {
788 
789  if ( strcmp($this->pj,$e_pj) != 0 )
790  {
791  $r.='<td>' . _('Numéro Pièce') .'</td><td>'. hb($this->pj) .
792  '<span class="notice"> '._('Attention numéro pièce existante, elle a du être adaptée').'</span></td>';
793  } else {
794  $r.='<td>' . _('Numéro Pièce') .'</td><td>'. hb($this->pj) . '</td>';
795  }
796  }
797  $r.='</tr>';
798  $r.='<tr>';
799  $r.='<td> ' . _('Date') . '</td><td> ' . hb($e_date) . '</td>';
800  $r.='</tr>';
801  $r.='<tr>';
802  $r.='<td>' . _('Echeance') . '</td><td> ' . hb($e_ech) . '</td>';
803  $r.='</tr>';
804  $r.='<tr>';
805  $r.='<td> ' . _('Période Comptable') . '</td><td> ' .hb( $date_limit['p_start'] . '-' . $date_limit['p_end']) . '</td>';
806  $r.='</tr>';
807  $r.='</table>';
808  $r.='</div>';
809  $r .= '<div id="summary_op2">';
810  $r.='<table>';
811  $r.='<tr>';
812  $r.='<td> ' . _('Journal') . '</td><td> ' . hb($this->get_name()) . '</td>';
813  $r.='</tr>';
814  $r.='<tr>';
815  $r.='<td> ' . _('Libellé') . '</td><td> ' . hb($e_comm) . '</td>';
816  $r.='</tr>';
817 
818  $r.='<tr>';
819  $r.='<td> ' . _('Client') . '</td><td> ' . hb($e_client . ':' . $client_name) . '</td>';
820  $r.='</tr>';
821  $r.='</table>';
822  $r.='</div>';
823  $r.='<div style="position:float;clear:both">';
824  $r.='</div>';
825 
826  $r.='<h2>' . _('Détail articles vendus') . '</h2>';
827  $r.='<p class="decale">';
828  $r.='<table class="result" >';
829  $r.='<TR>';
830  $r.="<th>" . _('Code') . "</th>";
831  $r.="<th>" . _('Dénomination') . "</th>";
832  $r.="<th style=\"text-align:right\">" . _('prix') . "</th>";
833  $r.="<th style=\"text-align:right\">" . _('quantité') . "</th>";
834 
835 
836  if ($g_parameter->MY_TVA_USE == 'Y') {
837  $r.="<th style=\"text-align:right\">" . _('tva') . "</th>";
838  $r.='<th style="text-align:right"> ' . _('Montant TVA') . '</th>';
839  $r.='<th style="text-align:right">' . _('Montant HTVA') . '</th>';
840  $r.='<th style="text-align:right">' . _('Montant TVAC') . '</th>';
841  } else {
842  $r.='<th style="text-align:right">' . _('Montant') . '</th>';
843  }
844  /* if we use the AC */
845  if ($g_parameter->MY_ANALYTIC != 'nu') {
846  $anc = new Anc_Plan($this->db);
847  $a_anc = $anc->get_list();
848  $x = count($a_anc);
849  /* set the width of the col */
850  $r.='<th colspan="' . $x . '">' . _('Compt. Analytique') . '</th>';
851 
852  /* add hidden variables pa[] to hold the value of pa_id */
853  $r.=Anc_Plan::hidden($a_anc);
854  }
855  $r.='</tr>';
856  $tot_amount = 0.0;
857  $tot_tva = 0.0;
858  for ($i = 0; $i < $nb_item; $i++) {
859  if (strlen(trim(${"e_march" . $i})) == 0)
860  continue;
861 
862  /* retrieve information for card */
863  $fiche = new Fiche($this->db);
864  $fiche->get_by_qcode(${"e_march" . $i});
865  if ($g_parameter->MY_UPDLAB == 'Y')
866  $fiche_name = h(${"e_march" . $i . "_label"});
867  else
868  $fiche_name = $fiche->strAttribut(ATTR_DEF_NAME);
869  if ($g_parameter->MY_TVA_USE == 'Y') {
870  $oTva = new Acc_Tva($this->db);
871  $idx_tva = ${"e_march" . $i . "_tva_id"};
872 
873  $oTva->set_parameter('id', $idx_tva);
874  $oTva->load();
875  }
876  $op = new Acc_Compute();
877  $amount = bcmul(${"e_march" . $i . "_price"}, ${'e_quant' . $i});
878  $op->set_parameter("amount", $amount);
879  if ($g_parameter->MY_TVA_USE == 'Y') {
880  $op->set_parameter('amount_vat_rate', $oTva->get_parameter('rate'));
881  $op->compute_vat();
882  $tva_computed = $op->get_parameter('amount_vat');
883  $tva_item = ${"e_march" . $i . "_tva_amount"};
884  if (isset($tva[$idx_tva]))
885  $tva[$idx_tva]=bcadd($tva[$idx_tva],$tva_item,2);
886  else
887  $tva[$idx_tva] = $tva_item;
888  $tot_tva = round(bcadd($tva_item, $tot_tva), 2);
889  }
890  $tot_amount = round(bcadd($tot_amount, $amount), 2);
891 
892  $r.='<tr>';
893  $r.='<td>';
894  $r.=${"e_march" . $i};
895  $r.='</td>';
896  $r.='<TD style="border-bottom:1px dotted grey;">';
897  $r.=$fiche_name;
898  $r.='</td>';
899  $r.='<td class="num">';
900  $r.=nbm(${"e_march" . $i . "_price"},4);
901  $r.='</td>';
902  $r.='<td class="num">';
903  $r.=nbm(${"e_quant" . $i},4);
904  $r.='</td>';
905  $both_side=0;
906  if ($g_parameter->MY_TVA_USE == 'Y') {
907  $r.='<td class="num">';
908  $r.=$oTva->get_parameter('label');
909  $r.='</td>';
910  $both_side=$oTva->get_parameter("both_side");
911  /* warning if tva_computed and given are not the
912  same */
913  if (bcsub($tva_item, $tva_computed) != 0 && ! ($tva_item == 0 && $both_side == 1)) {
914  $r.='<td style="background-color:red" class="num">';
916  $r.='<a href="#" class="error" style="display:inline" title="' . _("Attention Différence entre TVA calculée et donnée") . '">'
917  . nbm($tva_item) . '<a>';
918  } else {
919  $r.='<td class="num">';
920  $r.=nbm($tva_item);
921  }
922  $r.='</td>';
923  $r.='<td class="num">';
924  $r.=nbm($amount);
925  $r.='</td>';
926  $tot_row = bcadd($tva_item, $amount);
927  $r.=td(nbm($tot_row), 'class="num"');
928  } else {
929  $r.='<td class="num">';
930  $r.=nbm($amount);
931  $r.='</td>';
932  }
933  // encode the pa
934  if ($g_parameter->MY_ANALYTIC != 'nu'
935  && $g_parameter->match_analytic($fiche->strAttribut(ATTR_DEF_ACCOUNT))==TRUE) { // use of AA
936  // show form
937  $anc_op = new Anc_Operation($this->db);
938  $null = ($g_parameter->MY_ANALYTIC == 'op') ? 1 : 0;
939  $r.='<td>';
940  $p_mode = ($p_summary == false) ? 1 : 0;
941  $p_array['pa_id'] = $a_anc;
942  /* op is the operation it contains either a sequence or a jrnx.j_id */
943  $r.=HtmlInput::hidden('op[]=', $i);
944  $r.=$anc_op->display_form_plan($p_array, $null, $p_mode, $i, round($amount,2));
945  $r.='</td>';
946  }
947 
948 
949  $r.='</tr>';
950  } // end loop item
951  //
952  // Add the sum
953  $decalage=($g_parameter->MY_TVA_USE == 'Y')?'<td></td><td></td><td></td><td></td>':'<td></td>';
954  $tot = bcadd($tot_amount, $tot_tva, 2);
955  $tot_eur=round(bcdiv($tot, $p_currency_rate),2);
956  $tot=nbm($tot);
957  $str_tot=_('Totaux');
958 
959  // Get currency code
960  $default_currency=new Acc_Currency($this->db,0);
961  $str_code=$default_currency->get_code();
962  if ( $p_currency_code != 0 ) {
963  $acc_currency=new Acc_Currency($this->db);
964  $acc_currency->set_id($p_currency_code);
965  $str_code=$acc_currency->get_code();
966  }
967  // Format amount
969  $tot_tva=nbm($tot_tva);
970 
971 if ( $g_parameter->MY_TVA_USE=="Y") {
972  $r.=<<<EOF
973 <tr class="highlight">
974  {$decalage}
975  <td>
976  {$str_tot} {$str_code}
977  </td>
978  <td class="num">
979  {$tot_tva}
980  </td>
981  <td class="num">
982  {$tot_amount}
983  </td>
984  <td class="num">
985  {$tot} {$str_code}
986  </td>
987  </tr>
988 EOF;
989  if ($p_currency_code !=0) {
990  $rate=_("Taux ");
991 $r.=<<<EOF
992 <tr class="highlight">
993  {$decalage}
994  <td>
995 
996  </td>
997  <td class="num">
998 
999  </td>
1000  <td class="num">
1001  {$rate} {$p_currency_rate}
1002  </td>
1003  <td class="num">
1004  {$tot_eur} EUR
1005  </td>
1006 </tr>
1007 EOF;
1008  }
1009 
1010  } else {
1011  $r.=<<<EOF
1012 <tr class="highlight">
1013  {$decalage}
1014  <td>
1015  {$str_tot} {$str_code}
1016  </td>
1017  <td class="num">
1018 
1019  </td>
1020  <td class="num">
1021 
1022  </td>
1023  <td class="num">
1024  {$tot}
1025  </td>
1026  </tr>
1027 <tr class="highlight">
1028  {$decalage}
1029  <td>
1030  </td>
1031  <td>
1032 
1033  </td>
1034  <td>
1035  {$rate} {$p_currency_rate}
1036  </td>
1037  <td class="num">
1038  {$tot} {$str_code}
1039  </td>
1040 </tr>
1041 EOF;
1042  }
1043  $r.='</table>';
1044  $r.='</p>';
1045  if ($g_parameter->MY_ANALYTIC != 'nu' && ! $p_summary) // use of AA
1046  $r.='<input type="button" class="button" value="' . _('Vérifiez Imputation Analytique') . '" onClick="verify_ca(\'\');">';
1047  $r.=(! $p_summary )?'<div id="total_div_id" >':'<div>';
1048  $r.='<h2>Totaux</h2>';
1049 
1050  /* use VAT */
1051  if ($g_parameter->MY_TVA_USE == 'Y') {
1052  $r.='<table>';
1053  $r.='<tr><td>Total HTVA</td>';
1054  $r.=td(hb($tot_amount ),'class="num"');
1055  foreach ($tva as $i => $value) {
1056  $oTva->set_parameter('id', $i);
1057  $oTva->load();
1058 
1059  $r.='<tr><td> TVA ' . $oTva->get_parameter('label').'</td>';
1060  $r.=td(hb(nbm($tva[$i])),'class="num"');
1061  }
1062  $r.='<tr>'.td(_('Total TVA')).td(hb($tot_tva),'class="num"');
1063  $r.='<tr>'.td(_('Total TVAC')).td(hb($tot),'class="num"');
1064  $r.='</table>';
1065  } else {
1066  $r.='<br>Total '.hb($tot);
1067  }
1068  $r.='</div>';
1069 
1070 
1071  /* Add hidden */
1072  $r.=HtmlInput::hidden('e_client', $e_client);
1073  $r.=HtmlInput::hidden('nb_item', $nb_item);
1074  $r.=HtmlInput::hidden('p_jrn', $p_jrn);
1075  $mt = microtime(true);
1076  $r.=HtmlInput::hidden('mt', $mt);
1077  $r.=HtmlInput::post_to_hidden(['p_currency_rate','p_currency_code']);
1078 
1079  if (isset($period))
1080  {
1081  $r.=HtmlInput::hidden('period', $period);
1082  }
1083  /* \todo comment les types hidden gérent ils des contenus avec des quotes, double quote ou < > ??? */
1084  $r.=HtmlInput::hidden('e_comm', $e_comm);
1085  $r.=HtmlInput::hidden('e_date', $e_date);
1086  $r.=HtmlInput::hidden('e_ech', $e_ech);
1087  $r.=HtmlInput::hidden('e_pj', $e_pj);
1088  $r.=HtmlInput::hidden('e_pj_suggest', $e_pj_suggest);
1089 
1090  $e_mp = (isset($e_mp)) ? $e_mp : 0;
1091  $r.=HtmlInput::hidden('e_mp', $e_mp);
1092 
1093  if ( isset($repo) ) {
1094  // Show the available repository
1095  $r.= $this->select_depot($p_summary,$repo);
1096  }
1097 
1098  /* if the paymethod is not 0 and if a quick code is given */
1099  if ($e_mp != 0 && strlen(trim(${'e_mp_qcode_' . $e_mp})) != 0) {
1100  $r.=HtmlInput::hidden('e_mp_qcode_' . $e_mp, ${'e_mp_qcode_' . $e_mp});
1101  $r.=HtmlInput::hidden('acompte', $acompte);
1102  $r.=HtmlInput::hidden('e_comm_paiement', $e_comm_paiement);
1103  /* needed for generating a invoice */
1104  $r.=HtmlInput::hidden('qcode_benef', ${'e_mp_qcode_' . $e_mp});
1105  $r.=HtmlInput::hidden('mp_date', ${'mp_date'});
1106 
1107  $fname = new Fiche($this->db);
1108  $fname->get_by_qcode(${'e_mp_qcode_' . $e_mp});
1109  $r.='<h2>' . "Payé par " . ${'e_mp_qcode_' . $e_mp} .
1110  " le ".${"mp_date"}.
1111  " " . $fname->getName() . '</h2> ' . '<p class="decale">' . _('Déduction acompte ') . h($acompte) . '</p>' .
1112  _('Libellé :') . h($e_comm_paiement) ;
1113  $r.='<br>';
1114  }
1115 
1116  $r.=HtmlInput::hidden('jrn_type', $jrn_type);
1117  for ($i = 0; $i < $nb_item; $i++) {
1118  $r.=HtmlInput::hidden("e_march" . $i, ${"e_march" . $i});
1119  if (isset(${"e_march" . $i . "_label"}))
1120  $r.=HtmlInput::hidden("e_march" . $i . "_label", ${"e_march" . $i . "_label"});
1121  $r.=HtmlInput::hidden("e_march" . $i . "_price", ${"e_march" . $i . "_price"});
1122  if ($g_parameter->MY_TVA_USE == 'Y') {
1123  $r.=HtmlInput::hidden("e_march" . $i . "_tva_id", ${"e_march" . $i . "_tva_id"});
1124  $r.=HtmlInput::hidden("e_march" . $i . "_tva_amount", ${"e_march" . $i . "_tva_amount"});
1125  }
1126  $r.=HtmlInput::hidden("e_quant" . $i, ${"e_quant" . $i});
1127  }
1128  /*
1129  * warning if the amount is positive and expecting a negative one
1130  */
1131  $negative=$this->display_negative_warning($tot);
1132  if ( $negative != "") {
1133  $r.=span($negative,'class="warning" ');
1134  }
1135  return $r;
1136  }
1137 
1138  /*!\brief the function extra info allows to
1139  * - add a attachment
1140  * - generate an invoice
1141  * - insert extra info
1142  * \return string
1143  */
1144 
1145  public function extra_info() {
1146  $r = '<div id="facturation_div_id" style="height:185px;height:10rem">';
1147  // check for upload piece
1148  $file = new IFile();
1149  $file->table = 0;
1150  $file->setAlertOnSize(true);
1151  $r.='<p class="decale">';
1152  $r.=_("Ajoutez une pièce justificative ");
1153  $r.=$file->input("pj", "");
1154 
1155  if ($this->db->count_sql("select md_id,md_name from document_modele where md_affect='VEN'") > 0) {
1156 
1157 
1158  $r.=_('ou générer une facture') . ' <input type="checkbox" name="gen_invoice" CHECKED>';
1159  // We propose to generate the invoice and some template
1160  $doc_gen = new ISelect();
1161  $doc_gen->name = "gen_doc";
1162  $doc_gen->value = $this->db->make_array(
1163  "select md_id,md_name " .
1164  " from document_modele where md_affect='VEN'");
1165  $r.=$doc_gen->input() . '<br>';
1166  }
1167  $r.='<br>';
1168  $obj = new IText();
1169  $r.=_('Numero de bon de commande : ') . $obj->input('bon_comm') . '<br>';
1170  $r.=_('Autre information : ') . $obj->input('other_info') . '<br>';
1171  $r.='</p>';
1172  $r.='</div>';
1173  return $r;
1174  }
1175 
1176 
1177 
1178  /*!\brief display the form for entering data for invoice,
1179  * \param $p_array is null or you can put the predef operation or the $_POST
1180  *
1181  * \return HTML string
1182  */
1183 
1184  function input($p_array = null, $p_readonly = 0) {
1185  global $g_parameter, $g_user;
1186  if ($p_array != null)
1187  extract($p_array, EXTR_SKIP);
1188  $http=new HttpInput();
1189 
1190  $flag_tva = $g_parameter->MY_TVA_USE;
1191  /* Add button */
1192 
1193  $str_add_button_tiers = "";
1194  $add_card=FALSE;
1195  if ($g_user->check_action(FICADD) == 1) {
1196  $add_card=TRUE;
1197  $str_add_button_tiers = $this->add_card("deb", "e_client");
1198  }
1199 
1200  // The first day of the periode
1201  $oPeriode = new Periode($this->db);
1202  list ($l_date_start, $l_date_end) = $oPeriode->get_date_limit($g_user->get_periode());
1203  if ($g_parameter->MY_DATE_SUGGEST == 'Y')
1204  $op_date = (!isset($e_date) ) ? $l_date_start : $e_date;
1205  else
1206  $op_date = (!isset($e_date) ) ? '' : $e_date;
1207 
1208  $e_ech = (isset($e_ech)) ? $e_ech : "";
1209  $e_comm = (isset($e_comm)) ? $e_comm : "";
1210 
1211  $r = '';
1212  $r.=dossier::hidden();
1213  $f_legend = _('Client');
1214 
1215  $Echeance = new IDate();
1216  $Echeance->setReadOnly(false);
1217 
1218  $Echeance->tabindex = 2;
1220  $f_echeance = $Echeance->input('e_ech', $e_ech, _('Echéance') . $label);
1221  $Date = new IDate();
1222  $Date->setReadOnly(false);
1223 
1224  $f_date = $Date->input("e_date", $op_date);
1225 
1226  $f_periode = '';
1227  // Periode
1228  //--
1229  if ($this->check_periode() == true) {
1230  $l_user_per = $g_user->get_periode();
1231  $def = (isset($periode)) ? $periode : $l_user_per;
1232 
1233  $period = new IPeriod("period");
1234  $period->user = $g_user;
1235  $period->cn = $this->db;
1236  $period->value = $def;
1237  $period->type = OPEN;
1238  try {
1239  $l_form_per = $period->input();
1240  } catch (Exception $e) {
1241  if ($e->getCode() == 1) {
1242  throw new Exception( _("Aucune période ouverte") );
1243  }
1244  }
1246  $f_periode = '<td>' . _("Période comptable") . "</td> <td> $label " . $l_form_per . '</td>';
1247  }
1248  /* if we suggest the next pj, then we need a javascript */
1249  $add_js = "";
1250  if ($g_parameter->MY_PJ_SUGGEST == 'Y') {
1251  $add_js = "update_pj();";
1252  }
1253  if ($g_parameter->MY_DATE_SUGGEST == 'Y') {
1254  $add_js.='get_last_date();';
1255  }
1256  $add_js.='update_name();';
1257  $add_js.='update_pay_method();';
1258  $add_js.='update_row("sold_item");';
1259 
1260  $wLedger = $this->select_ledger('VEN', 2,FALSE);
1261  if ($wLedger == null)
1262  throw new Exception(_('Pas de journal disponible'));
1263  $wLedger->table = 0;
1264  $wLedger->javascript = "onChange='update_predef(\"ven\",\"f\",\"".$_REQUEST['ac']."\");$add_js'";
1265  $wLedger->label = " Journal " . Icon_Action::infobulle(2);
1266 
1267  $f_jrn = $wLedger->input();
1268 
1269  $Commentaire = new IText();
1270  $Commentaire->table = 0;
1271  $Commentaire->setReadOnly(false);
1272  $Commentaire->size = 60;
1273  $Commentaire->tabindex = 3;
1274 
1276 
1277  $f_desc = $Commentaire->input("e_comm", $e_comm) ;
1278  // PJ
1279  //--
1280  /* suggest PJ ? */
1281  $default_pj = '';
1282  if ($g_parameter->MY_PJ_SUGGEST == 'Y') {
1283  $default_pj = $this->guess_pj();
1284  }
1285 
1286  $pj = new IText();
1287 
1288  $pj->table = 0;
1289  $pj->name = "e_pj";
1290  $pj->size = 10;
1291  $pj->value = (isset($e_pj)) ? $e_pj : $default_pj;
1292  $f_pj = $pj->input() . HtmlInput::hidden('e_pj_suggest', $default_pj);
1293  // Display the customer
1294  //--
1295  $fiche = 'deb';
1296 
1297  // Save old value and set a new one
1298  //--
1299  $e_client = ( isset($e_client) ) ? $e_client : "";
1300  $e_client_label = "&nbsp;"; //str_pad("",100,".");
1301  // retrieve e_client_label
1302  //--
1303 
1304  if (strlen(trim($e_client)) != 0) {
1305  $fClient = new Fiche($this->db);
1306  $fClient->get_by_qcode($e_client);
1307  $e_client_label = $fClient->strAttribut(ATTR_DEF_NAME) . ' ' .
1308  ' Adresse : ' . $fClient->strAttribut(ATTR_DEF_ADRESS) . ' ' .
1309  $fClient->strAttribut(ATTR_DEF_CP) . ' ' .
1310  $fClient->strAttribut(ATTR_DEF_CITY) . ' ';
1311  }
1312 
1313  $W1 = new ICard();
1314  $W1->label = "Client " . Icon_Action::infobulle(0);
1315  $W1->name = "e_client";
1316  $W1->tabindex = 3;
1317  $W1->value = $e_client;
1318  $W1->table = 0;
1319  $W1->set_dblclick("fill_ipopcard(this);");
1320  $W1->set_attribute('ipopup', 'ipopcard');
1321 
1322  // name of the field to update with the name of the card
1323  $W1->set_attribute('label', 'e_client_label');
1324  // name of the field to update with the name of the card
1325  $W1->set_attribute('typecard', 'deb');
1326 
1327  // Add the callback function to filter the card on the jrn
1328  $W1->set_callback('filter_card');
1329  $W1->set_function('fill_data');
1330  $W1->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', $W1->name);
1331  $f_client_qcode = $W1->input();
1332  $client_label = new ISpan();
1333  $client_label->table = 0;
1334  $f_client = $client_label->input("e_client_label", $e_client_label);
1335  $f_client_bt = $W1->search();
1336 
1337 
1338  // Record the current number of article
1339  $Hid = new IHidden();
1340  $p_article = ( isset($nb_item)) ? $nb_item : $this->get_min_row();
1341  $r.=$Hid->input("nb_item", $p_article);
1342  $p_article = ($p_article < $this->get_min_row()) ? $this->get_min_row() : $p_article;
1343 
1344 
1345  $f_legend_detail = _("Détail articles vendus");
1346 
1347  // For each article
1348  //--
1349  for ($i = 0; $i < $p_article; $i++) {
1350  // Code id, price & vat code
1351  //--
1352  $march = (isset(${"e_march$i"})) ? ${"e_march$i"} : "";
1353  $march_price = (isset(${"e_march" . $i . "_price"})) ? ${"e_march" . $i . "_price"} : "" ;
1354  if ($flag_tva == 'Y') {
1355  $march_tva_id = (isset(${"e_march$i" . "_tva_id"})) ? ${"e_march$i" . "_tva_id"} : "";
1356  $march_tva_amount = (isset(${"e_march$i" . "_tva_amount"})) ? ${"e_march$i" . "_tva_amount"} : "";
1357  }
1358  $march_label = (isset(${"e_march" . $i . "_label"})) ? ${"e_march" . $i . "_label"} : "";
1359 
1360  // retrieve the tva label and name
1361  //--
1362  if (strlen(trim($march)) != 0 && strlen(trim($march_label)) == 0) {
1363  $fMarch = new Fiche($this->db);
1364  $fMarch->get_by_qcode($march);
1365  $march_label = $fMarch->strAttribut(ATTR_DEF_NAME);
1366  if ($flag_tva == 'Y') {
1367  if (!(isset(${"e_march$i" . "_tva_id"})))
1368  $march_tva_id = $fMarch->strAttribut(ATTR_DEF_TVA);
1369  }
1370  }
1371  // Show input
1372  //--
1373  $W1 = new ICard();
1374  $W1->label = "";
1375  $W1->name = "e_march" . $i;
1376  $W1->value = $march;
1377  $W1->table = 1;
1378  $W1->set_attribute('typecard', 'cred');
1379  $W1->set_dblclick("fill_ipopcard(this);");
1380  $W1->set_attribute('ipopup', 'ipopcard');
1381 
1382  // name of the field to update with the name of the card
1383  $W1->set_attribute('label', 'e_march' . $i . '_label');
1384  // name of the field with the price
1385  $W1->set_attribute('price', 'e_march' . $i . '_price');
1386  // name of the field with the TVA_ID
1387  $W1->set_attribute('tvaid', 'e_march' . $i . '_tva_id');
1388  // Add the callback function to filter the card on the jrn
1389  $W1->set_callback('filter_card');
1390  $W1->set_function('fill_data');
1391  $W1->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', $W1->name);
1392 
1393  $W1->readonly = false;
1394 
1395  $array[$i]['quick_code'] = $W1->input();
1396  $array[$i]['bt'] = $W1->search();
1397  $array[$i]['card_add']=($add_card==TRUE)?$this->add_card("cred", $W1->id):"";
1398  // For computing we need some hidden field for holding the value
1399  $array[$i]['hidden'] = '';
1400  if ($flag_tva == 'Y')
1401  $array[$i]['hidden'].=HtmlInput::hidden('tva_march' . $i, 0);
1402 
1403  $htva = new INum('htva_march' . $i);
1404  $htva->readOnly = 1;
1405  $htva->value = 0;
1406  $array[$i]['htva'] = $htva->input();
1407 
1408  if ($g_parameter->MY_TVA_USE == 'Y')
1409  $tvac = new INum('tvac_march' . $i);
1410  else
1411  $tvac = new IHidden('tvac_march' . $i);
1412 
1413  $tvac->readOnly = 1;
1414  $tvac->value = 0;
1415  $array[$i]['tvac'] = $tvac->input();
1416 
1417  if ( $g_parameter->MY_UPDLAB == 'Y')
1418  {
1419  $Span=new IText("e_march".$i."_label");
1420  $Span->style='class="input_text label_item"';
1421  } else
1422  {
1423  $Span=new ISpan("e_march".$i."_label");
1424  $Span->extra='class="label_item"';
1425  }
1426  $Span->value = $march_label;
1427  $Span->setReadOnly(false);
1428  // card's name, price
1429  //--
1430  $array[$i]['denom'] = $Span->input("e_march" . $i . "_label", $march_label);
1431  // price
1432  $Price = new INum();
1433  $Price->setReadOnly(false);
1434  $Price->size = 9;
1435  $Price->javascript = "onblur=\"format_number(this,4);clean_tva($i);compute_ledger($i)\"";
1436  $array[$i]['pu'] = $Price->input("e_march" . $i . "_price", $march_price);
1437  $array[$i]['tva'] = '';
1438  $array[$i]['amount_tva'] = '';
1439  // if tva is not needed then no tva field
1440  if ($flag_tva == 'Y') {
1441  // vat label
1442  //--
1443  $Tva = new ITva_Popup($this->db);
1444  $Tva->in_table = true;
1445  $Tva->set_attribute('compute', $i);
1446  $Tva->set_filter("sale");
1447 
1448  $Tva->js = 'onblur="clean_tva(' . $i . ');compute_ledger(' . $i . ')"';
1449  $Tva->value = $march_tva_id;
1450  $array[$i]['tva'] = $Tva->input("e_march$i" . "_tva_id");
1451  // vat amount
1452  //--
1453  $wTva_amount = new INum();
1454  $wTva_amount->readOnly = false;
1455  $wTva_amount->size = 6;
1456  $wTva_amount->javascript = "onblur='format_number(this);compute_ledger($i)'";
1457  $array[$i]['amount_tva'] = $wTva_amount->input("e_march" . $i . "_tva_amount", $march_tva_amount);
1458  }
1459  // quantity
1460  //--
1461  $quant = (isset(${"e_quant$i"})) ? ${"e_quant$i"} : "1"
1462  ;
1463  $Quantity = new INum();
1464  $Quantity->prec=4;
1465  $Quantity->setReadOnly(false);
1466  $Quantity->size = 8;
1467  $Quantity->javascript = "onchange=\"format_number(this);clean_tva($i);compute_ledger($i);\"";
1468  $array[$i]['quantity'] = $Quantity->input("e_quant" . $i, $quant);
1469  }// foreach article
1470  $f_type = _('Client');
1471 
1472  // Currency
1473  $currency_select = $this->CurrencyInput("currency_code", "p_currency_rate" , "p_currency_euro");
1474  $currency_select->selected=$http->request('p_currency_code','string',0);
1475 
1476  $currency_input=new INum("p_currency_rate");
1477  $currency_input->id="p_currency_rate";
1478  $currency_input->prec=6;
1479  $currency_input->value=$http->request('p_currency_rate','string',1);
1480  $currency_input->javascript='onchange="format_number(this,4);CurrencyCompute(\'p_currency_rate\',\'p_currency_euro\');"';
1481 
1482  $currency=new Acc_Currency($this->db,0);
1483 
1484  //
1485  // Button for template operation
1486  //
1487  ob_start();
1488  echo '<div id="predef_form">';
1489  echo HtmlInput::hidden('p_jrn_predef', $this->id);
1490  $op=new Pre_operation($this->db);
1491  $op->set_jrn_type("VEN");
1492  $op->set_p_jrn($this->id);
1493  $op->set_od_direct('f');
1494  $http=new \HttpInput();
1495  $url=http_build_query(array('p_jrn_predef'=>$this->id, 'ac'=>$http->request('ac'),
1496  'gDossier'=>dossier::id()));
1497  echo $op->form_get('do.php?'.$url);
1498  echo '</div>';
1499  $str_op_template=ob_get_contents();
1500  ob_end_clean();
1501 
1502  ob_start();
1503  require_once NOALYSS_TEMPLATE.'/form_ledger_detail.php';
1504  $r.=ob_get_contents();
1505  ob_end_clean();
1506 
1507 
1508 
1509  // Set correctly the REQUEST param for jrn_type
1510  $r.=HtmlInput::hidden('jrn_type', 'VEN');
1512  $r.= create_script("$('" . $Date->id . "').focus()");
1513  return $r;
1514  }
1515  /**
1516  * Retrieve data from the view v_detail_sale , gives all the row of an operation
1517  *
1518  * @remark $g_user connected user
1519  * @param $p_from jrn.jr_tech_per from
1520  * @param type $p_end jrn.jr_tech_per to
1521  * @param $p_filter_operation valid option : all, paid, unpaid
1522  * @return type
1523  */
1524  function get_detail_sale($p_from,$p_end,$p_filter_operation='all')
1525  {
1526  global $g_user;
1527  // Journal valide
1528  if ( $this->id == 0 ) die (__FILE__.":".__LINE__." Journal invalide");
1529 
1530  // Securite
1531  if ( $g_user->get_ledger_access($this->id) == 'X' ) return null;
1532 
1533  switch ( $p_filter_operation)
1534  {
1535  case 'all':
1536  $sql_filter="";
1537  break;
1538  case 'paid':
1539  $sql_filter=" and (jr_date_paid is not null or jr_rapt ='paid' ) ";
1540  break;
1541  case 'unpaid':
1542  $sql_filter=" and (jr_date_paid is null and coalesce(jr_rapt,'x') <> 'paid' ) ";
1543  break;
1544  default:
1545  throw new Exception(_("Filtre invalide",5));
1546 
1547  }
1548  // get the data from the view
1549  $sql = "select *
1550  from v_detail_sale
1551  where
1552  jr_def_id = $1
1553  and jr_date >= (select p_start from parm_periode where p_id = $2)
1554  {$sql_filter}
1555  and jr_date <= (select p_end from parm_periode where p_id = $3) "
1556  .' order by jr_date,substring(jr_pj_number,\'[0-9]+$\')::numeric asc ';
1557  $ret = $this->db->exec_sql($sql, array($this->id,$p_from, $p_end));
1558  return $ret;
1559  }
1560  /**
1561  * @brief compute an array with the heading cells for the
1562  * details, used for the export in CSV
1563  * @return array
1564  */
1565  static function heading_detail_sale()
1566  {
1567  $array['jr_id'] = _('Numéro opération');
1568  $array['jr_date'] = _('Date');
1569  $array['jr_date_paid'] = _('Date paiement');
1570  $array['jr_ech'] = _('Date échéance');
1571  $array['jr_tech_per'] = _('Période');
1572  $array['jr_comment'] = _('Libellé');
1573  $array['jr_pj_number'] = _('Pièce');
1574  $array['jr_internal'] = _('Interne');
1575  $array['jr_def_id'] = _('Code journal');
1576  $array['j_poste'] = _('Poste');
1577  $array['j_text'] = _('Commentaire');
1578  $array['j_qcode'] = _('Code Item');
1579  $array['item_card'] = _('N° fiche');
1580  $array['item_name'] = _('Nom fiche');
1581  $array['qs_client'] = _('N° fiche fournisseur');
1582  $array['tiers_name'] = _('Nom fournisseur');
1583  $array['quick_code'] = _('Code fournisseur');
1584  $array['tva_label'] = _('Nom TVA');
1585  $array['tva_comment'] = _('Commentaire TVA');
1586  $array['tva_both_side'] = _('TVA annulée');
1587  $array['vat_sided'] = _('TVA Non Payé');
1588  $array['vat_code'] = _('Code TVA');
1589  $array['vat'] = _('Montant TVA');
1590  $array['price'] = _('Total HTVA');
1591  $array['quantity'] = _('quantité');
1592  $array['price_per_unit'] = _('PU');
1593  $array['htva'] = _('HTVA Opération');
1594  $array['tot_vat'] = _('TVA Opération');
1595  $array['tot_vat_np'] = _('TVA ND');
1596  $array['oc_amount'] = _('Mont. Devise');
1597  $array['oc_vat_amount'] = _('Mont. TVA Devise');
1598  $array['cr_code_iso'] = _('Devise');
1599 
1600  return $array;
1601  }
1602 
1603 
1604 
1605 }
1606 
nbm
nbm($p_number, $p_dec=2)
format the number with a sep.
Definition: ac_common.php:137
$dir
$dir
Definition: file-dir.php:3
$tot
$tot['htva']
Definition: acc_ledger_history_purchase_detail.php:62
$p_end
$p_end
Definition: export_rec_csv.php:18
ATTR_DEF_ACCOUNT
const ATTR_DEF_ACCOUNT
Definition: constant.php:205
h
h( $row[ 'oa_description'])
Definition: ajax_anc_detail_operation.php:46
$ret
$ret
Definition: ajax_display_letter.php:51
Acc_Ledger_Sold\verify_operation
verify_operation($p_array)
verify that the data are correct before inserting or confirming
Definition: acc_ledger_sold.class.php:49
$e
$e
Definition: result_cat_card_summary.php:26
Periode
For the periode tables parm_periode and jrn_periode.
Definition: periode.class.php:32
ATTR_DEF_CP
const ATTR_DEF_CP
Definition: constant.php:214
Acc_Ledger\inc_seq_pj
inc_seq_pj()
increment the sequence for the pj
Definition: acc_ledger.class.php:1907
Acc_Ledger\get_name
get_name()
Return the name of a ledger.
Definition: acc_ledger.class.php:417
$max
$max
Definition: ajax_boxcard_search.php:40
$poste
$poste
Definition: lettering.account.inc.php:37
Operation_currency_SQL
ORM abstract of the table public.operation_currency.
Definition: operation_currency_sql.class.php:35
IPeriod
Generate the form for the periode Data Members.
Definition: iperiod.class.php:34
$tva_rate
catch(Exception $e) $tva_rate
Definition: ajax_tva_parameter.php:48
db
$SecUser db
Definition: export_security_pdf.php:118
INum
This class handles only the numeric input, the input will call a javascript to change comma to period...
Definition: inum.class.php:41
Acc_Ledger\check_payment
check_payment($e_mp, $e_mp_qcode)
check if the payment method is valid
Definition: acc_ledger.class.php:1871
Acc_Ledger_Sold\input
input($p_array=null, $p_readonly=0)
display the form for entering data for invoice,
Definition: acc_ledger_sold.class.php:1184
ITva_Popup
let you choose a TVA in a popup
Definition: itva_popup.class.php:43
Icon_Action\infobulle
static infobulle($p_comment)
Display a info in a bubble, text is in message_javascript.
Definition: icon_action.class.php:97
Acc_Ledger_Sold\get_detail_sale
get_detail_sale($p_from, $p_end, $p_filter_operation='all')
Retrieve data from the view v_detail_sale , gives all the row of an operation.
Definition: acc_ledger_sold.class.php:1524
IText
Html Input.
Definition: itext.class.php:29
$tot_amount
$tot_amount
Definition: acc_ledger_history_financial_oneline.php:44
$_POST
$_POST['ac']
Definition: do.php:360
HttpInput
manage the http input (get , post, request) and extract from an array
Definition: http_input.class.php:37
$fiche
$fiche
Definition: ajax_add_concerned_card.php:98
$currency
$currency
Definition: acc_currency_cfg.inc.php:35
Stock_Goods\insert_goods
static insert_goods(&$p_cn, $p_array)
Insert into stock_goods from ACH and VEN.
Definition: stock_goods.class.php:186
tr
tr($p_string, $p_extra='')
Definition: ac_common.php:88
Acc_Ledger_Sold\confirm
confirm($p_array, $p_summary=false)
show the summary of the operation and propose to save it
Definition: acc_ledger_sold.class.php:741
Pre_operation
manage the predefined operation, link to the table op_def and op_def_detail
Definition: pre_operation.class.php:30
create_script
create_script($p_string)
create the HTML for adding the script tags around of the script
Definition: function_javascript.php:38
check_parameter
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...
Definition: user_common.php:209
Acc_Tva
Acc_Tva is used for to map the table tva_rate parameter are.
Definition: acc_tva.class.php:36
$wLedger
$wLedger
Definition: compta_fin_rec.inc.php:223
Acc_Ledger
Class for jrn, class acc_ledger for manipulating the ledger.
Definition: acc_ledger.class.php:32
OPEN
const OPEN
Definition: constant.php:191
$str_code
$str_code
Definition: menu_detail.php:6
ISpan
Html Input.
Definition: ispan.class.php:31
Acc_Ledger_Sold\__construct
__construct($p_cn, $p_init)
Definition: acc_ledger_sold.class.php:38
Acc_Ledger\get_last_date
get_last_date()
get the date of the last operation
Definition: acc_ledger.class.php:1814
$prop
$prop
Definition: ajax_get_receipt.php:52
$a_poste
$a_poste
Definition: export_gl_pdf.php:66
Anc_Plan\hidden
static hidden($p_array)
return an HTML string containing hidden input type to hold the differant PA_ID
Definition: anc_plan.class.php:201
$sql
$sql
Definition: ajax_add_concerned_card.php:100
IDate
Html Input : Input a date format dd.mm.yyyy The property title should be set to indicate what it is e...
Definition: idate.class.php:33
IHidden
Html Input.
Definition: ihidden.class.php:30
Html_Input_Noalyss\ledger_add_item
static ledger_add_item($p_ledger)
Build a HTML string for adding multiple rows.
Definition: html_input_noalyss.class.php:42
Acc_Ledger\get_id
get_id($p_internal)
retrieve the jr_id thanks the internal code, do not change anything to the current object
Definition: acc_ledger.class.php:1829
$acompte
$acompte
Definition: compta_ven.inc.php:267
$jrn_type
$jrn_type[]
Definition: database.item.php:229
ATTR_DEF_TVA
const ATTR_DEF_TVA
Definition: constant.php:211
Acc_Compute
this class aims to compute different amount
Definition: acc_compute.class.php:55
Acc_Ledger\check_strict
check_strict()
Check if a Dossier is using the strict mode or not.
Definition: acc_ledger.class.php:1724
$sql_filter
$sql_filter
Definition: preod.inc.php:43
Acc_Ledger\is_closed
is_closed($p_periode)
check if the current ledger is closed
Definition: acc_ledger.class.php:1070
isDate
isDate($p_date)
Definition: ac_common.php:239
Acc_Ledger\select_ledger
select_ledger($p_type="ALL", $p_access=3, $enable=TRUE)
Show a select list of the ledgers you can access in writing, reading or simply accessing.
Definition: acc_ledger.class.php:526
Acc_Payment
Handle the table payment_method.
Definition: acc_payment.class.php:36
$periode
$periode
Definition: ajax_display_letter.php:48
sql_string
sql_string($p_string)
Fix the problem with the quote char for the database.
Definition: ac_common.php:504
jr_id
$op jr_id
Definition: ajax_ledger.php:87
$array
$array
Definition: ajax_add_concerned_card.php:115
Acc_Ledger\check_currency_setting
check_currency_setting($p_currency_code)
Check that the currency code does exist and the setting of the folder is correct.
Definition: acc_ledger.class.php:1754
id
$input_from id
Definition: balance.inc.php:63
Acc_Currency
display currency , convert to euro , and save them if used. The default currency has the id 0 and is ...
Definition: acc_currency.class.php:33
FICADD
const FICADD
Definition: constant.security.php:21
Acc_Ledger\CurrencyInput
CurrencyInput($p_currency_code, $p_currency_rate, $p_eur_amount)
Create a select from value for currency and add javascript to update $p_currency_rate and $p_eur_amou...
Definition: acc_ledger.class.php:3198
Acc_Ledger\compute_internal_code
compute_internal_code($p_grpt)
compute the internal code of the saved operation and set the $this->jr_internal to the computed value
Definition: acc_ledger.class.php:1263
Acc_Ledger_Sold\insert
insert($p_array=null)
insert into the database, it calls first the verify function, change the value of this->jr_id and thi...
Definition: acc_ledger_sold.class.php:244
Acc_Ledger\guess_pj
guess_pj()
guess what the next pj should be
Definition: acc_ledger.class.php:445
Acc_Ledger\check_periode
check_periode()
Check if a Dossier is using the check on the periode, if true than the user has to enter the date and...
Definition: acc_ledger.class.php:1739
$g_user
global $g_user
Find the default module or the first one.
Definition: action.inc.php:24
$p_jrn
$p_jrn
Definition: history_operation.inc.php:62
Acc_Ledger_Sold\extra_info
extra_info()
the function extra info allows to
Definition: acc_ledger_sold.class.php:1145
$value
$value
Definition: export_document.php:41
$file
$file
Definition: export_document_template.php:50
$i
$i
Definition: action_document_type_mtable_input.php:83
Acc_Operation
this file match the tables jrn & jrnx the purpose is to remove or save accountant writing to these ta...
Definition: acc_operation.class.php:33
Acc_Ledger_Fin
the class Acc_Ledger_Fin inherits from Acc_Ledger, this object permit to manage the financial ledger
Definition: acc_ledger_fin.class.php:35
Acc_Account_Ledger
Manage the account from the table jrn, jrnx or tmp_pcmn.
Definition: acc_account_ledger.class.php:27
$p_readonly
$p_readonly
Definition: category_detail.inc.php:50
Acc_Ledger\add_card
add_card($p_filter, $p_id_update)
Return a button to create new card, depending of the ledger.
Definition: acc_ledger.class.php:3146
Acc_Ledger\create_document
create_document($internal, $p_array)
create the invoice and saved it as attachment to the operation,
Definition: acc_ledger.class.php:1845
Acc_Reconciliation
new class for managing the reconciliation it must be used instead of the function InsertRapt,...
Definition: acc_reconciliation.class.php:32
Acc_Ledger_Sold\heading_detail_sale
static heading_detail_sale()
compute an array with the heading cells for the details, used for the export in CSV
Definition: acc_ledger_sold.class.php:1565
$label
$label
Definition: impress_jrn.inc.php:115
Anc_Plan
Concerns the Analytic plan (table plan_analytique)
Definition: anc_plan.class.php:32
isNumber
isNumber($p_int)
Definition: ac_common.php:218
$http
$http
Definition: action.common.inc.php:33
$date_limit
$date_limit
Definition: stock_state.inc.php:38
$url
$url
Definition: ajax_bookmark.php:66
Fiche
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: fiche.class.php:37
$jr_id
$jr_id
Definition: ajax_ledger.php:45
Acc_Ledger\check_currency
check_currency($p_qcode_payment, $p_currency_id)
When we write a record for the payment at the same time as a sale or a purchase, to have a bank saldo...
Definition: acc_ledger.class.php:1794
$obj
$obj
Definition: ajax_accounting.php:43
HtmlInput\post_to_hidden
static post_to_hidden($array)
transform $_POST data to hidden
Definition: html_input.class.php:655
$r
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
Definition: ajax_add_concerned_card.php:53
Acc_Ledger\select_depot
select_depot($p_readonly, $p_repo)
Let you select the repository before confirming a sale or a purchase.
Definition: acc_ledger.class.php:3068
$anc
$anc
Definition: ajax_anc_accounting.php:37
hb
hb($p_string)
Definition: ac_common.php:53
HtmlInput\show_receipt_document
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.
Definition: html_input.class.php:1101
$amount
$amount
Definition: ajax_anc_key_compute.php:40
$Res
$Res
Definition: export_security_pdf.php:117
Lettering
mother class for the lettering by account and by card use the tables jnt_letter, letter_deb and lette...
Definition: lettering.class.php:35
$ledger
$ledger
Definition: ajax_anc_key_choice.php:36
$repo
if(isset($_REQUEST['gDossier']) && $http->request("gDossier","number", 0) !=0) $repo
Definition: ajax_preference.php:47
ATTR_DEF_CITY
const ATTR_DEF_CITY
Definition: constant.php:219
Acc_Ledger\get_min_row
get_min_row()
Definition: acc_ledger.class.php:787
span
span($p_string, $p_extra='')
Definition: ac_common.php:43
Acc_Ledger_Sold
Handle the ledger of sold,.
Definition: acc_ledger_sold.class.php:36
ATTR_DEF_ADRESS
const ATTR_DEF_ADRESS
Definition: constant.php:213
$per
$per
Definition: stock_state.inc.php:36
$default_currency
$default_currency
Definition: operation_ods_new.inc.php:76
ICard
Input HTML for the card show buttons, in the file, you have to add card.js How to use :
Definition: icard.class.php:120
$j_id
$j_id
Definition: ajax_display_letter.php:35
$def
$def
show a form for quick_writing
Definition: compta_ods.inc.php:51
IFile
Html Input.
Definition: ifile.class.php:30
Acc_Ledger\$nb
$nb
!< type of the ledger ACH ODS FIN VEN or GL
Definition: acc_ledger.class.php:39
$g_parameter
global $g_parameter
Definition: acc_currency_cfg.inc.php:30
td
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
$min
$min
Definition: ajax_display_letter.php:89
ATTR_DEF_NAME
const ATTR_DEF_NAME
Definition: constant.php:206
$check_periode
$check_periode
Definition: company.inc.php:99
HtmlInput\hidden
static hidden($p_name, $p_value, $p_id="")
Definition: html_input.class.php:218
cmpDate
cmpDate($p_date, $p_date_oth)
Compare 2 dates.
Definition: ac_common.php:191
Anc_Operation
this class is used to show the form for entering an operation only FOR analytic operation to save it,...
Definition: anc_operation.class.php:32
$oPeriode
$oPeriode
Definition: do.php:204
$p_array
$p_array
Definition: ajax_view_mod_stock.php:33
$l
$l
Definition: export_fiche_detail_pdf.php:69
$op
$op
Definition: ajax_admin.php:37
ISelect
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
Definition: iselect.class.php:39
Acc_Ledger\$db
$db
!< jrn_def.jrn_def_id
Definition: acc_ledger.class.php:36
$seq
$seq
Definition: action_document_type_mtable_input.php:62
record_log
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1400
Acc_Ledger\display_negative_warning
display_negative_warning($p_amount)
If the amount is positive and the ledger expects a negative amount, il will return the saved warning.
Definition: acc_ledger.class.php:3241