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