noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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 * @class Acc_Ledger_Sale
32 * @brief : input, confirm and save new operations in edger of sales
33 the $_POST data is an array with these keys
34 @code
35 Array
36(
37
38// =====================
39// ANALYTIC PART
40// =====================
41 [pa_id] => Array
42 (
43 [0] => 1
44 )
45
46 [op] => Array
47 (
48 [0] => 0
49 )
50
51 [amount_t0] => 10
52 [hplan] => Array
53 (
54 [0] => Array
55 (
56 [0] => -1
57 )
58
59 )
60
61 [val] => Array
62 (
63 [0] => Array
64 (
65 [0] => 10
66 )
67
68 )
69// =====================
70// SALES DATA
71// =====================
72
73 [e_client] => QuickCode customer
74 [nb_item] => number of items (lines of invoice)
75 [p_jrn] => JRN_DEF.JRN_DEF_ID id of the ledger
76 [jrn_note_input] => Note JRN_NOTE.N_TEXT
77 [mt] => 1759130008.8134
78 [p_currency_rate] => Currency Rate
79 [p_currency_code] => Currency Code
80 [e_comm] => Description of invoice
81 [e_date] => date invoice
82 [e_ech] => limit date
83 [e_pj] => Receipt number
84 [e_pj_suggest] => suggested receipt number
85 [e_mp] => payment means (
86 [jrn_type] => Type of ledger (always VEN)
87 //---------------------------------------------
88 // For each invoice line
89 //---------------------------------------------
90 [e_march0] => QuickCode of the item
91 [e_march0_label] => label
92 [e_march0_price] => unit price
93 [e_march0_tva_id] => VAT ID
94 [e_march0_tva_amount] => amount of VAT
95 [e_quant0] => quantity of item
96//========================
97// MISC
98//========================
99 [repo] => 1 (repository)
100 [gen_invoice] => on (it is asked to generate an invoice
101 [gen_doc] => Document template id
102 [bon_comm] => JRN_INFO.
103 [other_info] = JRN_INFO.>
104 [opd_name] => Name of operation template
105 [od_description] => Description of operation template
106 [reverse_date] => if reverse is asked
107 [ext_label] => Label for revese operation
108 [jr_optype] => Type of operation NOR:Normal,, EXT; reverse, ..
109)
110 @endcode
111
112 */
113
115
116 function __construct($p_cn, $p_init) {
117 parent::__construct($p_cn, $p_init);
118 $this->ledger_type = 'VEN';
119 }
120
121 /*!\brief verify that the data are correct before inserting or confirming
122 * \param an array (usually $_POST)
123 * \return String
124 * \throw Exception if an error occurs
125 */
126 public function verify_operation($p_array) {
127 global $g_parameter, $g_user;
128
129 if (is_array($p_array ) == false || empty($p_array))
130 throw new Exception ("Array empty");
131
132 extract($p_array, EXTR_SKIP);
133
134 /*
135 * Check needed value
136 */
137 check_parameter($p_array,'p_jrn,e_date,e_client');
138
139 /* check for a double reload */
140 if (isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1', array($mt)) != 0)
141 throw new Exception(_('Double Encodage'), 5);
142
143 /* check if we can write into this ledger */
144 if ($g_user->check_jrn($p_jrn) != 'W')
145 throw new Exception(_('Accès interdit'), 20);
146
147 /* check if there is a customer */
148 if (noalyss_strlentrim($e_client) == 0)
149 throw new Exception(_('Vous n\'avez pas donné de client'), 11);
150
151 /* check if the date is valid */
152 if (isDate($e_date) == null) {
153 throw new Exception(_('Date invalide'), 2);
154 }
155
156 $oPeriode = new Periode($this->db);
157 if ($this->check_periode() == true && isset($p_array['period'])) {
158 $tperiode = $period;
159 /* check that the datum is in the choosen periode */
160 $oPeriode->p_id = $period;
161 list ($min, $max) = $oPeriode->get_date_limit();
162
163 if (cmpDate($e_date, $min) < 0 ||
164 cmpDate($e_date, $max) > 0)
165 throw new Exception(_('Date et periode ne correspondent pas'), 6);
166 }
167 else {
168 $per = new Periode($this->db);
169 $tperiode = $per->find_periode($e_date);
170 }
171
172 /* check if the periode is closed */
173 if ($this->is_closed($tperiode) == 1) {
174 throw new Exception(_('Periode fermee'), 6);
175 }
176 /* check if we are using the strict mode */
177 if ($this->check_strict() == true) {
178 /* if we use the strict mode, we get the date of the last
179 operation */
180 $last_date = $this->get_last_date();
181 if ($last_date != null && cmpDate($e_date, $last_date) < 0)
182 throw new Exception(_('Vous utilisez le mode strict la dernière operation est date du ')
183 . $last_date . _(' vous ne pouvez pas encoder à une date antérieure'), 13);
184 }
185
186
187 $fiche = new Fiche($this->db);
188 $fiche->get_by_qcode($e_client);
189
190 if ($fiche->get_f_enable() == '0')
191 throw new Exception(sprintf(_("La fiche %s n'est plus utilisée"),$e_client), 50);
192
193 if ($fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
194 throw new Exception(_('La fiche ') . $e_client . _('n\'a pas de poste comptable'), 8);
195
196
197
198 /* get the account and explode if necessary */
199 $sposte = $fiche->get_attribute(ATTR_DEF_ACCOUNT);
200 // if 2 accounts, take only the debit one for customer
201 if (strpos($sposte, ',') != 0) {
202 $array = explode(',', $sposte);
203 $poste_val = $array[0];
204 } else {
205 $poste_val = $sposte;
206 }
207 /* The account exists */
208
209 $poste = new Acc_Account_Ledger($this->db, $poste_val);
210
211 if ($poste->load() == false) {
212 throw new Exception(_('Pour la fiche ') . $e_client . _(' le poste comptable [') . $poste->id . _('] n\'existe pas'), 9);
213 }
214
215 /* Check if the card belong to the ledger */
216 $fiche = new Fiche($this->db);
217 $fiche->get_by_qcode($e_client, 'deb');
218 if ($fiche->belong_ledger($p_jrn) != 1)
219 throw new Exception(_('La fiche ') . $e_client . _('n\'est pas accessible à ce journal'), 10);
220
221 $nb = 0;
222
223 //----------------------------------------
224 // foreach item
225 //----------------------------------------
226 for ($i = 0; $i < $nb_item; $i++) {
227 if (! isset (${'e_march' . $i}) || noalyss_strlentrim(${'e_march' . $i}) == 0)
228 continue;
229 /* check if all card has a ATTR_DEF_ACCOUNT */
230 $fiche = new Fiche($this->db);
231 $fiche->get_by_qcode(${'e_march' . $i});
232 if ($fiche->get_f_enable() == '0')
233 throw new Exception(sprintf(_("La fiche %s n'est plus utilisée"), ${'e_march' . $i}), 50);
234
235
236 /* check if amount are numeric and */
237 if (isNumber(${'e_march' . $i . '_price'}) == 0)
238 throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a un montant invalide [') . ${'e_march' . $i} . ']', 6);
239 if (isNumber(${'e_quant' . $i}) == 0)
240 throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a une quantité invalide [') . ${'e_quant' . $i} . ']', 7);
241
242 if ($fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
243 throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('n\'a pas de poste comptable'), 8);
244
245 // Check if the given tva id is valid
246 if ($g_parameter->MY_TVA_USE == 'Y') {
247 $tva_rate = Acc_Tva::build($this->db,${'e_march' . $i . '_tva_id'});
248 $tva_rate->load();
249 if ($tva_rate->tva_id === -1 )
250 throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('a un code tva invalide') . ' [' . ${'e_march' . $i . '_tva_id'} . ']', 13);
251
252 $tva_rate->load();
253 /*
254 * check if the accounting for VAT are valid
255 */
256 $a_poste = explode(',', $tva_rate->tva_poste);
257
258 if (
259
260 $this->db->get_value('select count(*) from tmp_pcmn where pcm_val=$1', array($a_poste[1])) == 0)
261 throw new Exception(_(" La TVA " . $tva_rate->tva_label . " utilise des postes comptables inexistants"));
262 }
263 // if 2 accounts, take only the credit one
264 /* The account exists */
265 $sposte = $fiche->get_attribute(ATTR_DEF_ACCOUNT);
266
267 if (strpos($sposte, ',') != 0) {
268 $array = explode(',', $sposte);
269 $poste_val = $array[1];
270 } else {
271 $poste_val = $sposte;
272 }
273 $poste = new Acc_Account_Ledger($this->db, $poste_val);
274 if ($poste->load() == false) {
275 throw new Exception(_('Pour la fiche ') . ${'e_march' . $i} . _(' le poste comptable [') . $poste->id . _('n\'existe pas'), 9);
276 }
277 /* Check if the card belong to the ledger */
278 $fiche = new Fiche($this->db);
279 $fiche->get_by_qcode(${'e_march' . $i});
280 if ($fiche->belong_ledger($p_jrn, 'cred') != 1)
281 throw new Exception(_('La fiche ') . ${'e_march' . $i} . _('n\'est pas accessible à ce journal'), 10);
282
283 if ( ${"e_quant".$i} != 0 && trim(${"e_quant".$i}) !="" ) {$nb++;}
284
285 }
286 if ($nb == 0)
287 throw new Exception(_('Il n\'y a aucune marchandise'), 12);
288 //------------------------------------------------------
289 // The "Paid By" check
290 //------------------------------------------------------
291
292 if ($e_mp != 0) {
293 $this->check_payment($e_mp, ${"e_mp_qcode_" . $e_mp});
294 // check for the currency , if we use a financial ledger and a card which is a bank account (with his own
295 // ledger , then the currency of the operation must be the same
296 $this->check_currency(${"e_mp_qcode_" . $e_mp},$p_currency_code);
297 }
298
299
300
301
302 //
303 // Check payment date
304 if ( isset ($mp_date) && trim ($mp_date) != "" && isDate($mp_date) == null) {
305 throw new Exception(_('Date de paiement invalide'),13);
306
307 }
308
309 // check that MP is in a not closed and exists
310 if ( isset ($mp_date) && trim ($mp_date) != "" && isDate($mp_date) == $mp_date ) {
311 $periode=new Periode($this->cn);
312 $periode->find_periode($mp_date);
313 $periode->set_ledger($this->id);
314 if ( $periode->is_closed() ) {
315 throw new Exception(_("Période fermée")." $mp_date ");
316 }
317
318 }
319 // check limit date
320 if ( isset ($e_ech) && trim ($e_ech)!="" && isDate($e_ech) == null )
321 {
322 throw new Exception(_('Date échéance invalide'),14);
323
324 }
325 // Check currency_rate if valid
326 if ( isNumber($p_currency_rate) == 0 || $p_currency_rate <=0 ) {
327 throw new Exception(_('Taux devise invalide'),15);
328 }
329 $this->check_currency_setting($p_currency_code);
330 }
331
332 /*!
333 * \brief insert into the database, it calls first the verify function,
334 * store the value of the inserted operation in $this->jr_id and this->jr_internal
335 *
336 * It generates the document if gen_invoice is set and save the middle of payment if any ($e_mp)
337 *
338 * It also create a second operation if there is a payment
339 *
340 * \param $p_array is usually $_POST or a predefined operation
341 * \return string : internal number
342 * \note throw an Exception
343 */
344
345 public function insert($p_array = null) {
346 global $g_parameter,$g_user;
347 // load ledger definition
348 $this->load();
349 extract($p_array, EXTR_SKIP);
350 $this->verify($p_array);
351
352 $group = $this->db->get_next_seq("s_oa_group"); /* for analytic */
353 $seq = $this->db->get_next_seq('s_grpt');
354 $this->id = $p_jrn;
355 $internal = $this->compute_internal_code($seq);
356 $this->jr_internal = $internal;
357
358 $oPeriode = new Periode($this->db);
359 $check_periode = $this->check_periode();
360
361 if ($check_periode == true && isset($p_array['period']))
362 $tperiode = $period;
363 else
364 $tperiode = $oPeriode->find_periode($e_date);
365
366 $cust = new Fiche($this->db);
367 $cust->get_by_qcode($e_client);
368 $sposte = $cust->get_attribute(ATTR_DEF_ACCOUNT);
369
370 // if 2 accounts, take only the debit one for the customer
371 //
372 if (strpos($sposte, ',') != 0) {
373 $array = explode(',', $sposte);
374 $poste = $array[0];
375 } else {
376 $poste = $sposte;
377 }
378
379 bcscale(4);
380 try {
381 // variable : $tot_amount : total amount of the sales (credit)
382 $tot_amount = 0;
383 // variable : $tot_tva : total amount of the VAT
384 $tot_tva = 0;
385 // tot debit if item's amount < 0
386 $tot_debit = 0;
387 // variable : $tot_amount_cur : total amount in currency
388 $tot_amount_cur=0;
389
390 $this->db->start();
391 // variable : $tva array that will contain all the VAT Amount
392 $tva = array();
393 // variable : $tva_reverse array that contain all the VAT autoreverse AND negative
394 $tva_reverse = array();
395
396 // find the currency from v_currency_last_value
397 // variable : $currency_rate_ref Acc_Currency , currency object for this operation
398 $currency_rate_ref=new Acc_Currency($this->db, $p_currency_code);
399
400 /* Save all the items without vat */
401 for ($i = 0; $i < $nb_item; $i++) {
402 // variable : $n_both float auto-reverse amount
403 $n_both = 0;
404 if ( empty(${'e_march'.$i}) || empty(${'e_quant'.$i}) ) continue;
405
406 /* First we save all the items without vat */
407 $fiche = new Fiche($this->db);
408 $fiche->get_by_qcode(${"e_march" . $i});
409 $amount_currency = bcmul(${'e_march' . $i . '_price'}, ${'e_quant' . $i});
410
411 // convert amount to currency
412 $amount=bcdiv($amount_currency,$p_currency_rate);
413
415 $tot_amount = round($tot_amount, 2);
416 $acc_operation = new Acc_Operation($this->db);
417 $acc_operation->date = $e_date;
418 $sposte = $fiche->get_attribute(ATTR_DEF_ACCOUNT);
419
420 // if 2 accounts, take only the credit one
421 if (strpos($sposte, ',') != 0) {
422 $array = explode(',', $sposte);
423 $poste_val = $array[1];
424 } else {
425 $poste_val = $sposte;
426 }
427
428 $acc_operation->poste = $poste_val;
429 $acc_operation->amount = $amount;
430 $acc_operation->grpt = $seq;
431 $acc_operation->jrn = $p_jrn;
432 $acc_operation->type = 'c';
433 $acc_operation->periode = $tperiode;
434 if ($g_parameter->MY_UPDLAB=='Y')
435 {
436 $acc_operation->desc=strip_tags(${"e_march".$i."_label"});
437 }
438 else
439 {
440 $acc_operation->desc=null;
441 }
442
443 $acc_operation->qcode = ${"e_march" . $i};
444 if ($amount<0)
445 {
446 $tot_debit=round(bcadd($tot_debit, abs($amount)),2);
447 }
448
449 $j_id = $acc_operation->insert_jrnx();
450
451 if ($g_parameter->MY_TVA_USE == 'Y') {
452 /* Compute sum vat */
453 $oTva = Acc_Tva::build($this->db, trim(${'e_march' . $i . '_tva_id'}));
454 $idx_tva =$oTva->get_parameter("id");
455 // variable : $auto_reverse = if the oTVA autoreverse, fetch it once for this item,
456 $auto_reverse=$oTva->get_parameter("both_side");
457
458 $tva_item_currency = ${'e_march' . $i . '_tva_amount'};
459
460 /* if empty then we need to compute it */
461 if (trim($tva_item_currency) == '' || ${'e_march'.$i.'_tva_amount'} == 0) {
462 $tva_item_currency = bcmul($amount, $oTva->get_parameter('rate'));
463 $tva_item=round($tva_item_currency,2);
464 }
465 $tva_item=bcdiv($tva_item_currency,$p_currency_rate);
466 $tva_item=round($tva_item,2);
467
468 $tva[$idx_tva]=(isset($tva[$idx_tva]))?$tva[$idx_tva]:0;
469
470 if ( $auto_reverse == 0)
471 {
472 $tva[$idx_tva]=bcadd($tva_item,$tva[$idx_tva]);
473 $tva[$idx_tva]=round($tva[$idx_tva],2);
474 $tot_tva = bcadd($tva_item, $tot_tva);
475 $tot_tva = round($tot_tva, 2);
476 }
477 else
478 {
479 $n_both = $tva_item;
480 $tva_item_currency = 0;
481 if ($n_both<0)
482 {
483 $tot_debit=round(bcadd($tot_debit, abs($n_both)),2);
484 $tva_reverse[$idx_tva]=(isset($tva_reverse[$idx_tva]))?$tva_reverse[$idx_tva]:0;
485 $tva_reverse[$idx_tva]=bcadd($tva_item,$tva_reverse[$idx_tva]);
486 $tva_reverse[$idx_tva]=round($tva_reverse[$idx_tva],2);
487
488 } else {
489 $tva[$idx_tva]=bcadd($tva_item,$tva[$idx_tva]);
490 $tva[$idx_tva]=round($tva[$idx_tva],2);
491
492 }
493 }
494 }
495
496 /* Save the stock */
497 /* if the quantity is < 0 then the stock increase (return of
498 * material)
499 */
500 $nNeg = (${"e_quant" . $i} < 0) ? -1 : 1;
501
502 // always save quantity but in withStock we can find
503 // what card need a stock management
504 if ($g_parameter->MY_STOCK = 'Y' && isset($repo))
505 {
506 $dir=(${'e_quant'.$i} < 0 ) ? 'd':'c';
507 Stock_Goods::insert_goods($this->db, array('j_id' => $j_id, 'goods' => ${'e_march' . $i}, 'quant' => $nNeg * ${'e_quant' . $i}, 'dir' => $dir, 'repo' => $repo));
508 }
509
510
511 if ($g_parameter->MY_ANALYTIC != "nu" && $g_parameter->match_analytic($poste_val)) {
512 // for each item, insert into operation_analytique */
513 $op = new Anc_Operation($this->db);
514 $op->set_currency_rate($p_currency_rate);
515 $op->oa_group = $group;
516 $op->j_id = $j_id;
517 $op->oa_date = $e_date;
518 $op->oa_debit = 'f';
519 $op->oa_description = sql_string($e_comm);
520 $op->save_form_plan($_POST, $i, $j_id);
521 }
522 if (empty( ${'e_march' . $i . '_price'} ) ) ${'e_march' . $i . '_price'} = 0;
523 if (empty( ${'e_march' . $i } ) ) ${'e_march' . $i } = 0;
524 if (empty( ${'e_quant' . $i } ) ) ${'e_quant' . $i } = 0;
525
526 $price_euro=bcdiv(${'e_march'.$i.'_price'}, $p_currency_rate);
527
528 if ($g_parameter->MY_TVA_USE == 'Y') {
529 /* save into quant_sold */
530 $r = $this->db->exec_sql("select insert_quant_sold ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)", array(null, /* 1 */
531 $j_id, /* 2 */
532 ${'e_march' . $i}, /* 3 */
533 ${'e_quant' . $i}, /* 4 */
534 round($amount, 2), /* 5 */
535 $tva_item, /* 6 */
536 $oTva->get_parameter("id"), /* 7 */
537 $e_client, /* 8 */
538 $n_both, /* 9 */
539 $price_euro/* Price /unit */
540 ));
541 } else {
542 $tva_item_currency=0;
543
544 $r = $this->db->exec_sql("select insert_quant_sold ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10) ", array(null, /* 1 */
545 $j_id, /* 2 */
546 ${'e_march' . $i}, /* 3 */
547 ${'e_quant' . $i}, /* 4 */
548 $amount, // 5
549 0,
550 null,
551 $e_client,
552 0, /* 9 */
553 $price_euro /* Price /unit */
554 ));
555 } // if ( $g_parameter->MY_TVA_USE=='Y') {
556 /*
557 * Insert also in operation_currency
558 */
559 $operation_currency=new Operation_currency_SQL($this->db);
560 $operation_currency->oc_amount=$amount_currency;
561 $operation_currency->oc_vat_amount=$tva_item_currency;
562 $operation_currency->oc_price_unit=${'e_march'.$i.'_price'};
563 $operation_currency->j_id=$j_id;
564 $operation_currency->insert();
565 $tot_amount_cur=round(bcadd($tot_amount_cur,$amount_currency,4),4);
566 $tot_amount_cur=round(bcadd($tot_amount_cur,$tva_item_currency,4),4);
567 }// end loop : save all items
568
569 /*** save other tax ****/
570 if ( $this->has_other_tax() && isset($p_array['other_tax'])) {
571 $row=$this->db->get_row("select ac_id,ac_label,ac_accounting
572 from acc_other_tax
573 where ac_id=$1 ",
574 [$p_array['other_tax']]);
575 if ( ! empty ($row )) {
576 $other_tax_amount=bcmul($p_array['other_tax_amount'],$p_currency_rate);
577 $acc_operation=new Acc_Operation($this->db);
578 $acc_operation->date=$e_date;
579 $acc_operation->poste=$row['ac_accounting'];
580 $acc_operation->amount=$other_tax_amount;
581 $acc_operation->grpt=$seq;
582 $acc_operation->jrn=$p_jrn;
583 $acc_operation->type='c';
584 $acc_operation->periode=$tperiode;
585 $acc_operation->desc=$row['ac_label'];
586 $jrn_tax_sql=new Jrn_Tax_SQL($this->db);
587 $jrn_tax_sql->j_id=$acc_operation->insert_jrnx();
588 $jrn_tax_sql->ac_id=$row['ac_id'];
589 $jrn_tax_sql->pcm_val=$row['ac_accounting'];
590 $jrn_tax_sql->insert();
592 if ( $p_array['other_tax_amount'] < 0 ) {
593 $tot_debit=bcadd($tot_debit,abs($other_tax_amount));
594 }
595 $operation_currency=new Operation_currency_SQL($this->db);
596 $operation_currency->oc_amount=$p_array['other_tax_amount'];
597 $operation_currency->oc_vat_amount=0;
598 $operation_currency->oc_price_unit=0;
599 $operation_currency->j_id=$jrn_tax_sql->j_id;
600 $operation_currency->insert();
601 }
602
603 }
604
605
606 /* save total customer */
607 $cust_amount = bcadd($tot_amount, $tot_tva);
608 $cust_amount = round($cust_amount,2);
609 if ( DEBUGNOALYSS > 1 ) {
610 echo __LINE__." cust_amount $cust_amount<br>";
611 echo __LINE__." tot_amount $tot_amount<br>";
612 echo __LINE__." tot_tva $tot_tva<br>";
613
614 }
615
616 $acc_operation = new Acc_Operation($this->db);
617 $acc_operation->date = $e_date;
618 $acc_operation->poste = $poste;
619 $acc_operation->amount = $cust_amount;
620 $acc_operation->grpt = $seq;
621 $acc_operation->jrn = $p_jrn;
622 $acc_operation->type = 'd';
623 $acc_operation->periode = $tperiode;
624 $acc_operation->qcode = ${"e_client"};
625 if ($cust_amount>0)
626 {
627 $tot_debit=bcadd($tot_debit, $cust_amount);
628 $tot_debit=round($tot_debit, 2);
629 }
630 $let_tiers = $acc_operation->insert_jrnx();
631
632 // --- insert also the currency amount for the customer
633 $operation_currency=new Operation_currency_SQL($this->db);
634 $operation_currency->oc_amount=$tot_amount_cur;
635 $operation_currency->oc_vat_amount=0;
636 $operation_currency->oc_price_unit=0;
637 $operation_currency->j_id=$let_tiers ;
638 $operation_currency->insert();
639
640
641 /**************************************************************************************************
642 * save all vat
643 * $i contains the tva_id and value contains the vat amount
644 * if if ($g_parameter->MY_TVA_USE == 'Y' )
645 ************************************************************************************************** */
646 if ($g_parameter->MY_TVA_USE == 'Y') {
647
648 foreach ($tva as $i => $value) {
649 $oTva = Acc_Tva::build($this->db,$i);
650 $poste_vat = $oTva->get_side('c');
651
652 $cust_amount = bcadd($tot_amount, $tot_tva);
653 $acc_operation = new Acc_Operation($this->db);
654 $acc_operation->date = $e_date;
655 $acc_operation->poste = $poste_vat;
656 $acc_operation->amount = $value;
657 $acc_operation->grpt = $seq;
658 $acc_operation->jrn = $p_jrn;
659 $acc_operation->type = 'c';
660 $acc_operation->periode = $tperiode;
661 if ($value<0)
662 {
663 $tot_debit=bcadd($tot_debit, abs($value));
664 $tot_debit=round($tot_debit, 2);
665 }
666 if ( $oTva->get_parameter("both_side") == 1 && $value ==0 ) continue;
667 $acc_operation->insert_jrnx();
668
669 // if TVA is on both side, we deduce it immediately
670 if ($oTva->get_parameter("both_side") == 1 ) {
671 // $x temp variable is the tva_reverse_account and will be used to check $poste_vat
672 $x=$oTva->get_parameter("tva_reverse_account");
673
674 $poste_vat =(trim($x??"")=="")? $oTva->get_side('d'):$x;
675 if ($poste_vat == '#') $poste_vat=$oTva->get_side('c');
676 $cust_amount = bcadd($tot_amount, $tot_tva);
677 $acc_operation = new Acc_Operation($this->db);
678 $acc_operation->date = $e_date;
679 $acc_operation->poste = $poste_vat;
680 $acc_operation->amount = $value;
681 $acc_operation->grpt = $seq;
682 $acc_operation->jrn = $p_jrn;
683 $acc_operation->type = 'd';
684 $acc_operation->periode = $tperiode;
685 $acc_operation->insert_jrnx();
686 $tot_debit = bcadd($tot_debit, $value);
687 $tot_debit = round($tot_debit, 2);
688 $n_both = $value;
689 }
690
691 }
692 foreach ($tva_reverse as $i => $value) {
693 $oTva = Acc_Tva::build($this->db,$i);
694 $poste_vat = $oTva->get_side('c');
695 if ( $poste_vat == '#')
696 {
697 $poste_vat=$oTva->get_side('d');
698 }
699
700 $acc_operation = new Acc_Operation($this->db);
701 $acc_operation->date = $e_date;
702 $acc_operation->poste = $poste_vat;
703 $acc_operation->amount = $value;
704 $acc_operation->grpt = $seq;
705 $acc_operation->jrn = $p_jrn;
706 $acc_operation->type = 'c';
707 $acc_operation->periode = $tperiode;
708 if ($value<0)
709 {
710 $tot_debit=bcadd($tot_debit, abs($value));
711 $tot_debit=round($tot_debit, 2);
712 }
713 $acc_operation->insert_jrnx();
714
715 // if TVA is on both side, we deduce it immediately
716 $poste_vat = $oTva->get_side('d');
717 if ( $poste_vat == '#')
718 {
719 $poste_vat=$oTva->get_side('c');
720 }
721 $acc_operation = new Acc_Operation($this->db);
722 $acc_operation->date = $e_date;
723 $acc_operation->poste = $poste_vat;
724 $acc_operation->amount = $value;
725 $acc_operation->grpt = $seq;
726 $acc_operation->jrn = $p_jrn;
727 $acc_operation->type = 'd';
728 $acc_operation->periode = $tperiode;
729 $acc_operation->insert_jrnx();
730 $tot_debit = bcadd($tot_debit, $value);
731 $tot_debit = round($tot_debit, 2);
732 $n_both = $value;
733
734 }
735
736 } // if ($g_parameter->MY_TVA_USE=='Y')
737 /*
738 * Balance the amount on D and C , the difference must be inserted as "difference due to a rounded value"
739 * Value are retrieve thanks $seq
740 */
741
742 /* insert into jrn */
743 if ( DEBUGNOALYSS > 1 ) { echo __LINE__." tot_debit ".round($tot_debit,2)."<br>"; }
744 $acc_operation = new Acc_Operation($this->db);
745 $acc_operation->date = $e_date;
746 $acc_operation->echeance = $e_ech;
747 $acc_operation->amount = abs(round($tot_debit, 2));
748 $acc_operation->desc = $e_comm;
749 $acc_operation->grpt = $seq;
750 $acc_operation->jrn = $p_jrn;
751 $acc_operation->periode = $tperiode;
752 $acc_operation->pj = $e_pj;
753 $acc_operation->mt = $mt;
754 $acc_operation->currency_id=$p_currency_code;
755 $acc_operation->currency_rate=$p_currency_rate;
756 $acc_operation->currency_rate_ref=$currency_rate_ref->get_rate();
757
758 if ( ! $this->jr_id=$acc_operation->insert_jrn() ) {
759 throw new Exception (_("Erreur de balance"),EXC_BALANCE);
760 }
761
762 $this->pj = $acc_operation->update_receipt();
763
764 /**
765 *
766 * if the given receipt number is equal to one computed then increment
767 */
768 if ($e_pj == $this->pj && noalyss_strlentrim($e_pj) != 0) {
769 $this->inc_seq_pj();
770 }
771 $this->db->exec_sql("update jrn set jr_internal=$1 where jr_grpt_id = $2" ,[$internal,$seq]);
772
773
774 /* update quant_sold */
775 $this->db->exec_sql('update quant_sold set qs_internal = $1
776 where j_id in (select j_id from jrnx where j_grpt=$2)'
777 , array($internal, $seq));
778
779
780 //----------------------------------------
781 // Save the payer
782 //----------------------------------------
783 if ($e_mp != 0) {
784 /**
785 * Date
786 */
787 $pay_date=($mp_date=="")?$e_date:$mp_date;
788
789 /* mp */
790 $mp = new Acc_Payment($this->db, $e_mp);
791 $mp->load();
792
793
794 /* jrnx */
795 $acseq = $this->db->get_next_seq('s_grpt');
796 $acjrn = new Acc_Ledger($this->db, $mp->get_parameter('ledger_target'));
797 $acinternal = $acjrn->compute_internal_code($acseq);
798
799 /*
800 * for the use of the card of the bank
801 */
802 if ( $acjrn->get_type()=='FIN') {
803 $acjrn=new Acc_Ledger_Fin($this->db, $mp->get_parameter('ledger_target'));
804 $acfiche=new Fiche($this->db,$acjrn->get_bank());
805 $fqcode=$acfiche->get_attribute(ATTR_DEF_QUICKCODE);
806 } else {
807 $fqcode = ${'e_mp_qcode_' . $e_mp};
808 $acfiche = new Fiche($this->db);
809 $acfiche->get_by_qcode($fqcode);
810 }
811
812 /* Insert paid by */
813 $acc_pay = new Acc_Operation($this->db);
814 $acc_pay->date = $pay_date;
815 /* get the account and explode if necessary */
816 $sposte = $acfiche->get_attribute(ATTR_DEF_ACCOUNT);
817 // if 2 accounts, take only the debit one for customer
818 if (strpos($sposte, ',') != 0) {
819 $array = explode(',', $sposte);
820 $poste_val = $array[0];
821 } else {
822 $poste_val = $sposte;
823 }
824 // Convert paid amount in EUR
825 $acompte_eur=bcdiv($acompte, $p_currency_rate);
826
827 $famount=bcsub($cust_amount,$acompte_eur);
828 $acc_pay->poste = $poste_val;
829 $acc_pay->qcode = $fqcode;
830 $acc_pay->amount = abs(round($famount, 2));
831 $acc_pay->desc = null;
832
833 $acc_pay->grpt = $acseq;
834 $acc_pay->jrn = $mp->get_parameter('ledger_target');
835 $acc_pay->periode = $tperiode;
836 $acc_pay->type = ($famount >= 0) ? 'd' : 'c';
837 $let_pay=$acc_pay->insert_jrnx();
838
839 /* Insert supplier */
840 $acc_pay = new Acc_Operation($this->db);
841 $acc_pay->date = $pay_date;
842 $acc_pay->poste = $poste;
843 $acc_pay->qcode = $e_client;
844 $acc_pay->amount = abs(round($famount, 2));
845 $acc_pay->desc = null;
846 $acc_pay->grpt = $acseq;
847 $acc_pay->jrn = $mp->get_parameter('ledger_target');
848 $acc_pay->periode = $tperiode;
849 $acc_pay->type = ($famount >= 0) ? 'c' : 'd';
850 $let_other = $acc_pay->insert_jrnx();
851
852 // insert into operation_currency customer
853 $operation_currency=new Operation_currency_SQL($this->db);
854 $operation_currency->oc_amount=bcsub($tot_amount_cur,$acompte);
855 $operation_currency->oc_vat_amount=0;
856 $operation_currency->oc_price_unit=0;
857 $operation_currency->j_id=$let_other;
858 $operation_currency->insert();
859
860 // insert into operation_currency bank
861 $operation_currency=new Operation_currency_SQL($this->db);
862 $operation_currency->oc_amount=bcsub($tot_amount_cur,$acompte);
863 $operation_currency->oc_vat_amount=0;
864 $operation_currency->oc_price_unit=0;
865 $operation_currency->j_id=$let_pay;
866 $operation_currency->insert();
867
868 // Add info for currency
869 $acc_pay->currency_id=$p_currency_code;
870 $acc_pay->currency_rate=$p_currency_rate;
871 $acc_pay->currency_rate_ref=$currency_rate_ref->get_rate();
872
873
874 /* insert into jrn */
875 $acc_pay->mt = $mt;
876 $acjrn->jr_grpt_id = $acseq;
877 $acc_pay->desc = (!isset($e_comm_paiement) || noalyss_strlentrim($e_comm_paiement) == 0) ? $e_comm : $e_comm_paiement;
878 $mp_jr_id = $acc_pay->insert_jrn();
879 $acjrn->update_internal_code($acinternal);
880 // add an automatic PJ if ODS
881 if ($acjrn->get_type()=="ODS") {
882 $acc_pay->pj=$acjrn->guess_pj();
883 $acc_pay->update_receipt();
884 }
885 $r1 = $this->get_id($internal);
886 $r2 = $this->get_id($acinternal);
887
888 /*
889 * add lettering
890 */
891 $oletter = new Lettering($this->db);
892 $oletter->insert_couple($let_tiers, $let_other);
893
894
895 /* set the flag paid */
896 $Res = $this->db->exec_sql("update jrn set jr_rapt='paid' where jr_id=$1", array($r1));
897
898 /* Reconcialiation */
899 $rec = new Acc_Reconciliation($this->db);
900 $rec->set_jr_id($r1);
901 $rec->insert($r2);
902
903
904 /*
905 * save also into quant_fin
906 */
907
908 /* get ledger property */
909 $ledger = new Acc_Ledger_Fin($this->db, $acc_pay->jrn);
910 $prop = $ledger->get_propertie();
911
912 /* if ledger is FIN then insert into quant_fin */
913 if ($prop['jrn_def_type'] == 'FIN') {
914 $ledger->insert_quant_fin($acfiche->id, $mp_jr_id, $cust->id, bcmul($famount, 1),$let_other);
915 }
916 }
917 /*----------------------------------------------
918 * Save the note
919 ----------------------------------------------*/
920 if (isset($p_array['jrn_note_input']) && !empty($p_array['jrn_note_input'])) {
921 $acc_operation_note=Acc_Operation_Note::build_jrn_id(-1);
922 $acc_operation_note->setNote($p_array['jrn_note_input']);
923 $acc_operation_note->setOperation_id( $this->jr_id);
924 $acc_operation_note->save();
925 }
926 } catch (Exception $e) {
927 record_log($e);
928 $this->db->rollback();
929 throw $e;
930 }
931 $this->db->commit();
932
933 return $internal;
934 }
935
936 /*!
937 * @brief show the summary of the operation and propose to save it
938 * @param array contains normally $_POST. It proposes also to save
939 * the Analytic accountancy
940 * @param $p_summary false for the feedback, true to show the summary
941 * @return string
942 *
943 */
944
945 function confirm($p_array, $p_summary = false) {
946 global $g_parameter,$g_user;
947 extract($p_array, EXTR_SKIP);
948 if ( !isset($p_array['jrn_note_input'])) {$p_array['jrn_note_input']='';}
949 // don't need to verify for a summary
950 if (!$p_summary)
951 {
952 $this->verify($p_array);
953 }
954 $anc = null;
955 // to show a select list for the analytic & VAT USE
956 // if analytic is op (optionnel) there is a blank line
957
958 bcscale(4);
959 $client = new Fiche($this->db);
960 $client->get_by_qcode($e_client, true);
961
962 $client_name = $client->getName() .
963 ' ' . $client->get_attribute(ATTR_DEF_ADRESS) . ' ' .
964 $client->get_attribute(ATTR_DEF_POSTCODE) . ' ' .
965 $client->get_attribute(ATTR_DEF_CITY);
966 $lPeriode = new Periode($this->db);
967 if ($this->check_periode() == true) {
968 $lPeriode->p_id = $period;
969 } else {
970 $lPeriode->find_periode($e_date);
971 }
972 $date_limit = $lPeriode->get_date_limit();
973 $r = "";
974 $r .= '<div id="summary_op1" >';
975 $r.='<TABLE>';
976 if ( $p_summary ) {
977 $jr_id=$this->db->get_value('select jr_id from jrn where jr_internal=$1',array($this->jr_internal));
978 $r.="<tr>";
979 $r.='<td>';
980 $r.=_('Détail opération ');
981 $r.='</td>';
982 $r.='<td>';
983 $r.=sprintf ('<a class="line" style="display:inline" href="javascript:modifyOperation(%d,%d)">%s</a>',
984 $jr_id,dossier::id(),$this->jr_internal);
985 $r.='</td>';
986 $r.="</tr>";
987 }
988 $r.='<tr>';
990 if ( ! $p_summary) {
991 $r.='<td>' . _('Numéro Pièce') .$span.'</td><td>'. hb($e_pj) . '</td>';
992 } else {
993 if ( $g_parameter->MY_PJ_SUGGEST=="A" ||$g_user->check_action(UPDRECEIPT)==0)
994 $e_pj=$this->pj;
995 if ( strcmp($this->pj,$e_pj) != 0 )
996 {
997 $r.='<td>' . _('Numéro Pièce') .$span.'</td><td>'. hb($this->pj) .
998 '<span class="notice"> '._('Attention numéro pièce existante, elle a du être adaptée').'</span></td>';
999 } else {
1000 $r.='<td>' . _('Numéro Pièce') .$span.'</td><td>'. hb($this->pj) . '</td>';
1001 }
1002 }
1003 $e_comm=($e_comm == "")?_('Facture')." $e_pj":$e_comm;
1004 $r.='</tr>';
1005 $r.='<tr>';
1006 $r.='<td> ' . _('Date') . '</td><td> ' . hb($e_date) . '</td>';
1007 $r.='</tr>';
1008 $r.='<tr>';
1009 $r.='<td>' . _('Echeance') . '</td><td> ' . hb($e_ech) . '</td>';
1010 $r.='</tr>';
1011 $r.='<tr>';
1012 $r.='<td> ' . _('Période Comptable') . '</td><td> ' .hb( $date_limit['p_start'] . '-' . $date_limit['p_end']) . '</td>';
1013 $r.='</tr>';
1014 $r.='</table>';
1015 $r.='</div>';
1016 $r .= '<div id="summary_op2">';
1017 $r.='<table>';
1018 $r.='<tr>';
1019 $r.='<td> ' . _('Journal') . '</td><td> ' . hb($this->get_name()) . '</td>';
1020 $r.='</tr>';
1021 $r.='<tr>';
1022 $r.='<td> ' . _('Libellé') . '</td><td> ' . hb($e_comm) . '</td>';
1023 $r.='</tr>';
1024
1025 $r.='<tr>';
1026 $r.='<td> ' . _('Client') . '</td><td> ' . HtmlInput::card_detail($e_client).":".hb( $client_name) . '</td>';
1027 $r.='</tr>';
1028 $r.='</table>';
1029 $r.='<div>'._('Note').'<div id="jrn_note_td">'.$p_array['jrn_note_input'].'</div></div>';
1030 $r.='</div>';
1031 $r.='<div style="float:none;clear:both">';
1032 $r.='</div>';
1033
1034 $r.='<h2 class="h-section" class="h-section">' . _('Détail articles vendus') . '</h2>';
1035 $r.='<p class="decale">';
1036 $r.='<table class="result" >';
1037 $r.='<TR>';
1038 $r.="<th>" . _('Code') . "</th>";
1039 $r.="<th>" . _('Dénomination') . "</th>";
1040 $r.="<th style=\"text-align:right\">" . _('prix') . "</th>";
1041 $r.="<th style=\"text-align:right\">" . _('quantité') . "</th>";
1042
1043
1044 if ($g_parameter->MY_TVA_USE == 'Y') {
1045 $r.="<th style=\"text-align:right\">" . _('tva') . "</th>";
1046 $r.='<th style="text-align:right"> ' . _('Montant TVA') . '</th>';
1047 $r.='<th style="text-align:right">' . _('Montant HTVA') . '</th>';
1048 $r.='<th style="text-align:right">' . _('Montant TVAC') . '</th>';
1049 } else {
1050 $r.='<th style="text-align:right">' . _('Montant') . '</th>';
1051 }
1052 /* if we use the AC */
1053 if ($g_parameter->MY_ANALYTIC != 'nu') {
1054 $anc = new Anc_Plan($this->db);
1055 $a_anc = $anc->get_list();
1056 $x = count($a_anc);
1057 /* set the width of the col */
1058 $r.='<th colspan="' . $x . '">' . _('Compt. Analytique') . '</th>';
1059
1060 /* add hidden variables pa[] to hold the value of pa_id */
1061 $r.=Anc_Plan::hidden($a_anc);
1062 }
1063 $r.='</tr>';
1064 $tot_amount = 0.0;
1065 $tot_tva = 0.0;
1066 for ($i = 0; $i < $nb_item; $i++) {
1067 if (noalyss_strlentrim(${"e_march" . $i}) == 0)
1068 continue;
1069
1070 /* retrieve information for card */
1071 $fiche = new Fiche($this->db);
1072 $fiche->get_by_qcode(${"e_march" . $i});
1073 if ($g_parameter->MY_UPDLAB == 'Y')
1074 $fiche_name = h(${"e_march" . $i . "_label"});
1075 else
1076 $fiche_name = $fiche->get_attribute(ATTR_DEF_NAME);
1077 if ($g_parameter->MY_TVA_USE == 'Y') {
1078 $idx_tva = ${"e_march" . $i . "_tva_id"};
1079 $oTva = Acc_Tva::build($this->db,$idx_tva);
1080 $oTva->load();
1081 }
1082 $op = new Acc_Compute();
1083 $amount = bcmul(${"e_march" . $i . "_price"}, ${'e_quant' . $i});
1084 $op->set_parameter("amount", $amount);
1085 if ($g_parameter->MY_TVA_USE == 'Y') {
1086 $op->set_parameter('amount_vat_rate', $oTva->get_parameter('rate'));
1087 $op->compute_vat();
1088 $tva_computed = $op->get_parameter('amount_vat');
1089 $tva_item = ${"e_march" . $i . "_tva_amount"};
1090 if (isset($tva[$idx_tva]))
1091 $tva[$idx_tva]=bcadd($tva[$idx_tva],$tva_item,2);
1092 else
1093 $tva[$idx_tva] = $tva_item;
1094 $tot_tva = round(bcadd($tva_item, $tot_tva), 2);
1095 }
1096 $tot_amount = round(bcadd($tot_amount, $amount), 2);
1097
1098 $r.='<tr>';
1099 $r.='<td>';
1100 $r.=${"e_march" . $i};
1101 $r.='</td>';
1102 $r.='<TD style="border-bottom:1px dotted grey;">';
1103 $r.=$fiche_name;
1104 $r.='</td>';
1105 $r.='<td class="num">';
1106 $r.=nbm(${"e_march" . $i . "_price"},4);
1107 $r.='</td>';
1108 $r.='<td class="num">';
1109 $r.=nbm(${"e_quant" . $i},4);
1110 $r.='</td>';
1111 $both_side=0;
1112 if ($g_parameter->MY_TVA_USE == 'Y') {
1113 $r.='<td class="num">';
1114 $r.=$oTva->get_parameter('label');
1115 $r.='</td>';
1116 $both_side=$oTva->get_parameter("both_side");
1117 /* warning if tva_computed and given are not the
1118 same */
1119 if (bcsub($tva_item, $tva_computed) != 0 && ! ($tva_item == 0 && $both_side == 1)) {
1120 $r.='<td style="background-color:red" class="num">';
1122 $r.='<a href="#" class="error" style="display:inline" title="' . _("Attention Différence entre TVA calculée et donnée") . '">'
1123 . nbm($tva_item) . '<a>';
1124 } else {
1125 $r.='<td class="num">';
1126 $r.=nbm($tva_item);
1127 }
1128 $r.='</td>';
1129 $r.='<td class="num">';
1130 $r.=nbm($amount);
1131 $r.='</td>';
1132 $tot_row = bcadd($tva_item, $amount);
1133 $r.=td(nbm($tot_row), 'class="num"');
1134 } else {
1135 $r.='<td class="num">';
1136 $r.=nbm($amount);
1137 $r.='</td>';
1138 }
1139 // encode the pa
1140 if ($g_parameter->MY_ANALYTIC != 'nu'
1141 && $g_parameter->match_analytic($fiche->get_attribute(ATTR_DEF_ACCOUNT))==TRUE) { // use of AA
1142 // show form
1143 $anc_op = new Anc_Operation($this->db);
1144 $null = ($g_parameter->MY_ANALYTIC == 'op') ? 1 : 0;
1145 $r.='<td>';
1146 $p_mode = ($p_summary == false) ? 1 : 0;
1147 $p_array['pa_id'] = $a_anc;
1148 /* op is the operation it contains either a sequence or a jrnx.j_id */
1149 $r.=HtmlInput::hidden('op[]=', $i);
1150 $r.=$anc_op->display_form_plan($p_array, $null, $p_mode, $i, round($amount,2));
1151 $r.='</td>';
1152 }
1153
1154
1155 $r.='</tr>';
1156 } // end loop item
1157 //
1158 // Add the sum
1159 $decalage=($g_parameter->MY_TVA_USE == 'Y')?'<td></td><td></td><td></td><td></td>':'<td></td>';
1160 $tot = bcadd($tot_amount, $tot_tva, 2);
1161 $tot_eur=round(bcdiv($tot, $p_currency_rate),2);
1162 $tot_str=nbm($tot);
1163 $str_tot=_('Totaux');
1164
1165 // Get currency code
1166 $default_currency=new Acc_Currency($this->db,0);
1167 $str_code=$default_currency->get_code();
1168 if ( $p_currency_code != 0 ) {
1169 $acc_currency=new Acc_Currency($this->db);
1170 $acc_currency->set_id($p_currency_code);
1171 $str_code=$acc_currency->get_code();
1172 }
1173 // Format amount
1175 $tot_tva=nbm($tot_tva);
1176 $rate=_("Taux ");
1177if ( $g_parameter->MY_TVA_USE=="Y") {
1178 $r.=<<<EOF
1179 <tr class="highlight">
1180 {$decalage}
1181 <td>
1182 {$str_tot} {$str_code}
1183 </td>
1184 <td class="num">
1185 {$tot_tva}
1186 </td>
1187 <td class="num">
1188 {$tot_amount}
1189 </td>
1190 <td class="num">
1191 {$tot_str} {$str_code}
1192 </td>
1193 </tr>
1194EOF;
1195 if ($p_currency_code !=0) {
1196 $sql_currency=new Currency_SQL($this->cn,0);
1197 $iso_code=$sql_currency->getp("cr_code_iso");
1198
1199 $r.=<<<EOF
1200 <tr class="highlight">
1201 {$decalage}
1202 <td>
1203
1204 </td>
1205 <td class="num">
1206
1207 </td>
1208 <td class="num">
1209 {$rate} {$p_currency_rate}
1210 </td>
1211 <td class="num">
1212 {$tot_eur} {$iso_code}
1213 </td>
1214 </tr>
1215EOF;
1216 }
1217
1218 } else {
1219 $sql_currency=new Currency_SQL($this->cn,$p_currency_code);
1220 $str_code=$sql_currency->getp("cr_code_iso");
1221 $sql_currencydefault=new Currency_SQL($this->cn,0);
1222 $iso_code=$sql_currencydefault->getp("cr_code_iso");
1223 // without VAT
1224 $r.=<<<EOF
1225 <tr class="highlight">
1226 {$decalage}
1227 <td>
1228 {$str_tot} {$str_code}
1229 </td>
1230 <td class="num">
1231
1232 </td>
1233 <td class="num">
1234
1235 </td>
1236 <td class="num">
1237 {$tot_str} {$str_code}
1238 </td>
1239 </tr>
1240 <tr class="highlight">
1241 {$decalage}
1242 <td>
1243 </td>
1244 <td>
1245
1246 </td>
1247 <td>
1248 {$rate} {$p_currency_rate}
1249 </td>
1250 <td class="num">
1251 {$tot_eur} {$iso_code}
1252 </td>
1253 </tr>
1254EOF;
1255 }
1256 $r.='</table>';
1257 $r.='</p>';
1258 if ($g_parameter->MY_ANALYTIC != 'nu' && ! $p_summary) // use of AA
1259 $r.='<input type="button" class="button" value="' . _('Vérifiez Imputation Analytique') . '" onClick="verify_ca(\'\');">';
1260 $r.='<div id="total_div_id" >';
1261 $r.='<h2 class="h-section">Totaux</h2>';
1262 $other_tax_label="";
1264 if ( $this->has_other_tax() && isset($p_array['other_tax'])) {
1265 $other_tax_label=_("Autre taxe");
1266 $other_tax_amount=htmlspecialchars($p_array['other_tax_amount']);
1267 }
1268 /* use VAT */
1269 if ($g_parameter->MY_TVA_USE == 'Y') {
1270 $r.='<table>';
1271 $r.='<tr><td>Total HTVA</td>';
1272 $r.=td(hb($tot_amount ),'class="num"');
1273 foreach ($tva as $i => $value) {
1274 $oTva=Acc_Tva::build($this->cn, $i);
1275 $oTva->load();
1276
1277 $r.='<tr><td> TVA ' . $oTva->get_parameter('label').'</td>';
1278 $r.=td(hb(nbm($tva[$i])),'class="num"');
1279 }
1280 $r.='<tr>'.td(_('Total TVA')).td(hb($tot_tva),'class="num"');
1281 if ( ! empty($other_tax_label) ) {
1282 $r.='<tr>'.td($other_tax_label).td(hb($other_tax_amount),'class="num"');
1283 }
1284 if ( $other_tax_amount!="") {$tot=bcadd($tot,$other_tax_amount,2);}
1285 $r.='<tr>'.td(_('Total TVAC')).td(hb($tot),'class="num"');
1286 $r.='</table>';
1287 } else {
1288 if ( ! empty($other_tax_label) ) {
1289 $r.='<tr>'.td($other_tax_label).td(hb($other_tax_amount),'class="num"');
1290 }
1291 if ( $other_tax_amount!="") {$tot=bcadd($tot,$other_tax_amount,2);}
1292 $r.='<br>Total '.hb($tot);
1293 }
1294 $r.='</div>';
1295
1296
1297 /* Add hidden */
1298 $r.=HtmlInput::hidden('e_client', $e_client);
1299 $r.=HtmlInput::hidden('nb_item', $nb_item);
1300 $r.=HtmlInput::hidden('p_jrn', $p_jrn);
1301 $r.=HtmlInput::hidden('jrn_note_input',h($p_array['jrn_note_input']));
1302 $mt = microtime(true);
1303 $r.=HtmlInput::hidden('mt', $mt);
1304 $r.=HtmlInput::post_to_hidden(['p_currency_rate','p_currency_code']);
1305
1306 if (isset($period))
1307 {
1308 $r.=HtmlInput::hidden('period', $period);
1309 }
1310 /* \todo comment les types hidden gérent ils des contenus avec des quotes, double quote ou < > ??? */
1311 $r.=HtmlInput::hidden('e_comm', $e_comm);
1312 $r.=HtmlInput::hidden('e_date', $e_date);
1313 $r.=HtmlInput::hidden('e_ech', $e_ech);
1314 $r.=HtmlInput::hidden('e_pj', $e_pj);
1315 $r.=HtmlInput::hidden('e_pj_suggest', $e_pj_suggest);
1316 if ( $this->has_other_tax() && isset($p_array["other_tax"])) {
1317 $r.=HtmlInput::hidden("other_tax",$p_array['other_tax']);
1318 $r.=HtmlInput::hidden("other_tax_amount",$p_array['other_tax_amount']);
1319 }
1320 $e_mp = (isset($e_mp)) ? $e_mp : 0;
1321 $r.=HtmlInput::hidden('e_mp', $e_mp);
1322
1323 if ( isset($repo) ) {
1324 // Show the available repository
1325 $r.= $this->select_depot($p_summary,$repo);
1326 }
1327
1328 /* if the paymethod is not 0 and if a quick code is given */
1329 if ($e_mp != 0 && noalyss_strlentrim(${'e_mp_qcode_' . $e_mp}) != 0) {
1330 $r.=HtmlInput::hidden('e_mp_qcode_' . $e_mp, ${'e_mp_qcode_' . $e_mp});
1331 $r.=HtmlInput::hidden('acompte', $acompte);
1332 $r.=HtmlInput::hidden('e_comm_paiement', $e_comm_paiement);
1333 /* needed for generating a invoice */
1334 $r.=HtmlInput::hidden('qcode_benef', ${'e_mp_qcode_' . $e_mp});
1335 $r.=HtmlInput::hidden('mp_date', ${'mp_date'});
1336
1337 $fname = new Fiche($this->db);
1338 $fname->get_by_qcode(${'e_mp_qcode_' . $e_mp});
1339 $r.='<h2 class="h-section">' . "Payé par " . ${'e_mp_qcode_' . $e_mp} .
1340 " le ".${"mp_date"}.
1341 " " . $fname->getName() . '</h2> ' . '<p class="decale">' . _('Déduction acompte ') . h($acompte) . '</p>' .
1342 _('Libellé :') . h($e_comm_paiement) ;
1343 $r.='<br>';
1344 }
1345
1346 $r.=HtmlInput::hidden('jrn_type', $jrn_type);
1347 for ($i = 0; $i < $nb_item; $i++) {
1348 $r.=HtmlInput::hidden("e_march" . $i, ${"e_march" . $i});
1349 if (isset(${"e_march" . $i . "_label"}))
1350 $r.=HtmlInput::hidden("e_march" . $i . "_label", ${"e_march" . $i . "_label"});
1351 $r.=HtmlInput::hidden("e_march" . $i . "_price", ${"e_march" . $i . "_price"});
1352 if ($g_parameter->MY_TVA_USE == 'Y') {
1353 $r.=HtmlInput::hidden("e_march" . $i . "_tva_id", ${"e_march" . $i . "_tva_id"});
1354 $r.=HtmlInput::hidden("e_march" . $i . "_tva_amount", ${"e_march" . $i . "_tva_amount"});
1355 }
1356 $r.=HtmlInput::hidden("e_quant" . $i, ${"e_quant" . $i});
1357 }
1358 /*
1359 * warning if the amount is positive and expecting a negative one
1360 */
1361 $negative=$this->display_negative_warning($tot);
1362 if ( $negative != "") {
1363 $r.=span($negative,'class="warning" ');
1364 }
1365 return $r;
1366 }
1367
1368 /*!
1369 * \brief the function extra info allows to
1370 * - add a attachment
1371 * - generate an invoice
1372 * - insert extra info
1373 * \return string
1374 */
1375
1376 public function extra_info() {
1377 $r = '<div id="facturation_div_id" style="display:flex;height:185px;height:10rem">';
1378 // check for upload piece
1379 $file = new IFile();
1380 $file->table = 0;
1381 $file->setAlertOnSize(true);
1382 $r.='<p class="decale">';
1383
1384 // add a receipt
1385 $r.=_("Ajoutez une pièce justificative ");
1386 $r.=$file->input("pj", "");
1387
1388 //------------------------------------------------
1389 // Propose to generate an invoice
1390 //------------------------------------------------
1391 $r.=_('ou générer une facture') . ' <input type="checkbox" name="gen_invoice" CHECKED>';
1392 // We propose to generate the invoice and some template
1393 $doc_gen = new ISelect();
1394 $doc_gen->name = "gen_doc";
1395 $doc_gen->value = $this->db->make_array(
1396 "select md_id,md_name " .
1397 " from document_modele where md_affect='VEN' ".
1398 " union select -2,'"._("Z - Facture PDF Standard")."' ".
1399 " order by 2");
1400 $r.=$doc_gen->input() . '<br>';
1402
1403 $r.='<br>';
1404 $obj = new IText();
1405 $r.=_('Numero de bon de commande') . $obj->input('bon_comm') . '<br>';
1406 $r.=_('Communication') . $obj->input('other_info') . '<br>';
1407 $r.='</p>';
1408 $r.='</div>';
1409 return $r;
1410 }
1411
1412
1413
1414 /*!\brief display the form for entering data for invoice,
1415 * \param $p_array is null or you can put the predef operation or the $_POST
1416 *
1417 * \return HTML string
1418 */
1419
1420 function input($p_array = null, $p_readonly = 0) {
1421 global $g_parameter, $g_user;
1422 // load ledger definition
1423 $this->load();
1424 $http=new HttpInput();
1425 $http->set_array([]);
1426 if ($p_array != null) {
1427 extract($p_array, EXTR_SKIP);
1428 $http->set_array($p_array);
1429 }
1430 if ( !isset($p_array['jrn_note_input'])) {$p_array['jrn_note_input']='';}
1431 $flag_tva = $g_parameter->MY_TVA_USE;
1432 /* Add button */
1433
1434 $str_add_button_tiers = "";
1435 $add_card=FALSE;
1436 if ($g_user->check_action(FICADD) == 1) {
1437 $add_card=TRUE;
1438 $str_add_button_tiers = $this->add_card("deb", "e_client");
1439 }
1440
1441 // The first day of the periode
1442 $oPeriode = new Periode($this->db);
1443 list ($l_date_start, $l_date_end) = $oPeriode->get_date_limit($g_user->get_periode());
1444 if ($g_parameter->MY_DATE_SUGGEST == 'Y')
1445 $op_date = (!isset($e_date) ) ? $l_date_start : $e_date;
1446 else
1447 $op_date = (!isset($e_date) ) ? '' : $e_date;
1448
1449 $e_ech = (isset($e_ech)) ? $e_ech : "";
1450 $e_comm = (isset($e_comm)) ? $e_comm : "";
1451
1452 $r = '';
1453 $r.=dossier::hidden();
1454 $f_legend = _('Client');
1455
1456 $Echeance = new IDate();
1457 $Echeance->setReadOnly(false);
1458
1459 $Echeance->tabindex = 2;
1461 $f_echeance = $Echeance->input('e_ech', $e_ech, _('Echéance') . $label);
1462 $Date = new IDate();
1463 $Date->setReadOnly(false);
1464
1465 $f_date = $Date->input("e_date", $op_date);
1466
1467 $f_periode = '';
1468 // Periode
1469 //--
1470 if ($this->check_periode() == true) {
1471 $l_user_per = $g_user->get_periode();
1472 $def = (isset($periode)) ? $periode : $l_user_per;
1473
1474 $period = new IPeriod("period");
1475 $period->user = $g_user;
1476 $period->cn = $this->db;
1477 $period->value = $def;
1478 $period->type = OPEN;
1479 try {
1480 $l_form_per = $period->input();
1481 } catch (Exception $e) {
1482 if ($e->getCode() == 1) {
1483 throw new Exception( _("Aucune période ouverte") );
1484 }
1485 }
1487 $f_periode = '<td>' . _("Période comptable") . "</td> <td> $label " . $l_form_per . '</td>';
1488 }
1489 /* if we suggest the next pj, then we need a javascript */
1490 $add_js = "";
1491 if ($g_parameter->MY_PJ_SUGGEST != 'N') {
1492 $add_js = "update_receipt();";
1493 }
1494 if ($g_parameter->MY_DATE_SUGGEST == 'Y') {
1495 $add_js.='get_last_date();';
1496 }
1497 $add_js.='update_name();';
1498 $add_js.='update_pay_method();';
1499 $add_js.='update_row("sold_item");';
1500 $add_js.='update_other_tax();';
1501 $add_js.='update_visibility_quantity();';
1502
1503 $wLedger = $this->select_ledger('VEN', 2,FALSE);
1504 if ($wLedger == null)
1505 throw new Exception(_('Pas de journal disponible'));
1506 $wLedger->table = 0;
1507 $wLedger->javascript = "onChange='update_predef(\"ven\",\"f\",\"".$_REQUEST['ac']."\");$add_js'";
1508 $wLedger->label = " Journal " . Icon_Action::infobulle(2);
1509
1510 $f_jrn = $wLedger->input();
1511
1512 $Commentaire = new IText();
1513 $Commentaire->table = 0;
1514 $Commentaire->setReadOnly(false);
1515 $Commentaire->size = (empty($e_comm))?60:strlen($e_comm)+5;
1516 $Commentaire->size = ($Commentaire->size<60)?60:$Commentaire->size;
1517 $Commentaire->tabindex = 3;
1518
1520
1521 $f_desc = $Commentaire->input("e_comm", $e_comm) ;
1522 // PJ
1523 //--
1524 /* suggest PJ ? */
1525 $default_pj = '';
1526 if ($g_parameter->MY_PJ_SUGGEST != 'N') {
1527 $default_pj = $this->guess_pj();
1528 }
1529
1530 $pj = new IText();
1531 if ( $g_parameter->MY_PJ_SUGGEST=='A'||$g_user->check_action(UPDRECEIPT)==0)
1532 {
1533 $pj->setReadOnly(true);
1534 $pj->id="e_pj";
1535 }
1536
1537 $pj->table = 0;
1538 $pj->name = "e_pj";
1539 $pj->size = 10;
1540 $pj->value = (isset($e_pj)) ? $e_pj : $default_pj;
1541 $f_pj = $pj->input() . HtmlInput::hidden('e_pj_suggest', $default_pj);
1542 // Display the customer
1543 //--
1544 $fiche = 'deb';
1545
1546 // Save old value and set a new one
1547 //--
1548 $e_client = ( isset($e_client) ) ? $e_client : "";
1549 $e_client_label = "&nbsp;"; //str_pad("",100,".");
1550 // retrieve e_client_label
1551 //--
1552
1553 if (noalyss_strlentrim($e_client) != 0) {
1554 $fClient = new Fiche($this->db);
1555 $fClient->get_by_qcode($e_client);
1556 $e_client_label = $fClient->get_attribute(ATTR_DEF_NAME) . ' ' .
1557 ' Adresse : ' . $fClient->get_attribute(ATTR_DEF_ADRESS) . ' ' .
1558 $fClient->get_attribute(ATTR_DEF_POSTCODE) . ' ' .
1559 $fClient->get_attribute(ATTR_DEF_CITY) . ' ';
1560 }
1561
1562 $W1 = new ICard();
1563 $W1->label = "Client " . Icon_Action::infobulle(0);
1564 $W1->name = "e_client";
1565 $W1->tabindex = 3;
1566 $W1->value = $e_client;
1567 $W1->table = 0;
1568 $W1->set_dblclick("fill_ipopcard(this);");
1569 $W1->set_attribute('ipopup', 'ipopcard');
1570
1571 // name of the field to update with the name of the card
1572 $W1->set_attribute('label', 'e_client_label');
1573 // name of the field to update with the name of the card
1574 $W1->set_attribute('typecard', 'deb');
1575
1576 // Add the callback function to filter the card on the jrn
1577 $W1->set_callback('filter_card');
1578 $W1->set_function('fill_data');
1579 $W1->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', $W1->name);
1580 $f_client_qcode = $W1->input();
1581 $client_label = new ISpan();
1582 $client_label->table = 0;
1583 $f_client = $client_label->input("e_client_label", $e_client_label);
1584 $f_client_bt = $W1->search();
1585
1586
1587 // Record the current number of article
1588 $Hid = new IHidden();
1589 $p_article = ( isset($nb_item)) ? $nb_item : $this->get_min_row();
1590 $r.=$Hid->input("nb_item", $p_article);
1591 $p_article = ($p_article < $this->get_min_row()) ? $this->get_min_row() : $p_article;
1592
1593
1594 $f_legend_detail = _("Détail articles vendus");
1595
1596 // For each article
1597 //--
1598 for ($i = 0; $i < $p_article; $i++) {
1599 // Code id, price & vat code
1600 //--
1601 $march = (isset(${"e_march$i"})) ? ${"e_march$i"} : "";
1602 $march_price = (isset(${"e_march" . $i . "_price"})) ? ${"e_march" . $i . "_price"} : "" ;
1603 if ($flag_tva == 'Y') {
1604 $march_tva_id = (isset(${"e_march$i" . "_tva_id"})) ? ${"e_march$i" . "_tva_id"} : "";
1605 $march_tva_amount = (isset(${"e_march$i" . "_tva_amount"})) ? ${"e_march$i" . "_tva_amount"} : "";
1606 }
1607 $march_label = (isset(${"e_march" . $i . "_label"})) ? ${"e_march" . $i . "_label"} : "";
1608
1609 // retrieve the tva label and name
1610 //--
1611 if (noalyss_strlentrim($march) != 0 && noalyss_strlentrim($march_label) == 0) {
1612 $fMarch = new Fiche($this->db);
1613 $fMarch->get_by_qcode($march);
1614 $march_label = $fMarch->get_attribute(ATTR_DEF_NAME);
1615 if ($flag_tva == 'Y') {
1616 if (!(isset(${"e_march$i" . "_tva_id"})))
1617 $march_tva_id = $fMarch->get_attribute(ATTR_DEF_TVA);
1618 }
1619 }
1620 // Show input
1621 //--
1622 $W1 = new ICard();
1623 $W1->label = "";
1624 $W1->name = "e_march" . $i;
1625 $W1->value = $march;
1626 $W1->table = 0;
1627 $W1->setAfter_clean("compute_all_ledger()");
1628 $W1->set_attribute('typecard', 'cred');
1629 $W1->set_dblclick("fill_ipopcard(this);");
1630 $W1->set_attribute('ipopup', 'ipopcard');
1631
1632 // name of the field to update with the name of the card
1633 $W1->set_attribute('label', 'e_march' . $i . '_label');
1634 // name of the field with the price
1635 $W1->set_attribute('price', 'e_march' . $i . '_price');
1636 // name of the field with the TVA_ID
1637 $W1->set_attribute('tvaid', 'e_march' . $i . '_tva_id');
1638 // Add the callback function to filter the card on the jrn
1639 $W1->set_callback('filter_card');
1640 $W1->set_function('fill_data');
1641 $W1->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', $W1->name);
1642
1643 $W1->readonly = false;
1644
1645 $array[$i]['quick_code'] = $W1->input();
1646 $array[$i]['bt'] = $W1->search();
1647 $array[$i]['card_add']=($add_card==TRUE)?$this->add_card("cred", $W1->id):"";
1648 // For computing we need some hidden field for holding the value
1649 $array[$i]['hidden'] = '';
1650 if ($flag_tva == 'Y')
1651 $array[$i]['hidden'].=HtmlInput::hidden('tva_march' . $i, 0);
1652
1653 $htva = new INum('htva_march' . $i);
1654 $htva->readOnly = 1;
1655 $htva->value = 0;
1656 $array[$i]['htva'] = $htva->input();
1657
1658 if ($g_parameter->MY_TVA_USE == 'Y')
1659 $tvac = new INum('tvac_march' . $i);
1660 else
1661 $tvac = new IHidden('tvac_march' . $i);
1662
1663 $tvac->readOnly = 1;
1664 $tvac->value = 0;
1665 $array[$i]['tvac'] = $tvac->input();
1666
1667 if ( $g_parameter->MY_UPDLAB == 'Y')
1668 {
1669 $Span=new IText("e_march".$i."_label");
1670 $Span->style='class="input_text label_item"';
1671 } else
1672 {
1673 $Span=new ISpan("e_march".$i."_label");
1674 $Span->extra='class="label_item"';
1675 }
1676 $Span->value = $march_label;
1677 $Span->setReadOnly(false);
1678 // card's name, price
1679 //--
1680 $array[$i]['denom'] = $Span->input("e_march" . $i . "_label", $march_label);
1681 // price
1682 $Price = new INum();
1683 $Price->setReadOnly(false);
1684 $Price->size = 9;
1685 $Price->javascript = "onblur=\"format_number(this,4);clean_tva($i);compute_ledger($i)\"";
1686 $array[$i]['pu'] = $Price->input("e_march" . $i . "_price", $march_price);
1687 $array[$i]['tva'] = '';
1688 $array[$i]['amount_tva'] = '';
1689 // if tva is not needed then no tva field
1690 if ($flag_tva == 'Y') {
1691 // vat label
1692 //--
1693 $Tva = new ITva_Popup($this->db);
1694 $Tva->id="e_march$i"."_tva_id";
1695 $Tva->in_table = true;
1696 $Tva->set_attribute('compute', $i);
1697 $Tva->set_filter("sale");
1698
1699 $Tva->js = 'onblur="clean_tva(' . $i . ');compute_ledger(' . $i . ')"';
1700 $Tva->value = $march_tva_id;
1701 $array[$i]['tva'] = $Tva->input("e_march$i" . "_tva_id");
1702 // vat amount
1703 //--
1704 $wTva_amount = new INum();
1705 $wTva_amount->readOnly = false;
1706 $wTva_amount->size = 6;
1707 $wTva_amount->javascript = "onblur='format_number(this);compute_ledger($i)'";
1708 $array[$i]['amount_tva'] = $wTva_amount->input("e_march" . $i . "_tva_amount", $march_tva_amount);
1709 }
1710 // quantity
1711 //--
1712 $quant = (isset(${"e_quant$i"})) ? ${"e_quant$i"} : "1";
1713 $Quantity = new INum();
1714
1715 $Quantity->setReadOnly(false);
1716 $Quantity->size = 8;
1717 $Quantity->javascript = "onchange=\"format_number(this,2);clean_tva($i);compute_ledger($i);\"";
1718 $array[$i]['quantity'] = $Quantity->input("e_quant" . $i, $quant);
1719 }// foreach article
1720 $f_type = _('Client');
1721
1722 // Currency
1723 $currency_select = $this->CurrencyInput("currency_code", "p_currency_rate" , "p_currency_euro");
1724 $currency_select->selected=$http->extract('p_currency_code','string',0);
1725
1726 $currency_input=new INum("p_currency_rate");
1727 $currency_input->id="p_currency_rate";
1728 $currency_input->prec=8;
1729 $currency_input->value=$http->extract('p_currency_rate','string',1);
1730 $currency_input->javascript='onchange="format_number(this,4);CurrencyCompute(\'p_currency_rate\',\'p_currency_euro\');"';
1731
1732 $currency=new Acc_Currency($this->db,0);
1733
1734 //
1735 // Button for template operation
1736 //
1737 ob_start();
1738 echo '<div id="predef_form">';
1739 echo HtmlInput::hidden('p_jrn_predef', $this->id);
1740 $op=new Pre_operation($this->db);
1741 $op->set_jrn_type("VEN");
1742 $op->set_p_jrn($this->id);
1743 $op->set_od_direct('f');
1744 $url=http_build_query(array('p_jrn_predef'=>$this->id, 'ac'=>$http->request('ac'),
1745 'gDossier'=>dossier::id()));
1746 echo $op->form_get('do.php?'.$url);
1747 echo '</div>';
1748 $str_op_template=ob_get_contents();
1749 ob_end_clean();
1750
1751 ob_start();
1752 require_once NOALYSS_TEMPLATE.'/form_ledger_detail.php';
1753 $form_ledger_detail=ob_get_contents();
1754 ob_end_clean();
1755
1756 $r.=$form_ledger_detail;
1757
1758 // Set correctly the REQUEST param for jrn_type
1759 $r.=HtmlInput::hidden('jrn_type', 'VEN');
1761 $r.= create_script("$('" . $Date->id . "').focus()");
1762 $r.='<div id="additional_tax_div">';
1763 $r.=$this->input_additional_tax();
1764 $r.='</div>';
1765 return $r;
1766 }
1767 /**
1768 * Retrieve data from the view v_detail_sale , gives all the row of an operation
1769 *
1770 * @remark $g_user connected user
1771 * @param $p_from jrn.jr_tech_per from
1772 * @param type $p_end jrn.jr_tech_per to
1773 * @param $p_filter_operation valid option : all, paid, unpaid
1774 * @return type
1775 */
1776 function get_detail_sale($p_from,$p_end,$p_filter_operation='all')
1777 {
1778 global $g_user;
1779 // Journal valide
1780 if ( $this->id == 0 ) die (__FILE__.":".__LINE__." Journal invalide");
1781
1782 // Securite
1783 if ( $g_user->get_ledger_access($this->id) == 'X' ) return null;
1784
1785 switch ( $p_filter_operation)
1786 {
1787 case 'all':
1788 $sql_filter="";
1789 break;
1790 case 'paid':
1791 $sql_filter=" and (jr_date_paid is not null or jr_rapt ='paid' ) ";
1792 break;
1793 case 'unpaid':
1794 $sql_filter=" and (jr_date_paid is null and coalesce(jr_rapt,'x') <> 'paid' ) ";
1795 break;
1796 default:
1797 throw new Exception(_("Filtre invalide",5));
1798
1799 }
1800 // get the data from the view
1801 $sql = "select *
1802 from v_detail_sale
1803 where
1804 jr_def_id = $1
1805 and jr_date >= (select p_start from parm_periode where p_id = $2)
1806 {$sql_filter}
1807 and jr_date <= (select p_end from parm_periode where p_id = $3) "
1808 .' order by jr_date,substring(jr_pj_number,\'[0-9]+$\')::numeric asc ';
1809 $ret = $this->db->exec_sql($sql, array($this->id,$p_from, $p_end));
1810 return $ret;
1811 }
1812 /**
1813 * @brief compute an array with the heading cells for the
1814 * details, used for the export in CSV
1815 * @return array
1816 */
1817 static function heading_detail_sale()
1818 {
1819 $array['jr_id'] = _('Numéro opération');
1820 $array['jr_date'] = _('Date');
1821 $array['jr_date_paid'] = _('Date paiement');
1822 $array['jr_ech'] = _('Date échéance');
1823 $array['jr_tech_per'] = _('Période');
1824 $array['jr_comment'] = _('Libellé');
1825 $array['jr_pj_number'] = _('Pièce');
1826 $array['jr_internal'] = _('Interne');
1827 $array['jr_def_id'] = _('Code journal');
1828 $array['j_poste'] = _('Poste');
1829 $array['j_text'] = _('Commentaire');
1830 $array['j_qcode'] = _('Code Item');
1831 $array['jr_rapt'] = _('Payé');
1832 $array['item_card'] = _('N° item');
1833 $array['item_name'] = _('Nom fiche');
1834 $array['qs_client'] = _('N° fiche fournisseur');
1835 $array['tiers_name'] = _('Nom fournisseur');
1836 $array['quick_code'] = _('Code fournisseur');
1837 $array['tva_label'] = _('Nom TVA');
1838 $array['tva_comment'] = _('Commentaire TVA');
1839 $array['tva_both_side'] = _('TVA annulée');
1840 $array['vat_sided'] = _('TVA Non Payé');
1841 $array['vat_code'] = _('Code TVA');
1842 $array['vat'] = _('Montant TVA');
1843 $array['price'] = _('Total HTVA');
1844 $array['quantity'] = _('quantité');
1845 $array['price_per_unit'] = _('PU');
1846 $array['htva'] = _('HTVA Opération');
1847 $array['tot_vat'] = _('TVA Opération');
1848 $array['tot_vat_np'] = _('TVA ND');
1849 $array['other_tax'] = _("Autre taxe");
1850 $array['oc_amount'] = _('Mont. Devise');
1851 $array['oc_vat_amount'] = _('Mont. TVA Devise');
1852 $array['cr_code_iso'] = _('Devise');
1853
1854
1855 return $array;
1856 }
1857
1858 /**
1859 * @brief convert an Acc_Sold to an array usable by
1860 * Acc_Document::create_document
1861 * @parameters $sold (Acc_Sold) convert to convert
1862 */
1863 static function convert_to_array(Acc_Sold $sold)
1864 {
1865 //print $sold;
1866 $item=count($sold->det->array);
1867 if ( $item ==0)
1868 {
1869 throw new \Exception('No Data in Quant_sold');
1870 }
1871 $array=array();
1872
1873 $array['e_ech']=format_date($sold->det->jr_ech);
1874 $array['e_comm']=$sold->det->jr_comment;
1875 $array['p_jrn']=$sold->det->jr_def_id;
1876 $array['nb_item']=$item;
1877 $array['ledger_type']=$sold->signature;
1878 $array['e_date']= format_date($sold->det->jr_date);
1879 $array['e_pj']= $sold->det->jr_pj_number;
1880 $array['jr_date_paid']=$sold->det->jr_date_paid;
1881
1882 //$this->pj=$array['e_pj'];
1883 $array['internal']=$sold->det->jr_internal;
1884
1885 $client=new \Fiche($sold->db,$sold->det->array[0]['qs_client']);
1886 $array['e_client']=$client->get_quick_code();
1887 bcscale(2);
1888 for ($i=0;$i < $item ; $i++)
1889 {
1890 $idx='e_march';
1891 $serv=new \Fiche($sold->db,$sold->det->array[$i]['qs_fiche']);
1892 $array[$idx.$i]=$serv->get_quick_code();
1893 $array[$idx.$i.'_label']=$sold->det->array[$i]['j_text'];
1894 $array[$idx.$i.'_price']=bcdiv($sold->det->array[$i]['qs_price'],$sold->det->array[$i]['qs_quantite']);
1895 $array[$idx.$i.'_tva_id']=$sold->det->array[$i]['qs_vat_code'];
1896 $array[$idx.$i.'_tva_amount']=bcsub($sold->det->array[$i]['qs_vat'],$sold->det->array[$i]['qs_vat_sided']);
1897 $array['e_quant'.$i]=$sold->det->array[$i]['qs_quantite'];
1898 }
1899 // Get OTHER_INFO and BON_COMM
1900 $cn=\Dossier::connect();
1901 $array['bon_comm']=$cn->get_value("select ji_value from jrn_info where jr_id=$1 and id_type = 'BON_COMMANDE' ",[$sold->det->jr_id]);
1902 $array['other_info']=$cn->get_value("select ji_value from jrn_info where jr_id=$1 and id_type = 'OTHER' ",[$sold->det->jr_id]);
1903 $array['jrn_note_input']=$cn->get_value("select n_text from
1904 jrn_note where jr_id=$1 ",[$sold->det->jr_id]);
1905 $array['p_currency_code']=$sold->det->currency_id;
1906 $array['p_currency_rate']=$sold->det->currency_rate;
1907 return $array;
1908
1909
1910 }
1911
1912}
1913
format_date($p_date, $p_from_format='YYYY-MM-DD', $p_to_format='DD.MM.YYYY')
format the date, when taken from the database the format is MM-DD-YYYY
isNumber($p_int)
hb($p_string)
Definition ac_common.php:53
span($p_string, $p_extra='')
Definition ac_common.php:43
isDate($p_date)
Verifie qu'une date est bien formaté en d.m.y et est valable.
noalyss_strlentrim($p_string)
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 or in the log folder of NOALYSS Record also t...
sql_string($p_string)
Fix the problem with the quote char for the database.
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.
cmpDate($p_date, $p_date_oth)
Compare 2 dates.
global $g_parameter
global $g_user
if no group available , then stop
catch(Exception $e) $obj
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$op
h( $row[ 'oa_description'])
$op jr_id
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
_("actif, passif,charge,...")
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
: input, confirm and save new operations in edger of sales the $_POST data is an array with these key...
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
static convert_to_array(Acc_Sold $sold)
convert an Acc_Sold to an array usable by Acc_Document\create_document @parameters $sold (Acc_Sold) c...
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)
construct
verify_operation($p_array)
verify that the data are correct before inserting or confirming
Class for jrn, class acc_ledger for manipulating the ledger AND some acc.
input_supplemental_document()
display INPUT type to ask the supplementary documents
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...
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...
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
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,...
this class manage data from the QUANT_SOLD table
static build($db, $p_code)
retrieve TVA rate thanks the code that could be the tva_id or tva_code.
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...
static ledger_add_item($p_ledger)
Build a HTML string for adding multiple rows.
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...
Html Input for uploading file, must be in a form with enctype="multipart/form-data".
Html Input.
This class handles only the numeric input, the input will call a javascript to change comma to period...
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.
Html Input Text member :
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.
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
if( $g_parameter->MY_PJ_SUGGEST=='Y') $e_date
$other_tax_amount
Definition compute.php:94
const ATTR_DEF_ADRESS
Definition constant.php:230
const OPEN
Definition constant.php:207
const ATTR_DEF_NAME
Definition constant.php:223
const ATTR_DEF_TVA
Definition constant.php:228
const ATTR_DEF_POSTCODE
Definition constant.php:231
const ATTR_DEF_CITY
Definition constant.php:236
const EXC_BALANCE
Definition constant.php:362
const ATTR_DEF_QUICKCODE
Definition constant.php:244
const ATTR_DEF_ACCOUNT
Definition constant.php:222
const FICADD
const UPDRECEIPT
$jrn_type[]
$_POST['ac']
Definition do.php:323
$oPeriode
Definition do.php:164
$SecUser db
create_script($p_string)
create the HTML for adding the script tags around of the script
$str_code
$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...