noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
acc_ledger_purchase.class.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!
23 * \file
24 * \brief class for the purchase, herits from acc_ledger
25 */
26require_once NOALYSS_INCLUDE.'/lib/user_common.php';
27require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
28
29
30/*!
31 * \class Acc_Ledger_Purchase
32 ** @brief : input, confirm and save new operations in edger of purchase
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 supplier
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 ACH)
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 */
114{
115 private $payment_operation; /*<! id of the payment , set in insert */
116
117 function __construct ($p_cn,$p_init)
118 {
119 $this->ledger_type='ACH';
120 parent::__construct($p_cn,$p_init);
121 $this->payment_operation=-1;
122 }
123 /*!
124 * \brief verify that the data are correct before inserting or confirming
125 *\param an array (usually $_POST)
126 *\return String
127 *\throw Exception if an error occurs
128 */
129 public function verify_operation($p_array)
130 {
131 global $g_parameter,$g_user;
132
133 if (is_array($p_array ) == false || empty($p_array))
134 throw new Exception ("Array empty");
135 /*
136 * Check needed value
137 */
138 check_parameter($p_array,'p_jrn,e_date,e_client');
139
140 extract ($p_array, EXTR_SKIP);
141 /* check if we can write into this ledger */
142 if ( $g_user->check_jrn($p_jrn) != 'W' )
143 throw new Exception (_('Accès interdit'),20);
144
145
146 /* check for a double reload */
147 if ( isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1',array($mt)) != 0 )
148 throw new Exception (_('Double Encodage'),5);
149
150 /* check if there is a customer */
151 if ( noalyss_strlentrim($e_client)== 0 )
152 throw new Exception(_('Vous n\'avez pas donné de fournisseur'),11);
153
154 /* check if the date is valid */
155 if ( isDate($e_date) == null )
156 {
157 throw new Exception(_('Date invalide'), 2);
158 }
159 $oPeriode=new Periode($this->db);
160 if ( $this->check_periode() == false || ! isset($p_array['period']))
161 {
162 $tperiode=$oPeriode->find_periode($e_date);
163 }
164 else
165 {
166 $tperiode=$period;
167 $oPeriode->p_id=$tperiode;
168 /* check that the datum is in the choosen periode */
169 list ($min,$max)=$oPeriode->get_date_limit($tperiode);
170 if ( cmpDate($e_date,$min) < 0 ||
171 cmpDate($e_date,$max) > 0)
172 throw new Exception(_('Date et periode ne correspondent pas'),6);
173 }
174 /* check if the periode is closed */
175 if ( $this->is_closed($tperiode)==1 )
176 {
177 throw new Exception(_('Periode fermee'),6);
178 }
179
180 /* check if we are using the strict mode */
181 if( $this->check_strict() == true)
182 {
183 /* if we use the strict mode, we get the date of the last
184 operation */
185 $last_date=$this->get_last_date();
186 if ( $last_date != null && cmpDate($e_date,$last_date) < 0 )
187 throw new Exception(_('Vous utilisez le mode strict la dernière operation est à la date du ')
188 .$last_date._(' vous ne pouvez pas encoder à une '.
189 ' date antérieure dans ce journal'),13);
190
191 }
192
193 /* check the account */
194 $fiche=new Fiche($this->db);
195 $fiche->get_by_qcode($e_client);
196 if ($fiche->get_f_enable() == '0')
197 throw new Exception(sprintf(_("La fiche %s n'est plus utilisée"),$e_client), 50);
198
199 if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
200 throw new Exception(_('La fiche ').$e_client._('n\'a pas de poste comptable'),8);
201
202
203
204 /* get the account and explode if necessary */
205 $sposte=$fiche->get_attribute(ATTR_DEF_ACCOUNT);
206 // if 2 accounts, take only the credit one for supplier
207 if ( strpos($sposte,',') != 0 )
208 {
209 $array=explode(',',$sposte);
210 $poste_val=$array[1];
211 }
212 else
213 {
214 $poste_val=$sposte;
215 }
216
217 /* The account exists */
218 $poste=new Acc_Account_Ledger($this->db,$poste_val);
219 if ( $poste->load() == false )
220 {
221 throw new Exception(_('Pour la fiche ').$e_client._(' le poste comptable [').$poste->id.'] '._('n\'existe pas'),9);
222 }
223 /* Check if the card belong to the ledger */
224 $fiche=new Fiche ($this->db);
225 $fiche->get_by_qcode($e_client,'cred');
226 if ( $fiche->belong_ledger($p_jrn) !=1 )
227 throw new Exception(_('La fiche ').$e_client._('n\'est pas accessible à ce journal'),10);
228
229 $nb=0;
230 //------------------------------------------------------
231 // The "Paid By" check
232 //------------------------------------------------------
233 if ($e_mp != 0 ) {
234 $this->check_payment($e_mp,${"e_mp_qcode_".$e_mp});
235 // check for the currency , if we use a financial ledger and a card which is a bank account (with his own
236 // ledger , then the currency of the operation must be the same
237 $this->check_currency(${"e_mp_qcode_" . $e_mp},$p_currency_code);
238 }
239
240
241 //----------------------------------------
242 // foreach item
243 //----------------------------------------
244 for ($i=0;$i< $nb_item;$i++)
245 {
246 if ( noalyss_strlentrim(${'e_march'.$i})== 0) continue;
247
248 /* check if all card has a ATTR_DEF_ACCOUNT*/
249 $fiche=new Fiche($this->db);
250 $fiche->get_by_qcode(${'e_march'.$i});
251 if ($fiche->get_f_enable() == '0')
252 throw new Exception(sprintf(_("La fiche %s n'est plus utilisée"), ${'e_march' . $i}), 50);
253
254 /* check if amount are numeric and */
255 if ( isNumber(${'e_march'.$i.'_price'}) == 0 )
256 throw new Exception(_('La fiche ').${'e_march'.$i}._('a un montant invalide').' ['.${'e_march'.$i}.']',6);
257 if ( isNumber(${'e_quant'.$i}) == 0 )
258 throw new Exception(_('La fiche ').${'e_march'.$i}._('a une quantité invalide').' ['.${'e_quant'.$i}.']',7);
259
260 // Check if the given tva id is valid
261 if ( $g_parameter->MY_TVA_USE=='Y')
262 {
263 $tva_rate = Acc_Tva::build($this->db,${'e_march' . $i . '_tva_id'});
264 if ($tva_rate->tva_id == -1)
265 throw new Exception(_('La fiche ').${'e_march'.$i}._('a un code tva invalide').' ['.${'e_march'.$i.'_tva_id'}.']',13);
266 $tva_rate->load();
267 /*
268 * check if the accounting for VAT are valid
269 */
270 $a_poste=explode(',',$tva_rate->tva_poste);
271
272 if (
273 $this->db->get_value('select count(*) from tmp_pcmn where pcm_val=$1',array($a_poste[0])) == 0 )
274 throw new Exception(_(" La TVA ".$tva_rate->tva_label." utilise des postes comptables inexistants"));
275
276 }
277
278 if ( $fiche->empty_attribute(ATTR_DEF_ACCOUNT) == true)
279 throw new Exception(_('La fiche ').${'e_march'.$i}._('n\'a pas de poste comptable'),8);
280
281 /* get the account and explode if necessary */
282 $sposte=$fiche->get_attribute(ATTR_DEF_ACCOUNT);
283 // if 2 accounts, take only the debit
284 if ( strpos($sposte,',') != 0 )
285 {
286 $array=explode(',',$sposte);
287 $poste_val=$array[0];
288 }
289 else
290 {
291 $poste_val=$sposte;
292 }
293
294 /* The account exists */
295 $poste=new Acc_Account_Ledger($this->db,$poste_val);
296 if ( $poste->load() == false )
297 {
298 throw new Exception(_('Pour la fiche ').${'e_march'.$i}._(' le poste comptable').' ['.$poste->id._('n\'existe pas'),9);
299 }
300 /* Check if the card belong to the ledger */
301 $fiche=new Fiche ($this->db);
302 $fiche->get_by_qcode(${'e_march'.$i});
303 if ( $fiche->belong_ledger($p_jrn,'deb') !=1 )
304 throw new Exception(_('La fiche ').${'e_march'.$i}._('n\'est pas accessible à ce journal'),10);
305 /**
306 * we have to check also if the different accountings exist
307 "ATTR_DEF_DEP_PRIV"
308 "ATTR_DEF_DEPENSE_NON_DEDUCTIBLE"
309 "ATTR_DEF_TVA_NON_DEDUCTIBLE"
310 "ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP"
311 */
312 foreach (array(
317 {
318 if ( ! $fiche->empty_attribute($key[0]) && $fiche->empty_attribute($key[2]))
319 {
320 $a=new Acc_Parm_Code($this->db,$key[1]);
321 if ( $this->db->count_sql('select pcm_val from tmp_pcmn where pcm_val=$1',array($a->p_value))==0)
322 throw new Exception ($key[1]._("ce code n'a pas de poste comptable, créez ce poste : [".$a->p_value."]"));
323 }
324 if ( ! $fiche->empty_attribute($key[0]) && ! $fiche->empty_attribute($key[2]))
325 {
326 $nd_str=$fiche->get_attribute($key[2]);
327 if ( $nd_str != '')
328 {
329 $poste_nd=new Acc_Account_Ledger($this->db,$nd_str);
330 if ( $poste_nd->load() == false)
331 {
332 $nd_msg=sprintf(_("Pour la fiche %s, le compte contrepartie %s n'existe pas"),
333 $fiche->getName(),$poste_nd->id);
334 $nd_msg=h($nd_msg);
335 throw new Exception ($nd_msg);
336 }
337 }
338 }
339 }
340 if ( ${"e_quant".$i} != 0 && trim(${"e_quant".$i}) !="" ) {$nb++;}
341 }
342
343 if ( $nb == 0 )
344 throw new Exception(_('Il n\'y a aucune marchandise'),12);
345
346 // check payment date
347 if ( isset ($mp_date) && trim ($mp_date) != "" && isDate($mp_date) == null) {
348 throw new Exception(_('Date de paiement invalide'),13);
349
350 }
351 // check that MP is in a not closed and exists
352 if ( isset ($mp_date) && trim ($mp_date) != "" && isDate($mp_date) == $mp_date ) {
353 $periode=new Periode($this->cn);
354 $periode->find_periode($mp_date);
355 $periode->set_ledger($this->id);
356 if ( $periode->is_closed() ) {
357 throw new Exception(_("Période fermée")." $mp_date ");
358 }
359
360 }
361 // check limit date
362 if ( isset ($e_ech) && trim ($e_ech)!="" && isDate($e_ech) == null )
363 {
364 throw new Exception(_('Date échéance invalide'),14);
365
366 }
367 // Check currency_rate if valid
368 if ( isNumber($p_currency_rate) == 0 || $p_currency_rate <=0 ) {
369 throw new Exception(_('Taux devise invalide'),15);
370 }
371 $this->check_currency_setting($p_currency_code);
372 }
373 /**
374 * Compute the ND amount thanks the attribute of the concerned card. The object
375 * $p_nd_amount will changed
376 *
377 * @param Acc_Compute $p_nd_amount object with ND amount
378 * @param Fiche $p_fiche Concerned Card (purchase items)
379 * @param type $p_tva_bot 0 TVA on one side, 1 TVA on both side
380 */
381 private function compute_no_deductible(Acc_Compute $p_nd_amount, Fiche $p_fiche)
382 {
384 {
385 $p_nd_amount->amount_nd_rate = $p_fiche->get_attribute(ATTR_DEF_DEPENSE_NON_DEDUCTIBLE);
386 $p_nd_amount->compute_nd();
387 }
389 {
390 $p_nd_amount->nd_vat_rate = $p_fiche->get_attribute(ATTR_DEF_TVA_NON_DEDUCTIBLE);
391 $p_nd_amount->compute_nd_vat();
392 }
394 {
395 $p_nd_amount->nd_ded_vat_rate = $p_fiche->get_attribute(ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP);
396 $p_nd_amount->compute_ndded_vat();
397 }
398
399 if (!$p_fiche->empty_attribute(ATTR_DEF_DEP_PRIV))
400 {
401 $p_nd_amount->amount_perso_rate = $p_fiche->get_attribute(ATTR_DEF_DEP_PRIV);
402 $p_nd_amount->compute_perso();
403 }
404
405 }
406
407 /**
408 * @brief Insert into JRNX the No Deductible amount and into Analytic Accountancy for the ND VAT
409 * @param Acc_Compute $p_nd_amount content ND amount
410 * @param Fiche $p_fiche Card of the Service
411 * @param type $p_tva_both 0 if TVA is normal or 1 if on both side
412 * @param type $p_tot_debit total debit
413 * @param $p_acc_operation Acc_Operation for inserting into jrnx
414 * @param $p_group group for AC
415 * @param $idx row number
416 *
417 * @see Acc_Ledger_Purchase::insert
418 */
419 private function insert_no_deductible(Acc_Compute $p_nd_amount, Fiche $p_fiche, $p_tva_both,&$p_tot_debit,Acc_Operation $p_acc_operation,$p_group,$idx)
420 {
421 global $g_parameter;
422 if ($p_acc_operation->jrnx_id == 0) {
423 throw new Exception(__FILE__.__LINE__.'invalid acc_operation.j_id');
424 }
425 $source_j_id=$p_acc_operation->jrnx_id ;
426 /*
427 * Save all the no deductible
428 * ATTR_DEF_ACCOUNT_ND_TVA,ATTR_DEF_ACCOUNT_ND_TVA_ND,ATTR_DEF_ACCOUNT_ND_PERSO,ATTR_DEF_ACCOUNT_ND
429 */
430 if ($p_nd_amount->amount_nd_rate != 0)
431 {
432 $dna_default = new Acc_Parm_Code($this->db, 'DNA');
433
434 /* save op. */
435 if (!$p_fiche->empty_attribute(ATTR_DEF_ACCOUNT_ND))
436 {
437 $dna = $p_fiche->get_attribute(ATTR_DEF_ACCOUNT_ND);
438 } else
439 {
440 $dna = $dna_default->p_value;
441 }
442 $dna = ($dna == '') ? $dna_default->p_value : $dna;
443
444 $p_acc_operation->type = 'd';
445 $p_acc_operation->amount = $p_nd_amount->amount_nd;
446 $p_acc_operation->poste = $dna;
447 $p_acc_operation->qcode = '';
448 $p_acc_operation->desc=$this->find_label($dna)." ND ".$p_fiche->get_attribute(ATTR_DEF_QUICKCODE);
449 if ($p_nd_amount->amount_nd > 0)
450 $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->amount_nd );
451 $j_id = $p_acc_operation->insert_jrnx();
452 }
453 /*
454 * ATTR_DEF_ACCOUNT_ND_PERSO
455 */
456 if ($p_nd_amount->amount_perso != 0)
457 {
458 $dna_default = new Acc_Parm_Code($this->db, 'DEP_PRIV');
459
460 /* save op. */
461 $p_acc_operation->type = 'd';
463 {
465 } else
466 {
467 $dna = $dna_default->p_value;
468 }
469 $dna = ($dna == '') ? $dna_default->p_value : $dna;
470
471 $p_acc_operation->amount = $p_nd_amount->amount_perso ;
472 $p_acc_operation->poste = $dna;
473 $p_acc_operation->qcode = '';
474 $p_acc_operation->desc=$this->find_label($dna)." ND_PRIV ".$p_fiche->get_attribute(ATTR_DEF_QUICKCODE);
475 if ($p_nd_amount->amount_perso> 0)
476 $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->amount_perso);
477 $j_id = $p_acc_operation->insert_jrnx();
478 }
479 if ($p_nd_amount->nd_vat != 0)
480 {
481 $dna_default = new Acc_Parm_Code($this->db, 'TVA_DNA');
482
483 /* save op. */
484 $p_acc_operation->type = 'd';
485 $p_acc_operation->qcode = '';
487 {
489 } else
490 {
491 $dna = $dna_default->p_value;
492 }
493 $dna = ($dna == '') ? $dna_default->p_value : $dna;
494
495 $p_acc_operation->amount = $p_nd_amount->nd_vat;
496 $p_acc_operation->poste = $dna;
497 $p_acc_operation->desc=$this->find_label($dna)." ND_TVA ".$p_fiche->get_attribute(ATTR_DEF_QUICKCODE);
498 $j_id = $p_acc_operation->insert_jrnx();
499 if ( $g_parameter->MY_ANALYTIC != "nu"
500 && $g_parameter->match_analytic($p_fiche->get_attribute(ATTR_DEF_ACCOUNT))
501 )
502 {
503 $op=new Anc_Operation($this->db);
504 $op->oa_group=$p_group;
505 $op->j_id=$j_id;
506 $op->oa_date=$p_acc_operation->date;
507
508 $op->oa_debit='t';
509 $op->oa_description=sql_string('ND_TVA');
510 $op->oa_jrnx_id_source=$source_j_id;
511 $op->save_form_plan_vat_nd($_POST,$idx,$j_id,$p_nd_amount->nd_vat,$p_acc_operation->jrnx_id);
512 }
513 if ($p_nd_amount->nd_vat> 0)
514 $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->nd_vat);
515
516 }
517 if ($p_nd_amount->nd_ded_vat != 0)
518 {
519 $dna_default = new Acc_Parm_Code($this->db, 'TVA_DED_IMPOT');
520 /* save op. */
522 {
523 $dna = $p_fiche->get_attribute(ATTR_DEF_ACCOUNT_ND_TVA);
524 } else
525 {
526 $dna = $dna_default->p_value;
527 }
528 $dna = ($dna == '') ? $dna_default->value : $dna;
529
530
531
532 $p_acc_operation->type = 'd';
533 $p_acc_operation->qcode = '';
534 $p_acc_operation->amount = $p_nd_amount->nd_ded_vat;
535 $p_acc_operation->poste = $dna;
536 $p_acc_operation->desc=$this->find_label($dna)." DED_TVA ".$p_fiche->get_attribute(ATTR_DEF_QUICKCODE);
537 if ($p_nd_amount->nd_ded_vat > 0)
538 $p_tot_debit = bcadd($p_tot_debit, $p_nd_amount->nd_ded_vat);
539 $j_id = $p_acc_operation->insert_jrnx();
540 if ( $g_parameter->MY_ANALYTIC != "nu"
541 && $g_parameter->match_analytic($p_fiche->get_attribute(ATTR_DEF_ACCOUNT))
542 )
543 {
544 $op=new Anc_Operation($this->db);
545 $op->oa_group=$p_group;
546 $op->j_id=$j_id;
547 $op->oa_date=$p_acc_operation->date;
548
549 $op->oa_debit='t';
550 $op->oa_description=sql_string('DED_TVA ');
551 $op->oa_jrnx_id_source=$source_j_id;
552 $op->save_form_plan_vat_nd($_POST,$idx,$j_id,$p_nd_amount->nd_ded_vat);
553 }
554 }
555 }
556
557 /*!
558 * \brief insert into the database, it calls first the verify function
559 * change the value of this->jr_id and this->jr_internal.
560 * It generates the document and save the middle of payment, if 'gen_invoice is set
561 * and e_mp
562 *\param $p_array is usually $_POST or a predefined operation
563 \code
564 Array
565 (
566
567 [e_client] =>BELGACOM
568 [nb_item] =>9
569 [p_jrn] =>3
570 [period] =>117
571 [e_comm] =>Frais de téléphone
572 [e_date] =>01.09.2009
573 [e_ech] =>
574 [jrn_type] =>ACH
575 [e_pj] =>ACH53
576 [e_pj_suggest] =>ACH53
577 [mt] =>1265318941.39
578 [e_mp] =>0
579 [e_march0] =>TEL
580 [e_march0_price] =>63.6700
581 [e_march0_tva_id] =>1
582 [e_march0_tva_amount] =>13.3700
583 [e_quant0] =>1.000
584 ...
585 [bon_comm] =>
586 [other_info] =>
587 [record] =>Enregistrement
588 [p_currency_code]=> id currency
589 [p_currency_rate]=>rate used
590 )
591 \endcode
592 *\return string
593 *\note throw an Exception
594 */
595 public function insert($p_array=null)
596 {
597 global $g_parameter,$g_user;
598 extract ($p_array, EXTR_SKIP);
599 $this->verify($p_array) ;
600 if ( !isset($p_array['jrn_note_input'])) {$p_array['jrn_note_input']='';}
601 $group=$this->db->get_next_seq("s_oa_group"); /* for analytic */
602 $seq=$this->db->get_next_seq('s_grpt');
603 $this->id=$p_jrn;
604
605 $internal=$this->compute_internal_code($seq);
606 $this->jr_internal=$internal;
607
608 $cust=new Fiche($this->db);
609 $cust->get_by_qcode($e_client);
610 $sposte=$cust->get_attribute(ATTR_DEF_ACCOUNT);
611 // if 2 accounts, take only the credit Supplier
612 if ( strpos($sposte,',') != 0 )
613 {
614 $array=explode(',',$sposte);
615 $poste=$array[1];
616 }
617 else
618 {
619 $poste=$sposte;
620 }
621
622 $oPeriode=new Periode($this->db);
624
625 if ( $check_periode == true && isset($p_array['period']) )
626 $tperiode=$period;
627 else
628 $tperiode=$oPeriode->find_periode($e_date);
629
630
631 try
632 {
633 bcscale(4);
634 // variable : $tot_amount float : total amount of the purchase (debit)
635 $tot_amount=0;
636
637 // variable : $tot_tva float : total amount of the VAT
638 $tot_tva=0;
639
640 // variable: $tot_debit float : amount on debit side
641 $tot_debit=0;
642
643 $this->db->start();
644
645
646 // variable: $tot_tva_reversed float total VAT autoreverse, to deduce from supplier's amount
647 $tot_tva_reversed=0;
648
649 // variable : $tva array that will contain all the VAT Amount
650 $tva=array();
651
652 // variable : $tva_reverse array that contain all the VAT autoreverse AND negative
653 $tva_reverse = array();
654
655 // variable : $tva_reverse_credit array that contain all the VAT autoreverse for credit
656 $tva_reverse_credit = array();
657
658 // variable : $tot_amount_cur : total amount in currency
659 $tot_amount_cur=0;
660
661 // find the currency from v_currency_last_value
662 // variable : $currency_rate_ref Acc_Currency , currency object for this operation
663 $currency_rate_ref=new Acc_Currency($this->db, $p_currency_code);
664
665 /* Save all the items without vat and no deductible vat and expense*/
666 for ($i=0;$i< $nb_item;$i++)
667 {
668 if ( empty(${'e_march'.$i}) || empty(${'e_quant'.$i}) ) continue;
669
670 /* First we save all the items without vat */
671 $fiche=new Fiche($this->db);
672 $fiche->get_by_qcode(${"e_march".$i});
673 // variable : $tva_both integer 1 for autoreverse ,0 normal, fetch it once for this item,
674 $tva_both=0;
675 /* tva */
676 if ($g_parameter->MY_TVA_USE=='Y')
677 {
678 $idx_tva=trim(${'e_march'.$i.'_tva_id'});
679 $oTva=Acc_Tva::build($this->db,$idx_tva);
680
681 $oTva->load();
682 $tva_both=$oTva->get_parameter("both_side");
683 }
684 /* -- Create acc_operation -- */
685 $acc_operation=new Acc_Operation($this->db);
686 $acc_operation->date=$e_date;
687 $acc_operation->grpt=$seq;
688 $acc_operation->jrn=$p_jrn;
689 $acc_operation->type='d';
690 $acc_operation->periode=$tperiode;
691 $acc_operation->qcode="";
692 $amount_4=bcmul(${'e_march'.$i.'_price'},${'e_quant'.$i});
693
694 /* We have to compute all the amount thanks Acc_Compute */
695
696 $acc_amount=new Acc_Compute();
697 $acc_amount->check=false;
698 $acc_amount->set_parameter('amount',$amount_4);
699 // Set the currency rate
700 $acc_amount->set_parameter("currency_rate", $p_currency_rate);
701 $acc_amount->convert_euro();
702 $amount_euro=$acc_amount->amount;
703
704 // Compute VAT or take the given one
705 if ( $g_parameter->MY_TVA_USE=='Y')
706 {
707 $acc_amount->set_parameter('amount_vat_rate',$oTva->get_parameter('rate'));
708 if ( noalyss_strlentrim(${'e_march'.$i.'_tva_amount'}) ==0 || ${'e_march'.$i.'_tva_amount'} == 0)
709 {
710 // vat must computed and the amount is already converted to EUR
711 $acc_amount->compute_vat();
712
713 }
714 else
715 {
716 // we convert the vat in euro
717 $acc_amount->set_parameter("amount_vat", ${'e_march'.$i.'_tva_amount'});
718 $acc_amount->convert_euro_vat();
719
720 }
721 // convert amount in eur
722 $tot_tva=bcadd($tot_tva,$acc_amount->amount_vat);
723 $tot_tva=round($tot_tva,2);
724 }
725
726
727 /* compute ND */
728 // variable: $save_amount_vat total float amount of VAT before changing due to NOT DEDUCTIBLE
729 $save_amount_vat=$acc_amount->amount_vat;
730 $this->compute_no_deductible($acc_amount, $fiche);
731 $acc_amount->correct();
732 // TVA which avoid
733 if ( $tva_both == 1 ) {
734 $acc_amount->autoreverse=$save_amount_vat;
735 $tot_tva_reversed=bcadd($tot_tva_reversed,$save_amount_vat);
736 }
737
738
739
740 $tot_amount=round(bcadd($tot_amount,$acc_amount->amount),2);
741 $tot_amount=round(bcadd($tot_amount,$acc_amount->amount_nd),2);
742 $tot_amount=round(bcadd($tot_amount,$acc_amount->amount_perso),2);
743
744 /* get the account and explode if necessary */
745 $sposte=$fiche->get_attribute(ATTR_DEF_ACCOUNT);
746 // if 2 accounts, take only the debit one for customer
747 if ( strpos($sposte,',') != 0 )
748 {
749 $array=explode(',',$sposte);
750 $poste_val=$array[0];
751 }
752 else
753 {
754 $poste_val=$sposte;
755 }
756 if ($g_parameter->MY_UPDLAB=='Y')
757 {
758 $acc_operation->desc=strip_tags(${"e_march".$i."_label"}??"");
759 }
760 else
761 {
762 $acc_operation->desc="";
763 }
764 $acc_operation->poste=$poste_val;
765 $acc_operation->amount=$acc_amount->amount;
766 $acc_operation->qcode=${"e_march".$i};
767 if ($acc_amount->amount>0)
768 {
769 $tot_debit=bcadd($tot_debit, $acc_amount->amount);
770 }
771 $j_id=$acc_operation->insert_jrnx();
772
773 /* insert ND */
774 $this->insert_no_deductible($acc_amount, $fiche, $tva_both, $tot_debit,$acc_operation,$group,$i);
775
776
777 /* Compute sum vat */
778 if ( $g_parameter->MY_TVA_USE=='Y')
779 {
780 $tva_item=$acc_amount->amount_vat;
781
782 if ($tva_both == 0 ){
783 $tva[$idx_tva]=(isset( $tva[$idx_tva]))? $tva[$idx_tva]:0;
784 $tva[$idx_tva]=bcadd($tva[$idx_tva], $tva_item);
785 }else {
786 // $tva_item < 0 && $tva_both == 1
787 $tva_reverse[$idx_tva]=(isset($tva_reverse[$idx_tva]))?$tva_reverse[$idx_tva]:0;
788 $tva_reverse[$idx_tva]=bcadd($tva_item,$tva_reverse[$idx_tva]);
789 $tva_reverse_credit[$idx_tva]=(isset($tva_reverse_credit[$idx_tva]))?$tva_reverse_credit[$idx_tva]:0;
790 $tva_reverse_credit[$idx_tva]=bcadd($save_amount_vat,$tva_reverse_credit[$idx_tva]);
791 }
792 }
793 /* Save the stock */
794 /* if the quantity is < 0 then the stock increase (return of
795 * material)
796 */
797 $nNeg=(${"e_quant" . $i}< 0) ? -1 : 1;
798
799 // always save quantity but in withStock we can find
800 // what card need a stock management
801 if ( $g_parameter->MY_STOCK='Y'&& isset ($repo))
802 {
803 $dir=(${'e_quant'.$i} < 0 ) ? 'c':'d';
804 Stock_Goods::insert_goods($this->db,array('j_id'=>$j_id,'goods'=>${'e_march'.$i},'quant'=>$nNeg*${'e_quant'.$i},'dir'=>$dir,'repo'=>$repo)) ;
805 }
806
807 if ( $g_parameter->MY_ANALYTIC != "nu" && $g_parameter->match_analytic($poste_val))
808 {
809 // for each item, insert into operation_analytique */
810 $op=new Anc_Operation($this->db);
811 $op->set_currency_rate($p_currency_rate);
812 $op->oa_group=$group;
813 $op->j_id=$j_id;
814 $op->oa_date=$e_date;
815 $op->oa_debit='t';
816 $op->oa_description=sql_string($e_comm);
817 $op->save_form_plan($p_array,$i,$j_id);
818 }
819 // insert into quant_purchase
820 //-----
821
822 if (empty( ${'e_march' . $i . '_price'} ) ) ${'e_march' . $i . '_price'} = 0;
823 if (empty( ${'e_march' . $i } ) ) ${'e_march' . $i } = 0;
824 if (empty( ${'e_quant' . $i } ) ) ${'e_quant' . $i } = 0;
825 $price_euro=bcdiv(${'e_march'.$i.'_price'}, $p_currency_rate);
826
827 if ( $g_parameter->MY_TVA_USE=='Y')
828 {
829
830 $r=$this->db->exec_sql("select insert_quant_purchase ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)",
831 array(
832 null /*1*/
833 ,$j_id /* 2 */
834 ,${"e_march".$i} /* 3 */
835 ,${"e_quant".$i} /* 4 */
836 ,round($amount_euro,2) /* 5 */
837 ,$acc_amount->amount_vat /* 6 */
838 ,$oTva->get_parameter('id') /* 7 */
839 ,$acc_amount->amount_nd /* 8 */
840 ,$acc_amount->nd_vat /* 9 */
841 ,$acc_amount->nd_ded_vat /* 10 */
842 ,$acc_amount->amount_perso /* 11 */
843 ,$e_client /* 12 */
844 , $acc_amount->autoreverse /*13*/
845 ,$price_euro /* 14 */
846 ));
847
848
849 }
850 else
851 {
852 $acc_amount->amount_vat=0;
853 $r=$this->db->exec_sql("select insert_quant_purchase ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14)",
854 array(
855 null /*1*/
856 ,$j_id /* 2 */
857 ,${"e_march".$i} /* 3 */
858 ,${"e_quant".$i} /* 4 */
859 ,round($acc_amount->amount,2) /* 5 */
860 ,0 /* 6 */
861 ,null/* 7 */
862 ,$acc_amount->amount_nd /* 8 */
863 ,0 /* 9 */
864 ,$acc_amount->nd_ded_vat /* 10 */
865 ,$acc_amount->amount_perso /* 11 */
866 ,$e_client /* 12 */
867 , $acc_amount->autoreverse /*13*/
868 ,$price_euro /* 14 */
869 ));
870 }
871 /*
872 * Insert also in operation_currency
873 */
874 $operation_currency=new Operation_currency_SQL($this->db);
875 $operation_currency->oc_amount=$acc_amount->amount_currency;
876 $operation_currency->oc_vat_amount=($tva_both==0)?$acc_amount->amount_vat_currency:0;
877 $operation_currency->oc_price_unit=${'e_march'.$i.'_price'};
878 $operation_currency->j_id=$j_id;
879 $operation_currency->insert();
880 $tot_amount_cur=round(bcadd($tot_amount_cur,$acc_amount->amount_currency,4),4);
881 $tot_amount_cur=round(bcadd($tot_amount_cur,$acc_amount->amount_vat_currency,4),4);
882 if ( DEBUGNOALYSS > 1 ) {
883 echo __LINE__." insert into operation currency oc_amount:{$acc_amount->amount_currency} oc_vat_amount {$acc_amount->amount_vat_currency} <br>";
884 }
885 } // end loop : save all items
886
887
888 /*** save other tax ****/
889 if ( $this->has_other_tax() && isset($p_array['other_tax'])) {
890 $row=$this->db->get_row("select ac_id,ac_label,ac_accounting
891 from acc_other_tax
892 where ac_id=$1 ",
893 [$p_array['other_tax']]);
894 if ( ! empty ($row )) {
895 $other_tax_amount=bcmul($p_array['other_tax_amount'],$p_currency_rate);
896 $acc_operation=new Acc_Operation($this->db);
897 $acc_operation->date=$e_date;
898 $acc_operation->poste=$row['ac_accounting'];
899 $acc_operation->amount=$other_tax_amount;
900 $acc_operation->grpt=$seq;
901 $acc_operation->jrn=$p_jrn;
902 $acc_operation->type='d';
903 $acc_operation->periode=$tperiode;
904 $acc_operation->desc=$row['ac_label'];
905 $jrn_tax_sql=new Jrn_Tax_SQL($this->db);
906 $jrn_tax_sql->j_id=$acc_operation->insert_jrnx();
907 $jrn_tax_sql->ac_id=$row['ac_id'];
908 $jrn_tax_sql->pcm_val=$row['ac_accounting'];
909 $jrn_tax_sql->insert();
910 $operation_currency=new Operation_currency_SQL($this->db);
911 $operation_currency->oc_amount=$p_array['other_tax_amount'];
912 $operation_currency->oc_vat_amount=0;
913 $operation_currency->oc_price_unit=0;
914 $operation_currency->j_id=$jrn_tax_sql->j_id;
915 $operation_currency->insert();
916
917 $tot_debit=bcadd($tot_debit, abs($other_tax_amount));
919 }
920
921 }
922
923
924 /*** save total customer ***/
925 if ( DEBUGNOALYSS > 1 ) {
926 echo __LINE__." tot_amount $tot_amount<br>";
927 echo __LINE__." tot_tva $tot_tva<br>";
928
929 }
930 $cust_amount=round(bcadd($tot_amount,$tot_tva),2);
931 $acc_operation=new Acc_Operation($this->db);
932 $acc_operation->date=$e_date;
933 $acc_operation->poste=$poste;
934 $acc_operation->amount=bcsub($cust_amount,$tot_tva_reversed);
935 $acc_operation->grpt=$seq;
936 $acc_operation->jrn=$p_jrn;
937 $acc_operation->type='c';
938 $acc_operation->periode=$tperiode;
939 $acc_operation->qcode=${"e_client"};
940 if ($cust_amount<0)
941 {
942 $tot_debit=bcadd($tot_debit, abs($cust_amount));
943 }
944 $let_client=$acc_operation->insert_jrnx();
945
946 // --- insert also the currency amount for the customer
947 $operation_currency=new Operation_currency_SQL($this->db);
948 $operation_currency->oc_amount=$tot_amount_cur;
949 $operation_currency->oc_vat_amount=0;
950 $operation_currency->oc_price_unit=0;
951 $operation_currency->j_id=$let_client ;
952 $operation_currency->insert();
953
954 if ( $g_parameter->MY_TVA_USE=='Y')
955 {
956 /* save all vat
957 * $i contains the tva_id and value contains the vat amount
958 */
959 foreach ($tva as $i => $value)
960 {
961 $oTva=Acc_Tva::build($this->db,$i);
962 $poste_vat=$oTva->get_side('d');
963
964 $cust_amount=round(bcadd($tot_amount,$tot_tva),2);
965 $acc_operation=new Acc_Operation($this->db);
966 $acc_operation->date=$e_date;
967 $acc_operation->poste=$poste_vat;
968 $acc_operation->amount=$value;
969 $acc_operation->grpt=$seq;
970 $acc_operation->jrn=$p_jrn;
971 $acc_operation->type='d';
972 $acc_operation->periode=$tperiode;
973 if ( $value > 0 ) $tot_debit=bcadd($tot_debit,abs($value));
974 $acc_operation->insert_jrnx();
975
976 } // LOOP : foreach $tva
977 foreach ($tva_reverse as $i => $value) {
978 $oTva = Acc_Tva::build($this->db,$i);
979 $poste_vat = $oTva->get_side('d');
980 if ( $poste_vat == '#')
981 {
982 $poste_vat=$oTva->get_side('c');
983 }
984
985 $acc_operation = new Acc_Operation($this->db);
986 $acc_operation->date = $e_date;
987 $acc_operation->poste = $poste_vat;
988 $acc_operation->amount = $value;
989 $acc_operation->grpt = $seq;
990 $acc_operation->jrn = $p_jrn;
991 $acc_operation->type = 'd';
992 $acc_operation->periode = $tperiode;
993
994 $acc_operation->insert_jrnx();
995
996 // if TVA is on both side, we deduce it immediately
997 // $x temp variable is the tva_reverse_account and will be used to check $poste_vat
998 $x=$oTva->get_parameter("tva_reverse_account");
999 $poste_vat =(trim($x??"")=="")? $oTva->get_side('c'):$x;
1000
1001 if ( $poste_vat == '#')
1002 {
1003 $poste_vat=$oTva->get_side('d');
1004 }
1005 $acc_operation = new Acc_Operation($this->db);
1006 $acc_operation->date = $e_date;
1007 $acc_operation->poste = $poste_vat;
1008 $acc_operation->amount = $tva_reverse_credit[$i];
1009 $acc_operation->grpt = $seq;
1010 $acc_operation->jrn = $p_jrn;
1011 $acc_operation->type = 'c';
1012 $acc_operation->periode = $tperiode;
1013 $acc_operation->insert_jrnx();
1014 $tot_debit = bcadd($tot_debit, $value);
1015 $tot_debit = round($tot_debit, 2);
1016 } //LOOP: foreach $tva_reverse
1017 }
1018
1019 /* insert into jrn */
1020 $acc_operation=new Acc_Operation($this->db);
1021 $acc_operation->date=$e_date;
1022 $acc_operation->echeance=$e_ech;
1023 // Total DEB
1024 $acc_operation->amount=$this->db->get_value("select sum(j_montant) from jrnx where j_grpt = $1 and j_debit='t'",
1025 array($seq));
1026 $acc_operation->desc=$e_comm;
1027 $acc_operation->grpt=$seq;
1028 $acc_operation->jrn=$p_jrn;
1029 $acc_operation->periode=$tperiode;
1030 $acc_operation->pj=$e_pj;
1031 $acc_operation->mt=$mt;
1032 $acc_operation->currency_id=$p_currency_code;
1033 $acc_operation->currency_rate=$p_currency_rate;
1034 $acc_operation->currency_rate_ref=$currency_rate_ref->get_rate();
1035
1036 if ( ! $this->jr_id=$acc_operation->insert_jrn() ) {
1037 throw new Exception (_("Erreur de balance"),EXC_BALANCE);
1038 }
1039 $this->pj=$acc_operation->update_receipt();
1040
1041 // Set Internal code
1042 $this->jr_grpt_id=$seq;
1043 $this->update_internal_code($internal);
1044 /* update quant_purchase */
1045 $this->db->exec_sql('update quant_purchase set qp_internal = $1 where j_id in (select j_id from jrnx where j_grpt=$2)',
1046 array($internal,$seq));
1047
1048 /**= e_pj then do not increment sequence , if the given receipt number is equal to one computed then increment */
1049 if ($e_pj == $this->pj && noalyss_strlentrim($e_pj) != 0)
1050 {
1051 $this->inc_seq_pj();
1052 }
1053
1054 /* Save the attachment */
1055 if ( isset ($_FILES) && sizeof($_FILES) != 0 && $_FILES["pj"]["name"] != 0 )
1056 {
1057 $acc_document=new \Acc_Document($this->db, $this->jr_id);
1058 $acc_document->save_receipt();
1059 $this->doc=HtmlInput::show_receipt_document($this->jr_id,h($_FILES['pj']['name']));
1060 }
1061 $str_file="";
1062 /* Generate an document and save it into the database (Note de frais only)
1063 */
1064 if ( isset($_POST['gen_invoice']) )
1065 {
1066 $ref_doc= $this->create_document($internal,$p_array);
1067 $this->doc=HtmlInput::show_receipt_document($this->jr_id,h($ref_doc));
1068 }
1069
1070 //----------------------------------------
1071 // Save the payer
1072 //----------------------------------------
1073 if ( $e_mp != 0 )
1074 {
1075 /* mp */
1076 $mp=new Acc_Payment($this->db,$e_mp);
1077 $mp->load();
1078
1079 /* jrnx */
1080 $acseq=$this->db->get_next_seq('s_grpt');
1081 $acjrn=new Acc_Ledger($this->db,$mp->get_parameter('ledger_target'));
1082 $acinternal=$acjrn->compute_internal_code($acseq);
1083 /*
1084 * for the use of the card of the bank
1085 */
1086 if ( $acjrn->get_type()=='FIN') {
1087 $acjrn=new Acc_Ledger_Fin($this->db, $mp->get_parameter('ledger_target'));
1088 $acfiche=new Fiche($this->db,$acjrn->get_bank());
1089 $fqcode=$acfiche->get_attribute(ATTR_DEF_QUICKCODE);
1090 } else {
1091 $fqcode = ${'e_mp_qcode_' . $e_mp};
1092 $acfiche = new Fiche($this->db);
1093 $acfiche->get_by_qcode($fqcode);
1094 }
1095 /* Insert paid by */
1096 $acc_pay=new Acc_Operation($this->db);
1097 $acc_pay->date=$e_date;
1098
1099 /* get the account and explode if necessary */
1100 $sposte=$acfiche->get_attribute(ATTR_DEF_ACCOUNT);
1101 // if 2 accounts, take only the debit one for customer
1102 if ( strpos($sposte,',') != 0 )
1103 {
1104 $array=explode(',',$sposte);
1105 $poste_val=$array[1];
1106 }
1107 else
1108 {
1109 $poste_val=$sposte;
1110 }
1111 // remove the VAT autoliquidation
1112 $cust_amount=bcsub($cust_amount, $tot_tva_reversed);
1113
1114 // Convert paid amount in EUR
1115 $acompte_defcur=bcdiv($acompte, $p_currency_rate);
1116
1117 $famount=bcsub($cust_amount,$acompte_defcur);
1118
1119 $acc_pay->poste=$poste_val;
1120 $acc_pay->qcode=$fqcode;
1121 $acc_pay->amount=abs(round($famount,2));
1122 $acc_pay->desc='';
1123 $acc_pay->grpt=$acseq;
1124 $acc_pay->jrn=$mp->get_parameter('ledger_target');
1125 $acc_pay->periode=$tperiode;
1126 $acc_pay->type=($famount>=0)?'c':'d';
1127 $let_pay=$acc_pay->insert_jrnx();
1128
1129 /* Insert supplier */
1130 $acc_pay=new Acc_Operation($this->db);
1131 $acc_pay->date=empty($mp_date)?$e_date:$mp_date;
1132 $acc_pay->poste=$poste;
1133 $acc_pay->qcode=$e_client;
1134 $acc_pay->amount=abs(round($famount,2));
1135 $acc_pay->desc='';
1136 $acc_pay->grpt=$acseq;
1137 $acc_pay->jrn=$mp->get_parameter('ledger_target');
1138 $acc_pay->periode=$tperiode;
1139 $acc_pay->type=($famount>=0)?'d':'c';
1140 $let_other=$acc_pay->insert_jrnx();
1141
1142 // insert into operation_currency
1143 $operation_currency=new Operation_currency_SQL($this->db);
1144 $operation_currency->oc_amount=bcsub($tot_amount_cur,$acompte);
1145 $operation_currency->oc_vat_amount=0;
1146 $operation_currency->oc_price_unit=0;
1147 $operation_currency->j_id=$let_other;
1148 $operation_currency->insert();
1149
1150 // insert into operation_currency bank
1151 $operation_currency=new Operation_currency_SQL($this->db);
1152 $operation_currency->oc_amount=bcsub($tot_amount_cur,$acompte);
1153 $operation_currency->oc_vat_amount=0;
1154 $operation_currency->oc_price_unit=0;
1155 $operation_currency->j_id=$let_pay;
1156 $operation_currency->insert();
1157
1158 /* insert into jrn */
1159 $acc_pay->mt=$mt;
1160 $acc_pay->desc=(!isset($e_comm_paiement) || noalyss_strlentrim($e_comm_paiement) == 0) ?$e_comm:$e_comm_paiement;
1161
1162 // Add info for currency
1163 $acc_pay->currency_id=$p_currency_code;
1164 $acc_pay->currency_rate=$p_currency_rate;
1165 $acc_pay->currency_rate_ref=$currency_rate_ref->get_rate();
1166
1167
1168 // insert into the table JRN
1169 $mp_jr_id=$acc_pay->insert_jrn();
1170 $this->payment_operation=$mp_jr_id;
1171 $acjrn->jr_grpt_id=$acseq;
1172 $acjrn->update_internal_code($acinternal);
1173 // add an automatic PJ if ODS
1174 if ($acjrn->get_type()=="ODS") {
1175 $acc_pay->pj=$acjrn->guess_pj();
1176 $acc_pay->update_receipt();
1177 }
1178 $r1=$this->get_id($internal);
1179 $r2=$this->get_id($acinternal);
1180
1181 /*
1182 * add lettering
1183 */
1184 $oletter=new Lettering($this->db);
1185 $oletter->insert_couple($let_client,$let_other);
1186
1187 /* set the flag paid */
1188 $Res=$this->db->exec_sql("update jrn set jr_rapt='paid' where jr_id=$1",array($r1));
1189
1190 /* Reconcialiation */
1191 $rec=new Acc_Reconciliation($this->db);
1192 $rec->set_jr_id($r1);
1193 $rec->insert($r2);
1194 /*
1195 * save also into quant_fin
1196 */
1197
1198 /* get ledger property */
1199 $ledger=new Acc_Ledger_Fin($this->db,$acc_pay->jrn);
1200 $prop=$ledger->get_propertie();
1201
1202 /* if ledger is FIN then insert into quant_fin */
1203 if ( $prop['jrn_def_type'] == 'FIN' )
1204 {
1205 $ledger->insert_quant_fin($acfiche->id,$mp_jr_id,$cust->id,bcmul($famount,-1),$let_other);
1206 }
1207
1208
1209 }
1210 /*----------------------------------------------
1211 * Save the note
1212 ----------------------------------------------*/
1213 if (isset($p_array['jrn_note_input']) && !empty($p_array['jrn_note_input'])) {
1214 $acc_operation_note=Acc_Operation_Note::build_jrn_id(-1);
1215 $acc_operation_note->setNote($p_array['jrn_note_input']);
1216 $acc_operation_note->setOperation_id( $this->jr_id);
1217 $acc_operation_note->save();
1218 }
1219 }//end try
1220 catch (Exception $e)
1221 {
1222 record_log($e);
1223 $this->db->rollback();
1224 throw $e;
1225 }
1226 $this->db->commit();
1227 return $internal;
1228 }
1229
1230 /*!\brief display the form for entering data for invoice
1231 *\param $p_array is null or you can put the predef operation or the $_POST
1232 \code
1233 array
1234 'sa' => string 'n' (length=1)
1235 'p_action' => string 'ach' (length=3)
1236 'gDossier' => string '28' (length=2)
1237 'e_client' => string 'ASEKURA' (length=7)
1238 'nb_item' => string '9' (length=1)
1239 'p_jrn' => string '3' (length=1)
1240 'period' => string '126' (length=3)
1241 'e_comm' => string 'descriptio' (length=10)
1242 'e_date' => string '01.05.2010' (length=10)
1243 'e_ech' => string '' (length=0)
1244 'jrn_type' => string 'ACH' (length=3)
1245 'e_pj' => string 'ACH37' (length=5)
1246 'e_pj_suggest' => string 'ACH37' (length=5)
1247 'mt' => string '1273759434.5701' (length=15)
1248 'e_mp' => string '0' (length=1)
1249 'e_march0' => string 'DOC' (length=3)
1250 'e_march0_price' => string '2000' (length=4)
1251 'e_march0_tva_id' => string '3' (length=1)
1252 'e_march0_tva_amount' => string '120' (length=3)
1253 'e_quant0' => string '1' (length=1)
1254 'gen_invoice' => string 'on' (length=2)
1255 'gen_doc' => string '7' (length=1)
1256 'bon_comm' => string '' (length=0)
1257 'other_info' => string '' (length=0)
1258 'correct' => string 'Corriger' (length=8)
1259 \endcode
1260 *\return HTML string
1261 */
1262 public function input($p_array=null,$p_readonly=0)
1263 {
1264 global $g_parameter,$g_user;
1265 // load ledger definition
1266 $this->load();
1267 $http=new HttpInput();
1268 if ( $p_array != null ) extract($p_array, EXTR_SKIP);
1269
1270 $flag_tva=$g_parameter->MY_TVA_USE;
1271
1272 /* Add button */
1273 $str_add_button_tiers = "";
1274 $add_card=FALSE;
1275 if ($g_user->check_action(FICADD) == 1) {
1276 $add_card=TRUE;
1277 $str_add_button_tiers = $this->add_card("cred", "e_client");
1278 }
1279 // The first day of the periode
1280 $oPeriode=new Periode($this->db);
1281 list ($l_date_start,$l_date_end)=$oPeriode->get_date_limit($g_user->get_periode());
1282 if ( $g_parameter->MY_DATE_SUGGEST=='Y' )
1283 $op_date=( ! isset($e_date) ) ?$l_date_start:$e_date;
1284 else
1285 $op_date=( ! isset($e_date) ) ?'':$e_date;
1286
1287 $e_ech=(isset($e_ech))?$e_ech:"";
1288 $e_comm=(isset($e_comm))?$e_comm:"";
1289
1290 $r="";
1291 $r.=dossier::hidden();
1292 $f_legend_detail=_("Détail articles achetés");
1293
1294 // Date
1295 //--
1296 $Date=new IDate();
1297 $Date->setReadOnly(false);
1298 $Date->table=1;
1299 $Date->tabindex=1;
1300 $f_date=$Date->input("e_date",$op_date);
1301 // Payment limit
1302 //--
1303 $Echeance=new IDate();
1304 $Echeance->setReadOnly(false);
1305 $Echeance->tabindex=2;
1307 $f_echeance=$Echeance->input('e_ech',$e_ech,'Echéance'.$label);
1308 $f_periode="";
1309 if ($this->check_periode() == true)
1310 {
1311 // Periode
1312 //--
1313 $l_user_per=$g_user->get_periode();
1314 $def=(isset($periode))?$periode:$l_user_per;
1315
1316 $period=new IPeriod("period");
1317 $period->user=$g_user;
1318 $period->cn=$this->db;
1319 $period->value=$def;
1320 $period->type=OPEN;
1321 try
1322 {
1323 $l_form_per=$period->input();
1324 }
1325 catch (Exception $e)
1326 {
1327 record_log($e);
1328 if ($e->getCode() == 1 )
1329 {
1330 throw new Exception( _("Aucune période ouverte"));
1331 }
1332 }
1333
1334 $r.="<td>";
1336 $f_periode=td(_("Période comptable")." $label ").td($l_form_per);
1337 }
1338 // Ledger (p_jrn)
1339 //--
1340 /* if we suggest the next pj, then we need a javascript */
1341 $add_js="";
1342 if ( $g_parameter->MY_PJ_SUGGEST !='N')
1343 {
1344 $add_js="update_receipt();";
1345 }
1346 if ($g_parameter->MY_DATE_SUGGEST == 'Y')
1347 {
1348 $add_js.='get_last_date();';
1349 }
1350 $add_js.='update_name();';
1351 $add_js.='update_pay_method();';
1352 $add_js.='update_row("sold_item");';
1353 $add_js.='update_other_tax();';
1354 $add_js.='update_visibility_quantity();';
1355
1356 $wLedger=$this->select_ledger('ACH',2,FALSE);
1357
1358 if ($wLedger == null) throw new Exception(_('Pas de journal disponible'));
1359 $wLedger->javascript="onChange='update_predef(\"ach\",\"f\",\"".$http->request("ac")."\");$add_js'";
1360 $wLedger->table=0;
1361 $f_jrn=$wLedger->input();
1362
1363 // Comment
1364 //--
1365 $Commentaire=new IText();
1366 $Commentaire->table=0;
1367 $Commentaire->setReadOnly(false);
1368 $Commentaire->size=60;
1369 $Commentaire->tabindex=3;
1371 $f_desc=$Commentaire->input("e_comm",$e_comm);
1372
1373 // PJ
1374 //--
1375 /* suggest PJ ? */
1376 $default_pj='';
1377 if ( $g_parameter->MY_PJ_SUGGEST !='N')
1378 {
1379 $default_pj=$this->guess_pj();
1380 }
1381
1382 $pj=new IText();
1383 $pj->value=(isset($e_pj))?$e_pj:$default_pj;
1384
1385 if ( $g_parameter->MY_PJ_SUGGEST=='A' || $g_user->check_action(UPDRECEIPT)==0)
1386 {
1387 $pj->setReadOnly(true);
1388 $pj->id="e_pj";
1389 }
1390 $pj->table=0;
1391 $pj->name="e_pj";
1392 $pj->size=10;
1393 $pj->readonly=false;
1394
1395 $f_pj=$pj->input().HtmlInput::hidden('e_pj_suggest',$default_pj);
1396
1397 // Display the customer
1398 //--
1399 $fiche='cred';
1400
1401 // Save old value and set a new one
1402 //--
1403 $e_client=( isset ($e_client) )?$e_client:"";
1404 $e_client_label="&nbsp;";//str_pad("",100,".");
1405
1406
1407 // retrieve e_client_label
1408 //--
1409
1410 if ( noalyss_strlentrim($e_client) != 0)
1411 {
1412 $fClient=new Fiche($this->db);
1413 $fClient->get_by_qcode($e_client);
1414 $e_client_label=$fClient->get_attribute(ATTR_DEF_NAME).' '.
1415 ' Adresse : '.$fClient->get_attribute(ATTR_DEF_ADRESS).' '.
1416 $fClient->get_attribute(ATTR_DEF_POSTCODE).' '.
1417 $fClient->get_attribute(ATTR_DEF_CITY).' ';
1418
1419
1420 }
1421
1422 $W1=new ICard();
1423 $W1->label=_("Fournisseur ").Icon_Action::infobulle(0) ;
1424 $W1->name="e_client";
1425 $W1->tabindex=3;
1426 $W1->value=$e_client;
1427 $W1->table=0;
1428 $W1->set_dblclick("fill_ipopcard(this);");
1429 $W1->set_attribute('ipopup','ipopcard');
1430
1431 // name of the field to update with the name of the card
1432 $W1->set_attribute('label','e_client_label');
1433 // name of the field to update with the name of the card
1434 $W1->set_attribute('typecard','cred');
1435
1436 // Add the callback function to filter the card on the jrn
1437 $W1->set_callback('filter_card');
1438 $W1->set_function('fill_data');
1439 $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
1440 $W1->name);
1441 $f_client_qcode=$W1->input();
1442 $client_label=new ISpan();
1443 $client_label->style="vertical-align:top";
1444 $client_label->table=0;
1445 $f_client=$client_label->input("e_client_label",$e_client_label);
1446 $f_client_bt=$W1->search();
1447
1448
1449 // Record the current number of article
1450
1451 $e_comment=(isset($e_comment))?$e_comment:"";
1452 $p_article= ( isset ($nb_item))?$nb_item:$this->get_min_row();
1453 $p_article=($p_article < $this->get_min_row())?$this->get_min_row():$p_article;
1454
1455 $Hid=new IHidden();
1456 $r.=$Hid->input("nb_item",$p_article);
1457
1458 // For each article
1459 //--
1460 for ($i=0;$i< $p_article ;$i++)
1461 {
1462 // Code id, price & vat code
1463 //--
1464 $march=(isset(${"e_march$i"}))?${"e_march$i"}:"" ;
1465 $march_price=(isset(${"e_march".$i."_price"}))?${"e_march".$i."_price"}:""
1466 ;
1467 /* use vat */
1468 if ( $g_parameter->MY_TVA_USE=='Y')
1469 {
1470 $march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:"";
1471 $march_tva_amount=(isset(${"e_march$i"."_tva_amount"}))?${"e_march$i"."_tva_amount"}:"";
1472 }
1473
1474
1475
1476 $march_label=(isset(${"e_march".$i."_label"}))?${"e_march".$i."_label"}:"";
1477 // retrieve the tva label and name
1478 //--
1479 if ( noalyss_strlentrim($march)!=0 && noalyss_strlentrim($march_label)==0 )
1480 {
1481 $fMarch=new Fiche($this->db);
1482 $fMarch->get_by_qcode($march);
1483 $march_label=$fMarch->get_attribute(ATTR_DEF_NAME);
1484 /* vat use */
1485 if ( ! isset($march_tva_id) && $g_parameter->MY_TVA_USE=='Y' )
1486 $march_tva_id=$fMarch->get_attribute(ATTR_DEF_TVA);
1487 }
1488 // Show input
1489 //--
1490 $W1=new ICard();
1491 $W1->label="";
1492 $W1->name="e_march".$i;
1493 $W1->value=$march;
1494 $W1->table=0;
1495 $W1->setAfter_clean("compute_all_ledger()");
1496 $W1->set_dblclick("fill_ipopcard(this);");
1497 $W1->set_attribute('ipopup','ipopcard');
1498
1499 $W1->set_attribute('typecard','deb');
1500
1501 // name of the field to update with the name of the card
1502 $W1->set_attribute('label','e_march'.$i.'_label');
1503 // name of the field with the price
1504 $W1->set_attribute('purchase','e_march'.$i.'_price'); /* autocomplete */
1505 $W1->set_attribute('price','e_march'.$i.'_price'); /* via search */
1506
1507 // name of the field with the TVA_ID
1508 $W1->set_attribute('tvaid','e_march'.$i.'_tva_id');
1509 // Add the callback function to filter the card on the jrn
1510 $W1->set_callback('filter_card');
1511 $W1->set_function('fill_data');
1512 $W1->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
1513 $W1->name);
1514 $W1->readonly=false;
1515 $array[$i]['quick_code']=$W1->input();
1516 $array[$i]['bt']=$W1->search();
1517 $array[$i]['card_add']=($add_card==TRUE)?$this->add_card("deb", $W1->id):"";
1518
1519 $array[$i]['hidden']='';
1520 // For computing we need some hidden field for holding the value
1521 if ( $g_parameter->MY_TVA_USE=='Y')
1522 {
1523 $array[$i]['hidden'].=HtmlInput::hidden('tva_march'.$i,0);
1524 }
1525
1526 if ( $g_parameter->MY_TVA_USE=='Y')
1527 $tvac=new INum('tvac_march'.$i);
1528 else
1529 $tvac=new IHidden('tvac_march'.$i);
1530
1531 $tvac->readOnly=1;
1532 $tvac->value=0;
1533 $array[$i]['tvac']=$tvac->input();
1534
1535 $htva=new INum('htva_march'.$i);
1536 $htva->readOnly=1;
1537
1538 $htva->value=0;
1539 $array[$i]['htva']=$htva->input();
1540
1541 if ( $g_parameter->MY_UPDLAB == 'Y')
1542 {
1543 $Span=new IText("e_march".$i."_label");
1544 $Span->style='class="input_text label_item"';
1545 } else
1546 {
1547 $Span=new ISpan("e_march".$i."_label");
1548 $Span->extra='class="label_item"';
1549 }
1550 $Span->value=$march_label;
1551 $Span->setReadOnly(false);
1552 // card's name, price
1553 //--
1554 $array[$i]['denom']=$Span->input("e_march".$i."_label",$march_label);
1555 // price
1556 $Price=new INum();
1557 $Price->setReadOnly(false);
1558 $Price->size=9;
1559 $Price->javascript="onblur=\"format_number(this,4);clean_tva($i);compute_ledger($i)\"";
1560 $array[$i]['pu']=$Price->input("e_march".$i."_price",$march_price);
1561 if ( $g_parameter->MY_TVA_USE=='Y')
1562 {
1563
1564 // vat label
1565 //--
1566 $Tva=new ITva_Popup($this->db);
1567 $Tva->id="e_march$i"."_tva_id";
1568 $Tva->js="onblur=\"clean_tva($i);compute_ledger($i)\"";
1569 $Tva->in_table=true;
1570 $Tva->set_attribute('compute',$i);
1571 $Tva->set_filter("purchase");
1572 $Tva->value=$march_tva_id;
1573 $array[$i]['tva']=$Tva->input("e_march$i"."_tva_id");
1574
1575 // Tva_amount
1576
1577 // price
1578 $Tva_amount=new INum();
1579 $Tva_amount->setReadOnly(false);
1580 $Tva_amount->size=9;
1581 $Tva_amount->javascript="onblur=\"format_number(this);compute_ledger($i)\"";
1582 $array[$i]['amount_tva']=$Tva_amount->input("e_march".$i."_tva_amount",$march_tva_amount);
1583 }
1584 // quantity
1585 //--
1586 $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"1"
1587 ;
1588 $Quantity=new INum();
1589 $Quantity->setReadOnly(false);
1590 $Quantity->size=9;
1591 $Quantity->javascript="onchange=\"format_number(this,2);clean_tva($i);compute_ledger($i)\"";
1592 $array[$i]['quantity']=$Quantity->input("e_quant".$i,$quant);
1593
1594 }
1595 $f_type=_('Fournisseur');
1596
1597 // Currency
1598 $currency_select = $this->CurrencyInput("currency_code", "p_currency_rate" , "p_currency_euro");
1599 $currency_select->selected=$http->request('p_currency_code','string',0);
1600
1601 $currency_input=new INum("p_currency_rate");
1602 $currency_input->prec=8;
1603 $currency_input->id="p_currency_rate";
1604 $currency_input->value=$http->request('p_currency_rate','string',1);
1605 $currency_input->javascript='onchange="format_number(this,6);CurrencyCompute(\'p_currency_rate\',\'p_currency_euro\');"';
1606
1607 $currency=new Acc_Currency($this->db,0);
1608
1609 //
1610 // Button for template operation
1611 //
1612 ob_start();
1613 echo '<div id="predef_form">';
1614 echo HtmlInput::hidden('p_jrn_predef', $this->id);
1615 $op = new Pre_operation($this->db);
1616 $op->set_p_jrn($this->id);
1617 $op->set_jrn_type("ACH");
1618 $op->set_od_direct('f');
1619 $url=http_build_query(array('p_jrn_predef'=>$this->id,'ac'=>$http->request('ac'),'gDossier'=>dossier::id()));
1620 echo $op->form_get('do.php?'.$url);
1621 echo '</div>';
1622 $str_op_template=ob_get_contents();
1623 ob_end_clean();
1624
1625 ob_start();
1626 require_once NOALYSS_TEMPLATE.'/form_ledger_detail.php';
1627 $r.=ob_get_contents();
1628 ob_end_clean();
1629
1630 // Set correctly the REQUEST param for jrn_type
1631 $r.= HtmlInput::hidden('jrn_type','ACH');
1633
1634
1635
1636 /* if we suggest the pj n# the run the script */
1637 if ( $g_parameter->MY_PJ_SUGGEST !='N')
1638 {
1639 $r.='<script> update_receipt();</script>';
1640 }
1641 // set focus on date
1642 $r.= create_script("$('".$Date->id."').focus()");
1643 $r.='<div id="additional_tax_div">';
1644 $r.=$this->input_additional_tax();
1645 $r.='</div>';
1646 return $r;
1647 }
1648
1649 /*!@brief show the summary of the operation and propose to save it
1650 *@param array contains normally $_POST. It proposes also to save
1651 * the Analytic accountancy
1652 * @param $p_summary true to confirm false, show only the result in RO
1653 *@return string
1654 */
1655 function confirm($p_array,$p_summary=false)
1656 {
1657 global $g_parameter,$g_user;
1658 extract ($p_array,EXTR_SKIP);
1659 if ( !isset($p_array['jrn_note_input'])) {$p_array['jrn_note_input']='';}
1660 // we don't need to verify if we need only a feedback
1661 if ( ! $p_summary ){$this->verify($p_array) ;}
1662
1663 $anc=null;
1664 // to show a select list for the analytic
1665 // if analytic is op (optionnel) there is a blank line
1666
1667 bcscale(4);
1668 $client=new Fiche($this->db);
1669 $client->get_by_qcode($e_client,true);
1670
1671 $client_name=h($client->getName().
1672 ' '.$client->get_attribute(ATTR_DEF_ADRESS).' '.
1673 $client->get_attribute(ATTR_DEF_POSTCODE).' '.
1674 $client->get_attribute(ATTR_DEF_CITY));
1675 $lPeriode=new Periode($this->db);
1676 if ($this->check_periode() == true)
1677 {
1678 $lPeriode->p_id=$period;
1679 }
1680 else
1681 {
1682 $lPeriode->find_periode($e_date);
1683 }
1684 $date_limit=$lPeriode->get_date_limit();
1685 $r="";
1686 $r .= '<div id="summary_op1">';
1687 $r.='<TABLE>';
1688 if ( $p_summary ) {
1689 $jr_id=$this->db->get_value('select jr_id from jrn where jr_internal=$1',array($this->jr_internal));
1690 $r.="<tr>";
1691 $r.='<td>';
1692 $r.=_('Détail opération ');
1693 $r.='</td>';
1694 $r.='<td>';
1695 $r.=sprintf ('<a class="line" style="display:inline" href="javascript:modifyOperation(%d,%d)">%s</a>',
1696 $jr_id,dossier::id(),$this->jr_internal);
1697 $r.='</td>';
1698 $r.="</tr>";
1699 }
1700 $r.='<tr>';
1701
1703 if ( ! $p_summary) {
1704 $r.='<td>' . _('Numéro Pièce') .$span.'</td><td>'. hb($e_pj) . '</td>';
1705 } else {
1706 if ( $g_parameter->MY_PJ_SUGGEST=="A" || $g_user->check_action(UPDRECEIPT)==0) $e_pj=$this->pj;
1707
1708 if ( strcmp($this->pj,$e_pj) != 0 )
1709 {
1710 $r.='<td>' . _('Numéro Pièce').$span .'</td><td>'. hb($this->pj) .
1711 '<span class="notice"> '._('Attention numéro pièce existante, elle a du être adaptée').'</span></td>';
1712 } else {
1713 $r.='<td>' . _('Numéro Pièce') .$span.'</td><td>'. hb($this->pj) . '</td>';
1714 }
1715 }
1716 $r.='</tr>';
1717 $r.='<td> ' . _('Date') . '</td><td> ' . hb($e_date) . '</td>';
1718 $r.='</tr>';
1719 $r.='<tr>';
1720 $r.='<td>' . _('Echeance') . '</td><td> ' . hb($e_ech) . '</td>';
1721 $r.='</tr>';
1722
1723
1724 $r.='<tr>';
1725 $r.='<td> ' . _('Période Comptable') . '</td><td> ' .hb( $date_limit['p_start'] . '-' . $date_limit['p_end']) . '</td>';
1726 $r.='</tr>';
1727 $r.='</table>';
1728 $r.='</div>';
1729 $r .= '<div id="summary_op2">';
1730 $r.='<table>';
1731 $r.='<tr>';
1732 $r.='<td> ' . _('Journal') . '</td><td> ' . hb($this->get_name()) . '</td>';
1733 $r.='</tr>';
1734 $r.='<tr>';
1735 $r.='<td> ' . _('Libellé') . '</td><td> ' . hb($e_comm) . '</td>';
1736 $r.='</tr>';
1737 $r.='<tr>';
1738
1739 $r.='<tr>';
1740 $r.='<td> ' . _('Fournisseur') . '</td><td> ' . hb($e_client . ':' . $client_name) . '</td>';
1741 $r.='</tr>';
1742 $r.='</table>';
1743 $r.='<pre>'._('Note').' '.h($p_array['jrn_note_input']).'</pre>';
1744 $r.='</div>';
1745 $r.='<div style="position:float;clear:both">';
1746 $r.='</div>';
1747 $r.='<h2>' . _('Détail articles achetés') . '</h2>';
1748 $r.='<p class="decale">';
1749 $r.='<table class="result" >';
1750 $r.='<TR>';
1751 $r.="<th>" . _('Code') . "</th>";
1752 $r.="<th>" . _('Dénomination') . "</th>";
1753 $r.="<th style=\"text-align:right\">" . _('prix') . "</th>";
1754 $r.="<th style=\"text-align:right\">" . _('quantité') . "</th>";
1755
1756
1757 if ($g_parameter->MY_TVA_USE == 'Y') {
1758 $r.="<th style=\"text-align:right\">" . _('tva') . "</th>";
1759 $r.='<th style="text-align:right"> ' . _('Montant TVA') . '</th>';
1760 $r.='<th style="text-align:right">' . _('Montant HTVA') . '</th>';
1761 $r.='<th style="text-align:right">' . _('Montant TVAC') . '</th>';
1762 } else {
1763 $r.='<th style="text-align:right">' . _('Montant') . '</th>';
1764 }
1765
1766 /* if we use the AC */
1767 if ($g_parameter->MY_ANALYTIC!='nu')
1768 {
1769 $anc=new Anc_Plan($this->db);
1770 $a_anc=$anc->get_list();
1771 $x=count($a_anc);
1772 /* set the width of the col */
1773 $r.='<th colspan="'.$x.'">'._('Compt. Analytique').'</th>';
1774
1775 /* add hidden variables pa[] to hold the value of pa_id */
1776 $r.=Anc_Plan::hidden($a_anc);
1777 }
1778
1779 $r.='</tr>';
1780 $tot_amount=0.0;
1781 $tot_tva=0.0;
1782 //--
1783 // For each item
1784 //--
1785 for ($i = 0; $i < $nb_item;$i++)
1786 {
1787 $tot_row=0;
1788 if ( noalyss_strlentrim(${"e_march".$i}) == 0 ) continue;
1789
1790 /* retrieve information for card */
1791 $fiche=new Fiche($this->db);
1792 $fiche->get_by_qcode(${"e_march".$i});
1793 if ( $g_parameter->MY_UPDLAB=='Y')
1794 $fiche_name=h(${"e_march".$i."_label"});
1795 else
1796 $fiche_name=$fiche->get_attribute (ATTR_DEF_NAME);
1797 $amount=bcmul(${"e_march".$i."_price"},${'e_quant'.$i});
1798 if ( $g_parameter->MY_TVA_USE=='Y')
1799 {
1800 $idx_tva=${"e_march".$i."_tva_id"};
1801 $oTva=Acc_Tva::build($this->db,$idx_tva);
1802
1803 $oTva->load();
1804 $op=new Acc_Compute();
1805
1806 $op->set_parameter("amount",$amount);
1807 $op->set_parameter('amount_vat_rate',$oTva->get_parameter('rate'));
1808 $op->compute_vat();
1809 $tva_computed=$op->get_parameter('amount_vat');
1810 //----- if tva_amount is not given we compute the vat ----
1811 if ( strlen (trim (${'e_march'.$i.'_tva_amount'})) == 0)
1812 {
1813 $tva_item=$op->get_parameter('amount_vat');
1814 }
1815 else
1816 $tva_item=round(${'e_march'.$i.'_tva_amount'},2);
1817
1818 if (isset($tva[$idx_tva] ) )
1819 $tva[$idx_tva]=bcadd($tva_item,$tva[$idx_tva]);
1820 else
1821 $tva[$idx_tva]=$tva_item;
1822
1823
1824
1825 }
1826 $tot_amount=round(bcadd($tot_amount,$amount),2);
1827 $tot_row=round(bcadd($tot_row,$amount),2);
1828 $r.='<tr>';
1829 $r.='<td>';
1830 $r.=${"e_march".$i};
1831 $r.='</td>';
1832 $r.='<TD style="border-bottom:1px dotted grey;">';
1833 $r.=$fiche_name;
1834 $r.='</td>';
1835 $r.='<td class="num">';
1836 $r.=nbm(${"e_march".$i."_price"},4);
1837 $r.='</td>';
1838 $r.='<td class="num">';
1839 $r.=nbm(${"e_quant".$i},4);
1840 $r.='</td>';
1841 $both_side=0;
1842 if ($g_parameter->MY_TVA_USE == 'Y')
1843 {
1844 $r.='<td class="num">';
1845 $r.=$oTva->get_parameter('label');
1846 $both_side=$oTva->get_parameter("both_side");
1847 if ( $both_side == 0) {
1848 $tot_row=bcadd($tot_row,$tva_item);
1849 $tot_tva=round(bcadd($tva_item,$tot_tva),2);
1850 }
1851 $r.='</td>';
1852 /* warning if tva_computed and given are not the
1853 same */
1854 $css_void_tva=($both_side == 1)?'style="text-decoration:line-through"':'';
1855 if ( bcsub($tva_item,$tva_computed) != 0 && ! ($tva_item == 0 && $both_side == 1))
1856 {
1857
1858 $r.='<td style="background-color:red" class="num" '.$css_void_tva.'>';
1860 $r.='<a href="#" class="error" style="display:inline" title="'. _("Attention Différence entre TVA calculée et donnée").'">'
1861 .nbm($tva_item).'<a>';
1862 }
1863 else{
1864 $r.='<td class="num" '.$css_void_tva.'>';
1865 $r.=nbm($tva_item);
1866 }
1867 $r.='</td>';
1868 $r.='<td class="num"> ';
1869 $r.=nbm(round($amount,2));
1870 $r.='</td>';
1871 }
1872 $r.='<td class="num">';
1873 $r.=nbm(round($tot_row,2));
1874 $r.='</td>';
1875 // encode the pa
1876 if ( $g_parameter->MY_ANALYTIC!='nu'
1877 && $g_parameter->match_analytic($fiche->get_attribute(ATTR_DEF_ACCOUNT))==TRUE
1878 ) // use of AA
1879 {
1880 // show form
1881 $anc_op=new Anc_Operation($this->db);
1882 $null=($g_parameter->MY_ANALYTIC=='op')?1:0;
1883 $r.='<td>';
1884 $p_mode=($p_summary==false)?1:0;
1885 $p_array['pa_id']=$a_anc;
1886 /* op is the operation it contains either a sequence or a jrnx.j_id */
1887 $r.=HtmlInput::hidden('op[]=',$i);
1888 $r.=$anc_op->display_form_plan($p_array,$null,$p_mode,$i,round($amount,2));
1889 $r.='</td>';
1890 }
1891
1892
1893 $r.='</tr>';
1894
1895 }
1896 // Add the sum
1897 $decalage=($g_parameter->MY_TVA_USE == 'Y')?'<td></td><td></td><td></td><td></td>':'<td></td>';
1898 $tot = round(bcadd($tot_amount, $tot_tva), 2);
1899 $str_tot=_('Totaux');
1900 $tot_eur=round(bcdiv($tot, $p_currency_rate),2);
1901
1902 // Get currency code
1903 $default_currency=new Acc_Currency($this->db,0);
1904 $str_code=$default_currency->get_code();
1905 if ( $p_currency_code != 0 ) {
1906 $acc_currency=new Acc_Currency($this->db);
1907 $acc_currency->set_id($p_currency_code);
1908 $str_code=$acc_currency->get_code();
1909 }
1910 // Format amount
1912 $tot_tva=nbm($tot_tva);
1913 $tot_str=nbm($tot);
1914
1915 if ( $g_parameter->MY_TVA_USE == 'Y') {
1916 $r.=<<<EOF
1917<tr class="highlight">
1918 {$decalage}
1919 <td>
1920 {$str_tot} {$str_code}
1921 </td>
1922 <td class="num">
1923 {$tot_tva}
1924 </td>
1925 <td class="num">
1926 {$tot_amount}
1927 </td>
1928 <td class="num">
1929 {$tot_str} {$str_code}
1930 </td>
1931</tr>
1932EOF;
1933 if ($p_currency_code !=0) {
1934 $sql_currency=new Currency_SQL($this->cn,0);
1935 $iso_code=$sql_currency->getp("cr_code_iso");
1936 $rate=_("Taux ");
1937 $r.=<<<EOF
1938 <tr class="highlight">
1939 {$decalage}
1940 <td>
1941
1942 </td>
1943 <td class="num">
1944
1945 </td>
1946 <td class="num">
1947 {$rate} {$p_currency_rate}
1948 </td>
1949 <td class="num">
1950 {$tot_eur} {$iso_code}
1951 </td>
1952 </tr>
1953 EOF;
1954 } // if ($p_currency_code !=0
1955 }else // if $g_parameter->MY_TVA_USE=='Y'
1956 {
1957 $sql_currency=new Currency_SQL($this->cn,0);
1958 $iso_code=$sql_currency->getp("cr_code_iso");
1959 $r.=<<<EOF
1960<tr class="highlight">
1961 {$decalage}
1962 <td>
1963 {$str_tot} {$str_code}
1964 </td>
1965 <td class="num">
1966 {$tot_amount}
1967 </td>
1968 <td class="num">
1969
1970 </td>
1971 <td class="num">
1972 {$tot_str} {$str_code}
1973 </td>
1974</tr>
1975<tr class="highlight">
1976 {$decalage}
1977 <td>
1978 </td>
1979 <td>
1980 </td>
1981 <td>
1982 </td>
1983 <td class="num">
1984 {$tot_str} {$iso_code}
1985 </td>
1986</tr>
1987EOF;
1988
1989 }
1990 $r.='</table>';
1991 $r.='</p>';
1992 if ( $g_parameter->MY_ANALYTIC!='nu' && !$p_summary) // use of AA
1993 $r.='<input type="button" class="button" value="'._('Vérifiez imputation analytique').'" onClick="verify_ca(\'\');">';
1994
1995 $r.='<div id="total_div_id" >';
1996 $r.='<h2>Totaux</h2>';
1997 $other_tax_label="";
1999 if ( $this->has_other_tax() && isset($p_array['other_tax'])) {
2000 $other_tax_label=_("Autre taxe");
2001 $other_tax_amount=htmlspecialchars($p_array['other_tax_amount']);
2002 }
2003 /* use VAT */
2004 if ($g_parameter->MY_TVA_USE == 'Y') {
2005 $r.='<table>';
2006 $r.='<tr><td>Total HTVA</td>';
2007 $r.=td(hb($tot_amount ),'class="num"');
2008 foreach ($tva as $i => $value) {
2009 $oTva=Acc_Tva::build($this->db,$i);
2010 $oTva->load();
2011
2012 $r.='<tr><td> TVA ' . $oTva->get_parameter('label').'</td>';
2013 $r.=td(hb(nbm($tva[$i])),'class="num"');
2014 }
2015 $r.='<tr>'.td(_('Total TVA')).td(hb($tot_tva),'class="num"');
2016 if ( ! empty($other_tax_label) ) {
2017 $r.='<tr>'.td($other_tax_label).td(hb($other_tax_amount),'class="num"');
2018 }
2019 if ( $other_tax_amount!="") {$tot=bcadd($tot,$other_tax_amount,2);}
2020 $r.='<tr>'.td(_('Total TVAC')).td(hb($tot),'class="num"');
2021 $r.='</table>';
2022 } else {
2023 if ( ! empty($other_tax_label) ) {
2024 $r.='<tr>'.td($other_tax_label).td(hb($other_tax_amount),'class="num"');
2025 }
2026 if ( $other_tax_amount!="") {$tot=bcadd($tot,$other_tax_amount,2);}
2027 $r.='<br>Total '.hb($tot);
2028 }
2029 $r.='</div>';
2030 /* Add hidden */
2031 $r.=HtmlInput::hidden('e_client',$e_client);
2032 $r.=HtmlInput::hidden('nb_item',$nb_item);
2033 $r.=HtmlInput::hidden('p_jrn',$p_jrn);
2034 $r.=HtmlInput::hidden('jrn_note_input',h($p_array['jrn_note_input']));
2035
2036 if ( isset($period))
2037 $r.=HtmlInput::hidden('period',$period);
2038 $r.=HtmlInput::hidden('e_comm',$e_comm);
2039 $r.=HtmlInput::hidden('e_date',$e_date);
2040 $r.=HtmlInput::hidden('e_ech',$e_ech);
2041 $r.=HtmlInput::hidden('jrn_type',$jrn_type);
2042 $r.=HtmlInput::hidden('e_pj',$e_pj);
2043 $r.=HtmlInput::hidden('e_pj_suggest',$e_pj_suggest);
2044 $r.=HtmlInput::post_to_hidden(['p_currency_rate','p_currency_code']);
2045 if ( $this->has_other_tax() && isset($p_array["other_tax"])) {
2046 $r.=HtmlInput::hidden("other_tax",$p_array['other_tax']);
2047 $r.=HtmlInput::hidden("other_tax_amount",$p_array['other_tax_amount']);
2048 }
2049 $mt=microtime(true);
2050 $r.=HtmlInput::hidden('mt',$mt);
2051
2052 $e_mp=(isset($e_mp))?$e_mp:0;
2053 $r.=HtmlInput::hidden('e_mp',$e_mp);
2054 /* Paid by */
2055 /* if the paymethod is not 0 and if a quick code is given */
2056
2057
2058 for ($i=0;$i < $nb_item;$i++)
2059 {
2060 $r.=HtmlInput::hidden("e_march".$i,${"e_march".$i});
2061 if (isset (${"e_march".$i."_label"})) $r.=HtmlInput::hidden("e_march".$i."_label",${"e_march".$i."_label"});
2062 $r.=HtmlInput::hidden("e_march".$i."_price",${"e_march".$i."_price"});
2063 if ( $g_parameter->MY_TVA_USE=='Y' )
2064 {
2065 $r.=HtmlInput::hidden("e_march".$i."_tva_id",${"e_march".$i."_tva_id"});
2066 $r.=HtmlInput::hidden('e_march'.$i.'_tva_amount', ${'e_march'.$i.'_tva_amount'});
2067 }
2068 $r.=HtmlInput::hidden("e_quant".$i,${"e_quant".$i});
2069
2070 }
2071
2072 /**
2073 * Payment method
2074 */
2075 if ( $e_mp!=0 && strlen (trim (${'e_mp_qcode_'.$e_mp})) != 0 )
2076 {
2077 $r.="<p>";
2078 $r.=HtmlInput::hidden('e_mp_qcode_'.$e_mp,${'e_mp_qcode_'.$e_mp});
2079 $r.=HtmlInput::hidden('acompte',$acompte);
2080 $r.=HtmlInput::hidden('e_comm_paiement',$e_comm_paiement);
2081 $r.=HtmlInput::hidden('mp_date',$mp_date);
2082 /* needed for generating a invoice */
2083 $r.=HtmlInput::hidden('qcode_benef', ${'e_mp_qcode_' . $e_mp});
2084 $fname = new Fiche($this->db);
2085 $fname->get_by_qcode(${'e_mp_qcode_' . $e_mp});
2086 $detail_payment="";
2087 // payment operation
2088 if ($this->payment_operation != 1) {
2089 $pay_internal=$this->db->get_value("select jr_internal from jrn where jr_id=$1",
2090 [$this->payment_operation]);
2091 $detail_payment=HtmlInput::detail_op($this->payment_operation,$pay_internal);
2092 }
2093 $r.='<h2>' . _("Payé par")." " . ${'e_mp_qcode_' . $e_mp} .
2094 " " . $fname->getName() .$detail_payment. '</h2> ' ;
2095 $r.='<p class="decale">' . _('Déduction acompte ') . h($acompte) . '</p>' .
2096 _('Libellé :') . h($e_comm_paiement) ;
2097 $r.='<br>';
2098 $r.='<br>';
2099
2100 $r.="</p>";
2101 }
2102 // check for upload piece
2103 /*
2104 * warning if the amount is positive and expecting a negative one
2105 */
2106 $negative=$this->display_negative_warning($tot);
2107 if ( $negative != "") {
2108 $r.=span($negative,'class="warning" ');
2109 }
2110 return $r;
2111 }
2112
2113 /*!\brief the function extra info allows to
2114 * - add a attachment
2115 * - generate an invoice
2116 * - insert extra info
2117 *\return html string
2118 */
2119 public function extra_info()
2120 {
2121 $r="";
2122 $r = '<div id="facturation_div_id" class="conf_op_extra_info">';
2123 $r.='<p class="decale">';
2124 // check for upload piece
2125 $file=new IFile();
2126 $file->setAlertOnSize(true);
2127 $file->table=0;
2128 $r.=_("Ajoutez une pièce justificative ");
2129 $r.=$file->input("pj","");
2130
2131 if ( $this->db->count_sql("select md_id,md_name from document_modele where md_affect='ACH'") > 0 )
2132 {
2133
2134 $r.=_('ou générer un document').' <input type="checkbox" name="gen_invoice" >';
2135 // We propose to generate the fee note
2136 $doc_gen=new ISelect();
2137 $doc_gen->name="gen_doc";
2138 $doc_gen->value=$this->db->make_array(
2139 "select md_id,md_name ".
2140 " from document_modele where md_affect='ACH' order by 2");
2141 $r.=$doc_gen->input().'<br>';
2142 }
2143 $r.='</p>';
2145 $r.='<p>';
2146 $obj=new IText();
2147 $r.=_('Numero de bon de commande : ').$obj->input('bon_comm').'<br>';
2148 $r.=_('Autre information : ').$obj->input('other_info').'<br>';
2149 $r.='</p>';
2150 $r.='</div>';
2151 return $r;
2152 }
2153
2154
2155 /**
2156 * @brief update the payment
2157 * @todo to remove, obsolete
2158 * @deprecated
2159 */
2160 function show_unpaid_deprecated()
2161 {
2162 // Show list of unpaid sell
2163 // Date - date of payment - Customer - amount
2164 // Nav. bar
2165 $step=$_SESSION[SESSION_KEY.'g_pagesize'];
2166 $page=(isset($_GET['offset']))?$_GET['page']:1;
2167 $offset=(isset($_GET['offset']))?$_GET['offset']:0;
2168
2169
2171 list($max_line,$list)=$this->list_operation($sql,null,$offset,1);
2172 $sql=SQL_LIST_UNPAID_INVOICE." and jr_def_id=".$this->id ;
2173 list($max_line2,$list2)=$this->list_operation($sql,null,$offset,1);
2174
2175 // Get the max line
2176 $m=($max_line2>$max_line)?$max_line2:$max_line;
2177 $bar2=navigation_bar($offset,$m,$step,$page);
2178
2179 echo $bar2;
2180 echo '<h2 class="info"> '._('Echeance dépassée').' </h2>';
2181 echo $list;
2182 echo '<h2 class="info"> '._('Non Payée').' </h2>';
2183 echo $list2;
2184 echo $bar2;
2185 // Add hidden parameter
2186 $hid=new IHidden();
2187
2188 echo '<hr>';
2189
2190 if ( $m != 0 )
2191 echo HtmlInput::submit('paid',_('Mise à jour paiement'));
2192
2193
2194 }
2195 /**
2196 * Retrieve data from the view v_detail_purchase
2197 * @note $g_user connected user
2198 * @param $p_from jrn.jr_tech_per from
2199 * @param $p_end jrn.jr_tech_per to
2200 * @return handle to database result
2201 */
2202 function get_detail_purchase($p_from,$p_end,$p_filter_operation='all')
2203 {
2204 global $g_user;
2205 // Journal valide
2206 if ( $this->id == 0 ) die (__FILE__.":".__LINE__." Journal invalide");
2207 switch ( $p_filter_operation)
2208 {
2209 case 'all':
2210 $sql_filter="";
2211 break;
2212 case 'paid':
2213 $sql_filter=" and (jr_date_paid is not null or jr_rapt ='paid' ) ";
2214 break;
2215 case 'unpaid':
2216 $sql_filter=" and (jr_date_paid is null and coalesce(jr_rapt,'x') <> 'paid' ) ";
2217 break;
2218 default:
2219 throw new Exception(_("Filtre invalide",5));
2220
2221 }
2222
2223 // get the data from the view
2224 $sql = "select *
2225 from v_detail_purchase
2226 where
2227 jr_def_id = $1
2228 and jr_date >= (select p_start from parm_periode where p_id = $2)
2229 {$sql_filter}
2230 and jr_date <= (select p_end from parm_periode where p_id = $3) "
2231 .' order by jr_date,substring(jr_pj_number,\'[0-9]+$\')::numeric asc ';
2232 $ret = $this->db->exec_sql($sql, array($this->id,$p_from, $p_end));
2233 return $ret;
2234 }
2235 /**
2236 * @brief compute an array with the heading cells for the
2237 * details, used for the export in CSV
2238 * @return array
2239 */
2240 static function heading_detail_purchase()
2241 {
2242 $array['jr_id'] = _('Numéro opération');
2243 $array['jr_date'] = _('Date');
2244 $array['jr_date_paid'] = _('Date paiement');
2245 $array['jr_ech'] = _('Date échéance');
2246 $array['jr_tech_per'] = _('Période');
2247 $array['jr_comment'] = _('Libellé');
2248 $array['jr_pj_number'] = _('Pièce');
2249 $array['jr_internal'] = _('Interne');
2250 $array['jr_def_id'] = _('Code journal');
2251 $array['j_poste'] = _('Poste');
2252 $array['j_text'] = _('Commentaire');
2253 $array['j_qcode'] = _('Code Item');
2254 $array['jr_rapt'] = _('Payé');
2255 $array['item_card'] = _('N° fiche');
2256 $array['item_name'] = _('Nom fiche');
2257 $array['qp_supplier'] = _('N° fiche fournisseur');
2258 $array['tiers_name'] = _('Nom fournisseur');
2259 $array['quick_code'] = _('Code fournisseur');
2260 $array['tva_label'] = _('Nom TVA');
2261 $array['tva_comment'] = _('Commentaire TVA');
2262 $array['tva_both_side'] = _('TVA annulée');
2263 $array['vat_sided'] = _('TVA Non Payé');
2264 $array['vat_code'] = _('Code TVA');
2265 $array['vat'] = _('Montant TVA');
2266 $array['price'] = _('Total HTVA');
2267 $array['quantity'] = _('quantité');
2268 $array['price_per_unit'] = _('PU');
2269 $array['non_ded_amount'] = _('Montant ND');
2270 $array['non_ded_tva'] = _('Montant TVA ND');
2271 $array['non_ded_tva_recup'] = _('TVA récup.');
2272 $array['htva'] = _('HTVA Opération');
2273 $array['tot_vat'] = _('TVA Opération');
2274 $array['tot_tva_np'] = _('TVA NP opération');
2275 $array['other_tax'] = _("Autre taxe");
2276 $array['oc_amount'] = _('Mont. Devise');
2277 $array['oc_vat_amount'] = _('Mont. TVA Devise');
2278 $array['cr_code_iso'] = _('Devise');
2279
2280 return $array;
2281 }
2282
2283
2284}
2285
2286
2287
2288
2289
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,...")
$_GET['qcode']
Manage the account from the table jrn, jrnx or tmp_pcmn.
this class aims to compute different amount
compute_nd()
Compute the no deductible part of the amount, it reduce also the vat.
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 purchase the $_POST data is an array with these ...
insert($p_array=null)
insert into the database, it calls first the verify function change the value of this->jr_id and this...
insert_no_deductible(Acc_Compute $p_nd_amount, Fiche $p_fiche, $p_tva_both, &$p_tot_debit, Acc_Operation $p_acc_operation, $p_group, $idx)
Insert into JRNX the No Deductible amount and into Analytic Accountancy for the ND VAT.
__construct($p_cn, $p_init)
construct
input($p_array=null, $p_readonly=0)
display the form for entering data for invoice
compute_no_deductible(Acc_Compute $p_nd_amount, Fiche $p_fiche)
Compute the ND amount thanks the attribute of the concerned card.
verify_operation($p_array)
verify that the data are correct before inserting or confirming
confirm($p_array, $p_summary=false)
show the summary of the operation and propose to save it
Class for jrn, class acc_ledger for manipulating the ledger AND some acc.
input_supplemental_document()
display INPUT type to ask the supplementary documents
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...
find_label($p_value)
Retrieve the label of an accounting.
create_document($internal, $p_array)
alias for Acc_Document->create_document
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.
update_internal_code($p_internal)
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...
insert_jrnx()
Insert into the table Jrn The needed data are :
Manage the table parm_code which contains the custom parameter for the module accountancy.
Handle the table payment_method.
new class for managing the reconciliation it must be used instead of the function InsertRapt,...
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...
empty_attribute($p_attr)
check if an attribute is empty
get_attribute($p_ad_id, $p_return=1)
return the string of the given attribute (attr_def.ad_id)
static ledger_add_item($p_ledger)
Build a HTML string for adding multiple rows.
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
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_TVA_NON_DEDUCTIBLE_RECUP
Definition constant.php:243
const ATTR_DEF_ACCOUNT_ND_TVA_ND
Definition constant.php:249
const ATTR_DEF_NAME
Definition constant.php:223
const SQL_LIST_UNPAID_INVOICE
Definition constant.php:341
const ATTR_DEF_ACCOUNT_ND
Definition constant.php:251
const ATTR_DEF_ACCOUNT_ND_TVA
Definition constant.php:248
const ATTR_DEF_TVA
Definition constant.php:228
const SQL_LIST_UNPAID_INVOICE_DATE_LIMIT
Definition constant.php:345
const ATTR_DEF_POSTCODE
Definition constant.php:231
const ATTR_DEF_ACCOUNT_ND_PERSO
Definition constant.php:250
const ATTR_DEF_DEP_PRIV
Definition constant.php:240
const ATTR_DEF_TVA_NON_DEDUCTIBLE
Definition constant.php:242
const ATTR_DEF_CITY
Definition constant.php:236
const EXC_BALANCE
Definition constant.php:362
const ATTR_DEF_DEPENSE_NON_DEDUCTIBLE
Definition constant.php:241
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
$str_file
$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...
navigation_bar($p_offset, $p_line, $p_size=0, $p_page=1, $p_javascript="")
Create a navigation_bar (pagesize)