noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
acc_operation.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/*!\file
23 * \brief this file match the tables jrn & jrnx the purpose is to
24 * remove or save accountant writing to these table.
25 */
26
27/*!
28 * @class Acc_Operation
29 * \brief this file match the tables jrn & jrnx the purpose is to
30 * remove or save accountant writing to these table.
31 *
32 */
34{
35 var $db; /*!< database connx */
36 var $jr_id; /*!< pk of jrn */
37 var $jrn_id; /*!< jrn_def_id */
38 var $debit; /*!< debit or credit */
39 var $user; /*!< current user */
40 var $jrn; /*!< the ledger to use */
41 var $poste; /*!< account */
42 var $date; /*!< the date */
43 var $periode; /*!< periode to use */
44 var $amount; /*!< amount of the operatoin */
45 var $grpt; /*!< the group id */
47 var $jr_optype; /*!< type of operation :NOR,CLO,EXT,OPE */
48 var $currency_rate; /*< currency rate used */
49 var $currency_id; /*< currency id */
50 var $currency_rate_ref; /*< currency rate in the table currency*/
51 //!< Qcode of item
52 var $qcode;
53 //!< internal code from jrn
56 var $desc;
57 var $type;
60 var $pj;
61 var $mt;
62 var $f_id;
63 /*!
64 * \brief constructor set automatically the attributes user and periode
65 * \param $p_cn the databse connection
66 */
67 function __construct($p_cn,$p_jrid=0)
68 {
69 global $g_user;
70 $this->db=$p_cn;
71 $this->qcode="";
72 $this->user=$_SESSION[SESSION_KEY.'g_user'];
73 $this->periode=$g_user->get_periode();
74 $this->jr_id=$p_jrid;
75 $this->jr_optype="NOR";
76 $this->amount=0;
77 $this->currency_rate=1;
78 $this->currency_rate_ref=1;
79 $this->currency_id=NULL;
80 }
81
82 function __toString(): string
83 {
84 $r=<<<EOF
85 Acc_Operation Object
86 [
87
88 qcode {$this->qcode}
89 user {$this->user}
90 periode {$this->periode}
91 jr_id {$this->jr_id}
92 jr_optype {$this->jr_optype}
93 amount {$this->amount}
94 currency_rate {$this->currency_rate}
95 currency_rate_ref {$this->currency_rate_ref}
96 currency_id {$this->currency_id}
97 ]
98EOF;
99 return $r;
100
101 }
102
103 /**
104 *@brief retrieve the grpt_id from jrn for a jr_id
105 *@return jrn.jr_grpt_id or an empty string if not found
106 */
107 function seek_group()
108 {
109 $ret=$this->db->get_value('select jr_grpt_id from jrn where jr_id=$1',
110 array($this->jr_id));
111 return $ret;
112 }
113 /**
114 * \brief prepare the query for getting the qcode of the tiers, when
115 * executing this SQL , an array of (jrn.jr_id , jrnx.j_id) must be
116 * provided
117 */
118 private function prepare_sql_tiers()
119 {
120 // prepare for getting the tiers
121 $this->db->prepare('prep_tiers',"select fiche_detail.f_id,ad_value from
122 fiche_detail
123 join (select qf_other as f_id
124 from quant_fin
125 where
126 quant_fin.jr_id = $1
127 union all
128 select qp_supplier as f_id
129 from quant_purchase
130 where quant_purchase.j_id=$2
131 union all
132 select qs_client as f_id
133 from quant_sold
134 where quant_sold.j_id=$2 ) as v_fiche on (fiche_detail.f_id=v_fiche.f_id) where ad_id=23 ");
135 }
136 /**
137 * \brief prepare the query for getting the qcode of the tiers, when
138 * executing this SQL , an array of (jrn.jr_id , jrnx.j_id) must be
139 * provided
140 */
141 private function prepare_sql_counterpart()
142 {
143 // prepare for getting the tiers
144 $this->db->prepare('prep_counterpart',"select fiche_detail.f_id,ad_value from
145 fiche_detail
146 join (select qf_bank as f_id
147 from quant_fin
148 where
149 quant_fin.jr_id = $1
150 union all
151 select qp_fiche as f_id
152 from quant_purchase
153 where quant_purchase.j_id=$2
154 union all
155 select qs_fiche as f_id
156 from quant_sold
157 where quant_sold.j_id=$2 ) as v_fiche on (fiche_detail.f_id=v_fiche.f_id) where ad_id=23 ");
158 }
159 /**
160 * @brief Find the tiers of an operation , thanks the SQL prepared query
161 * prep_tiers and prep_counterpart. Return a string with the quick_code
162 * @param type $pn_jrn_id pk of the table jrn (jrn.jr_id)
163 * @param type $pn_jrnx_id pk of the table jrnx (jrnx.jr_id)
164 * @param type $p_code quickcode
165 * @return string
166 */
167 function find_tiers($pn_jrn_id,$pn_jrnx_id,$p_code)
168 {
169 static $p=0;
170 if ( $p == 0 ){
172 $this->prepare_sql_tiers();
173 $p=1;
174 }
175 $tiers="";
176 $res_tiers=$this->db->execute('prep_tiers',
177 array($pn_jrn_id,$pn_jrnx_id));
178 if ( Database::num_row($res_tiers) > 0) {
179 $atiers=Database::fetch_array($res_tiers);
180 $tiers=$atiers['ad_value'];
181 // If the found tiers has the same quickcode than the current
182 // card, it means it is a card of supplier or customer,
183 // so we must look for the countercard
184 if ($tiers == $p_code) {
185 $res_counterpart=$this->db->execute('prep_counterpart',
186 array($pn_jrn_id,$pn_jrnx_id));
187 $tiers="";
188 if ( Database::num_row($res_counterpart) > 0) {
189 $atiers=Database::fetch_array($res_counterpart);
190 $tiers=$atiers['ad_value'];
191 }
192 }
193 }
194 return $tiers;
195 }
196 /**
197 *@brief Insert into the table Jrn
198 *The needed data are :
199 * - this->date
200 * - this->amount
201 * - this->poste
202 * - this->grpt
203 * - this->jrn
204 * - this->type ( debit or credit)
205 * - this->user
206 * - this->periode
207 * - this->qcode
208 * - this->desc optional
209 *@note if the amount is less than 0 then side changes, for example debit becomes
210 *a credit and vice versa
211 *@return jrnx.j_id
212 */
213
214 function insert_jrnx()
215 {
216 if ( $this->poste == "") { throw new Exception (__FILE__.':'.__LINE__.' Poste comptable vide');return false; }
217 /* for negative amount the operation is reversed */
218 if ( $this->amount < 0 )
219 {
220 $this->type=($this->type=='d')?'c':'d';
221 }
222 if ( DEBUGNOALYSS > 1 ) {
223 echo "insert_jrnx = [{ $this->poste}] {$this->amount} rounded ".round($this->amount,2)." type {$this->type}<br>";
224 }
225 $this->amount=abs($this->amount);
226 $debit=($this->type=='c')?'false':'true';
227 $this->desc=(isset($this->desc))?$this->desc:'';
228 $this->amount=(trim($this->amount)==''||$this->amount==NULL)?0:$this->amount;
229 $Res=$this->db->exec_sql("select insert_jrnx
230 ($1::text,abs($2)::numeric,$3::account_type,$4::integer,$5::integer,$6::bool,$7::text,$8::integer,upper($9),$10::text)",
231 array(
232 $this->date, //$1
233 round($this->amount,2), //$2
234 $this->poste, //$3
235 $this->grpt, //$4
236 $this->jrn, //$5
237 $debit, //$6
238 $this->user, //$7
239 $this->periode, //$8
240 $this->qcode, // $9
241 $this->desc)); //$10
242 if ( $Res===FALSE) return FALSE;
243 $this->jrnx_id=$this->db->get_current_seq('s_jrn_op');
244 return $this->jrnx_id;
245
246 }
247
248 /**
249 * @brief get the sum of other tax linked to this operation
250 */
251 function get_sum_other_tax() {
252 if ( $this->jr_id == 0 ) {return 0;}
253 $sum=$this->db->get_value("select
254 sum(case when j_debit is false and jrn_def.jrn_def_type='ACH'
255 then 0-j_montant when j_debit is true and jrn_def.jrn_def_type='VEN'
256 then 0-j_montant
257 else j_montant end) sum_tax
258 from
259 jrn_tax join jrnx j1 using (j_id)
260 join jrn on (jr_grpt_id=j1.j_grpt)
261 join jrn_def on (jrn.jr_def_id=jrn_def.jrn_def_id)
262 where
263 jrn.jr_id=$1",[$this->jr_id]);
264 ;
265 if ( $this->db->count()==0) {return 0;}
266 return $sum;
267 }
268
269 /*!
270 *\brief set the pj of a operation in jrn. the jr_id must be set
271 *\note if the jr_id it fails
272 */
273 function update_receipt()
274 {
275 if ( noalyss_strlentrim($this->pj) == 0 )
276 {
277 // echo __LINE__."debug {$this->pj} est vide";
278 $sql="update jrn set jr_pj_number=$1 where jr_id=$2";
279 $this->db->exec_sql($sql,array(null,$this->jr_id));
280 return '';
281 }
282 /* is pj uniq ? */
283 if ( $this->db->count_sql("select jr_id from jrn
284 where jr_pj_number=$1 and jr_def_id=$2
285 and jr_id !=$3",
286 array($this->pj,$this->jrn,$this->jr_id)
287 ) == 0 )
288 {
289
290 $sql="update jrn set jr_pj_number=$1 where jr_id=$2";
291 $this->db->exec_sql($sql,array($this->pj,$this->jr_id));
292 }
293 else
294 {
295 /* get pref */
296 $pref=$this->db->get_value("select jrn_def_pj_pref from jrn_def where jrn_def_id=$1",
297 array($this->jrn));
298 /* try another seq */
299 $flag=0;
300 $limit=100;
301 while ( $flag == 0 )
302 {
303 /* limit the search to $limit */
304 if ( $limit < 1 )
305 {
306 $this->pj='';
307 $flag=2;
308 break;
309 }
310 /* get padding */
311 $padding=$this->db->get_value("select jrn_def_pj_padding from jrn_def where jrn_def_id=$1",
312 array($this->jrn));
313
314 $seq=$this->db->get_next_seq('s_jrn_pj'.$this->jrn);
315
316 // see Acc_Ledger::guess_pj
317 $this->pj=$pref.str_pad($seq,$padding??0,'0',STR_PAD_LEFT);
318
319 /* check if the new pj numb exist */
320 $c=$this->db->count_sql("select jr_id from jrn where jr_pj_number=$1 and jr_def_id=$2
321 and jr_id !=$3",
322 array($this->pj,$this->jrn,$this->jr_id)
323 );
324 if ( $c == 0 )
325 {
326 $flag=1;
327 break;
328 }
329 $limit--;
330 }
331 /* a pj numb is found */
332 if ( $flag == 1 )
333 {
334 $sql="update jrn set jr_pj_number=$1 where jr_id=$2";
335 $this->db->exec_sql($sql,array($this->pj,$this->jr_id));
336 }
337 }
338 return $this->pj;
339 }
340
341 /*!
342 *\brief Insert into the table Jrn, the amount is computed from jrnx thanks the
343 * group id ($p_grpt)
344 *
345 * \return sequence of jr_id
346 *
347 */
348
349 function insert_jrn()
350 {
351 $p_comment=$this->desc;
352 if ( DEBUGNOALYSS > 1 ) {
353 echo "insert_jrn = {$this->amount} <br>";
354 }
355 $diff=$this->db->get_value("select check_balance ($1)",array($this->grpt));
356 if ( $diff != 0 )
357 {
358
359 printf (_("Erreur : balance incorrecte :diff = %s"),$diff);
360 return false;
361 }
362
363 $echeance=( isset( $this->echeance) && noalyss_strlentrim($this->echeance) != 0)?$this->echeance:null;
364 if ( ! isset($this->mt) )
365 {
366 $this->mt=microtime(true);
367 }
368
369 // if amount == -1then the triggers will throw an error
370 //
371 $this->amount=(trim($this->amount)==''||$this->amount==NULL)?0:$this->amount;
372 $Res=$this->db->exec_sql("insert into jrn (jr_def_id,jr_montant,jr_comment,".
373 "jr_date,jr_ech,jr_grpt_id,jr_tech_per,jr_mt,jr_optype,currency_id,currency_rate,currency_rate_ref) values (".
374 "$1,$2,$3,".
375 "to_date($4,'DD.MM.YYYY'),to_date($5,'DD.MM.YYYY'),$6,$7,$8,$9,$10,$11,$12)",
376 array ($this->jrn, $this->amount,$p_comment,
377 $this->date,$echeance,$this->grpt,$this->periode,$this->mt,$this->jr_optype,
378 $this->currency_id,$this->currency_rate,$this->currency_rate_ref)
379 );
380 if ($Res==FALSE)
381 {
382 return FALSE;
383 }
384 $this->jr_id=$this->db->get_current_seq('s_jrn');
385 return $this->jr_id;
386 }
387 /*!
388 * \brief Return the internal value, the property jr_id must be set before
389 *
390 * \return null si aucune valeur de trouv
391 *
392 */
393 function get_internal()
394 {
395 if ( ! isset($this->jr_id) )
396 throw new Exception('jr_id is not set',1);
397 $Res=$this->db->exec_sql("select jr_internal from jrn where jr_id=$1",[$this->jr_id]);
398 if ( Database::num_row($Res) == 0 ) return null;
400 $this->jr_internal= $l_line['jr_internal'];
401 return $this->jr_internal;
402 }
403 /*!
404 * \brief search an operation thankx it internal code
405 * \param internal code
406 * \return 0 ok -1 nok
407 */
408 function seek_internal($p_internal)
409 {
410 $res=$this->db->exec_sql('select jr_id from jrn where jr_internal=$1',
411 array($p_internal));
412 if ( Database::num_row($res) == 0 ) return -1;
414 return 0;
415 }
416 /*!
417 * \brief retrieve data from jrnx
418 *\note the data are filtered by the access of the current user
419 * \return an array or FALSE if nothing found
420 */
422 {
423 global $g_user;
424 $filter_sql=$g_user->get_ledger_sql('ALL',3);
425 $filter_sql=noalyss_str_replace('jrn_def_id','jr_def_id',$filter_sql);
426 if ( $this->jr_id==0 ) return;
427 $sql=" select jr_id,j_id,jr_date,j_qcode,j_poste,j_montant,jr_internal,case when j_debit = 'f' then 'C' else 'D' end as debit,jr_comment as description,
428 vw_name,pcm_lib,j_debit,coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter,jr_def_id ".
429 " from jrnx join jrn on (jr_grpt_id=j_grpt)
430 join tmp_pcmn on (j_poste=pcm_val)
431 left join vw_fiche_attr on (j_qcode=quick_code)
432 where
433 jr_id=$1 and $filter_sql order by j_debit desc";
434 $res=$this->db->exec_sql($sql,array($this->jr_id));
435 if ( Database::num_row ($res) == 0 ) return array();
437 return $all;
438 }
439 /*!
440 * \brief add a comment to the line (jrnx.j_text)
441 */
442 function update_comment($p_text)
443 {
444 $sql="update jrnx set j_text=$1 where j_id=$2";
445 $this->db->exec_sql($sql,array($p_text,$this->jrnx_id));
446 }
447 /*!
448 * \brief add a comment to the operation (jrn.jr_text)
449 */
450 function operation_update_comment($p_text)
451 {
452 $sql="update jrn set jr_comment=$1 where jr_id=$2";
453 $this->db->exec_sql($sql,array($p_text,$this->jr_id));
454 }
455 /*!
456 * \brief add a limit of payment to the operation (jrn.jr_ech)
457 */
459 {
460 if ( isDate($p_text) == null )
461 {
462 $p_text=null;
463 }
464 $sql="update jrn set jr_ech=to_date($1,'DD.MM.YYYY') where jr_id=$2";
465 $this->db->exec_sql($sql,array($p_text,$this->jr_id));
466 }
467 /*!
468 * \brief return the jrn_def_id from jrn
469 */
470 function get_ledger()
471 {
472 $sql="select jr_def_id from jrn where jr_id=$1";
473 $row=$this->db->get_value($sql,array($this->jr_id));
474 return $row;
475 }
476 /*!\brief display_jrnx_detail : get the data from get_jrnx_data and
477 return a string with HTML code
478 * \param table(=0 no code for table,1 code for table,2 code for CSV)
479
480 */
481 function display_jrnx_detail($p_table)
482 {
483 $show=$this->get_jrnx_detail();
484
485 $r='';
486 $r_notable='';
487 $csv="";
488 foreach ($show as $l)
489 {
490 $border="";
491 if ( $l['j_poste'] == $this->poste || ($l['j_qcode']==$this->qcode && trim($this->qcode) != ''))
492 $border=' class="highlight"';
493 $r.='<tr '.$border.'>';
494 $r.='<td>';
495 $a=$l['j_qcode'];
496
497 $r_notable.=$a;
498 $r.=$a;
499 $csv.='"'.$a.'";';
500 $r.='</td>';
501
502 $r.='<td '.$border.'>';
503 $a=$l['j_poste'];
504 $r_notable.=$a;
505 $r.=$a;
506 $csv.='"'.$a.'";';
507 $r.='</td>';
508
509 $r.='<td '.$border.'>';
510 // $a=($l['vw_name']=="")?$l['j_qcode']:$l['pcm_lib'];
511 $a=(noalyss_strlentrim($l['j_qcode'])==0)?$l['pcm_lib']:$l['vw_name'];
512 $r_notable.=$a;
513 $r.=h($a);
514 $csv.='"'.$a.'";';
515 $r.='</td>';
516
517 $r.='<td '.$border.'>';
518 $a=$l['j_montant'];
519 $r_notable.=$a;
520 $r.=$a;
521 $csv.=$a.';';
522 $r.='</td>';
523
524 $r.='<td '.$border.'>';
525 $a=$l['debit'];
526 $r_notable.=$a;
527 $r.=$a;
528 $csv.='"'.$a.'"';
529
530 $csv.="\r\n";
531 $r.='</td>';
532 $r.='<td '.$border.'>';
533 $a=($l['letter']!=-1)?$l['letter']:'';
534 $r_notable.=$a;
535 $r.=$a;
536 $csv.='"'.$a.'"';
537
538 $csv.="\r\n";
539 $r.='</td>';
540
541
542 $r.='</tr>';
543 }
544 switch ($p_table)
545 {
546 case 1:
547 return $r;
548 break;
549 case 0:
550 return $r_notable;
551 break;
552 case 2:
553 return $csv;
554 }
555 return "ERROR PARAMETRE";
556 }
557 /*!
558 * @brief Get data from jrnx where p_grpt=jrnx(j_grpt)
559 *
560 * @param connection
561 * @return array of 3 elements
562 * - First Element is an array
563 @verbatim
564 Array
565 (
566 [op_date] => 01.12.2009
567 [class_cred0] => 7000008
568 [mont_cred0] => 8880.0000
569 [op_cred0] => 754
570 [text_cred0] =>
571 [jr_internal] => 23VEN-01-302
572 [comment] =>
573 [ech] =>
574 [jr_id] => 302
575 [jr_def_id] => 2
576 [class_deb0] => 4000005
577 [mont_deb0] => 10744.8000
578 [text_deb0] =>
579 [op_deb0] => 755
580 [class_cred1] => 4511
581 [mont_cred1] => 1864.8000
582 [op_cred1] => 756
583 [text_cred1] =>
584 )
585 @endverbatim
586 * - Second : number of line with debit
587 * - Third : number of line with credit
588 */
589 function get_data ($p_grpt)
590 {
591 $Res=$this->db->exec_sql("select
592 to_char(j_date,'DD.MM.YYYY') as j_date,
593 j_text,
594 j_debit,
595 j_poste,
596 coalesce(j_qcode,'-') as qcode,
597 j_montant,
598 j_id,
599 jr_comment,
600 to_char(jr_ech,'DD.MM.YYYY') as jr_ech,
601 to_char(jr_date,'DD.MM.YYYY') as jr_date,
602 jr_id,jr_internal,jr_def_id,jr_pj
603 from jrnx inner join jrn on j_grpt=jr_grpt_id where j_grpt=$1",array($p_grpt));
604 $MaxLine=Database::num_row($Res);
605 if ( $MaxLine == 0 ) return null;
606 $deb=0;
607 $cred=0;
608 for ( $i=0; $i < $MaxLine; $i++)
609 {
610
612 $l_array['op_date']=$l_line['j_date'];
613 if ( $l_line['j_debit'] == 't' )
614 {
615 $l_class=sprintf("class_deb%d",$deb);
616 $l_montant=sprintf("mont_deb%d",$deb);
617 $l_text=sprintf("text_deb%d",$deb);
618 $l_qcode=sprintf("qcode_deb%d",$deb);
619 $l_array[$l_class]=$l_line['j_poste'];
620 $l_array[$l_montant]=$l_line['j_montant'];
621 $l_array[$l_text]=$l_line['j_text'];
622 $l_array[$l_qcode]=$l_line['qcode'];
623 $l_id=sprintf("op_deb%d",$deb);
624 $l_array[$l_id]=$l_line['j_id'];
625 $deb++;
626 }
627 if ( $l_line['j_debit'] == 'f' )
628 {
629 $l_class=sprintf("class_cred%d",$cred);
630 $l_montant=sprintf("mont_cred%d",$cred);
631 $l_array[$l_class]=$l_line['j_poste'];
632 $l_array[$l_montant]=$l_line['j_montant'];
633 $l_id=sprintf("op_cred%d",$cred);
634 $l_array[$l_id]=$l_line['j_id'];
635 $l_text=sprintf("text_cred%d",$cred);
636 $l_array[$l_text]=$l_line['j_text'];
637 $l_qcode=sprintf("qcode_cred%d",$cred);
638 $l_array[$l_qcode]=$l_line['qcode'];
639 $cred++;
640 }
641 $l_array['jr_internal']=$l_line['jr_internal'];
642 $l_array['comment']=$l_line['jr_comment'];
643 $l_array['ech']=$l_line['jr_ech'];
644 $l_array['jr_id']=$l_line['jr_id'];
645 $l_array['jr_def_id']=$l_line['jr_def_id'];
646 }
647 return array($l_array,$deb,$cred);
648 }
649 /**
650 *@brief retrieve data from jrnx and jrn
651 *@return return an object
652 *@note
653 *@see
654 @code
655
656 @endcode
657 */
658 function get()
659 {
660 $ret=new Acc_Misc($this->db,$this->jr_id);
661 $ret->get();
662 return $ret;
663 }
664 /**
665 *@brief retrieve data from the table QUANT_*
666 *@return return an object or null if there is no
667 * data from the QUANT table
668 *@see Acc_Sold Acc_Purchase Acc_Fin Acc_Detail Acc_Misc
669 */
670 function get_quant()
671 {
672 $ledger_id=$this->get_ledger();
673 if ( $ledger_id=='') throw new Exception(_('Journal non trouvé'));
674 $oledger=new Acc_Ledger($this->db,$ledger_id);
675
676 // retrieve info from jrn_info
677
678
679 switch($oledger->get_type())
680 {
681 case 'VEN':
682 $ret=new Acc_Sold($this->db,$this->jr_id);
683 break;
684 case 'ACH':
685 $ret=new Acc_Purchase($this->db,$this->jr_id);
686 break;
687 case 'FIN':
688 $ret=new Acc_Fin($this->db,$this->jr_id);
689 break;
690 default:
691 $ret=new Acc_Misc($this->db,$this->jr_id);
692 break;
693 }
694 $ret->get();
695 if ( empty($ret->det->array))
696 {
697 $ret=new Acc_Misc($this->db,$this->jr_id);
698 $ret->get();
699 }
700 $ret->get_info();
701 return $ret;
702 }
703 /**
704 *@brief retrieve amount in currency for the operation
705 *@return amount in currency or 0 if this operation doesn't use currency
706 *@see Acc_Sold Acc_Purchase Acc_Fin Acc_Detail Acc_Misc
707 */
709 {
710 if ( $this->det->currency_id == 0 ) {
711 return 0;
712 }
713 $ledger_id=$this->get_ledger();
714 if ( $ledger_id=='') throw new Exception(_('Journal non trouvé'));
715 $oledger=new Acc_Ledger($this->db,$ledger_id);
716
717 // retrieve info from jrn_info
718
719
720 switch($oledger->get_type())
721 {
722 case 'VEN':
723 $sql_amount="
724 select
725 sum(oc_amount)+sum(oc_vat_amount )
726 from operation_currency oc
727 join quant_sold qs using(j_id)
728 where
729 oc.j_id in (select j_id
730 from jrnx join jrn on (jr_grpt_id=j_grpt)
731 where jr_id=$1);
732 ";
733 break;
734 case 'ACH':
735 $sql_amount="
736 select
737 sum(oc_amount)+sum(oc_vat_amount )
738 from operation_currency oc
739 join quant_purchase qs using(j_id)
740 where
741 oc.j_id in (select j_id
742 from jrnx join jrn on (jr_grpt_id=j_grpt)
743 where jr_id=$1);
744 ";
745 break;
746 case 'FIN':
747 $sql_amount="
748 select
749 sum(oc_amount)+sum(oc_vat_amount )
750 from operation_currency oc
751 join quant_fin qs using(j_id)
752 where
753 oc.j_id in (select j_id
754 from jrnx join jrn on (jr_grpt_id=j_grpt)
755 where jr_id=$1);
756 ";
757 break;
758 default:
759 $sql_amount="
760 select
761 sum(oc_amount)+sum(oc_vat_amount )
762 from operation_currency oc
763 join jrnx using(j_id)
764 join jrn on (jr_grpt_id=j_grpt)
765 where
766 jr_id=$1 and j_debit='t';
767 ";
768 break;
769 }
770 $amount=$this->db->get_value($sql_amount,[$this->jr_id]);
771 return $amount;
772 }
773 /**
774 * @brief retrieve info from the jrn_info, create 2 new arrays
775 * obj->info->command and obj->info->other
776 * the columns are the idx
777 */
778 function get_info()
779 {
780 $this->info=new stdClass();
781 // other info
782 $array=$this->db->get_value("select ji_value from jrn_info where
783 jr_id=$1 and id_type=$2",array($this->jr_id,'OTHER'));
784 $this->info->other= $array;
785
786 // Bon de commande
787 $array=$this->db->get_value("select ji_value from jrn_info where
788 jr_id=$1 and id_type=$2",array($this->jr_id,'BON_COMMANDE'));
789 $this->info->command= $array;
790
791 }
792 /**
793 * Save into jrn_info
794 * @param $p_info msg to save
795 * @param $p_type is OTHER or BON_COMMAND
796 */
797 function save_info($p_info,$p_type)
798 {
799 if ( ! in_array($p_type,array('OTHER','BON_COMMANDE'))) return;
800 if (trim($p_info)=="") {
801 $this->db->exec_sql('delete from jrn_info where jr_id=$1 and id_type=$2',array($this->jr_id,$p_type));
802 return;
803 }
804 $exist=$this->db->get_value('select count(ji_id) from jrn_info where jr_id=$1 and id_type=$2',array($this->jr_id,$p_type));
805 if ( $exist == "0" ) {
806 //insert into jrn_info
807 $this->db->exec_sql('insert into jrn_info(jr_id,id_type,ji_value) values ($1,$2,$3)',
808 array($this->jr_id,$p_type,$p_info));
809 } elseif ( $exist == 1) {
810 //update
811 $this->db->exec_sql('update jrn_info set ji_value=$3 where jr_id=$1 and id_type=$2',
812 array($this->jr_id,$p_type,$p_info));
813 }
814 }
815
816 function insert_related_action($p_string)
817 {
818 if ($p_string == "") return;
819 $a_action=explode(',',$p_string);
820 for ($i=0;$i<count($a_action);$i++)
821 {
822 $action = new Follow_Up($this->db,$a_action[$i]);
823 $action->operation=$this->jr_id;
824 $action->insert_operation();
825 }
826 }
827 /**
828 * @brief set the operation id (jrn.jr_id)
829 * @param type $p_id
830 */
831 function set_id($p_id)
832 {
833 if (isNumber($p_id)==0) {
834 throw new Exception(_('Acc_Operation::set_id , id invalide '));
835 }
836 $this->jr_id=$p_id;
837 }
838 /**
839 * \brief flag the operation as paid
840 */
841 function set_paid()
842 {
843 // Operation
844 if ( $this->jr_id == 0 )
845 throw new Exception(_('Object invalide, id incorrect'));
846 if (
847 $this->db->get_value('select count(*) from jrn where jr_id=$1',
848 array($this->jr_id)) == 0 )
849 throw new Exception(_('Object invalide, id incorrect'));
850
851 $this->db->exec_sql("update jrn set jr_rapt = 'paid' where jr_id = $1",
852 array($this->jr_id));
853 }
854 /**
855 * return amount of the jr_id
856 */
857 function get_amount()
858 {
859 if ( $this->jr_id == 0 )
860 throw new Exception(_('Object invalide, id incorrect'));
861 $amount=$this->db->get_value('select jr_montant from jrn where jr_id=$1',
862 array($this->jr_id));
863 return $amount;
864 }
865 static function test_me()
866 {
867 global $g_user;
868 $cn=Dossier::connect();
869 $g_user=new Noalyss_user($cn);
870 $a=new Acc_Operation($cn);
871 $a->jr_id=993;
872 $b=$a->get_quant();
873 echo h1('contain of get_quant() ');
874 var_dump($b);
875 echo h1('contain of get_jrnx_detail()');
876 var_dump($a->get_jrnx_detail());
877 }
878 /**
879 * Return a select object to choose the type of operation
880 * - NOR normal
881 * - EXT reverse operation
882 * - CLO closing periode
883 * - OPE opening periode
884 * @param string $p_status
885 * @return \ISelect
886 */
887 static function select_operation_type($p_status)
888 {
889 $type_operation=new ISelect("jr_optype");
890 $type_operation->value=array(
891 array(("label")=>_("Normal"), "value"=>"NOR"),
892 array(("label")=>_("Ouverture"), "value"=>"OPE"),
893 array(("label")=>_("Fermeture"), "value"=>"CLO"),
894 array(("label")=>_("Extourne"), "value"=>"EXT")
895 );
896
897 $type_operation->selected=$p_status;
898 return $type_operation;
899 }
900 /**
901 * @brief create a form to recreate the operation and returns it,
902 * it works the same as when you want to correct an operation instead of confirming
903 *
904 * @see compta_ach.inc.php
905 * @see compta_ven.inc.php
906 *
907 * @param $p_id string DOMID of the form
908 */
910 // retrieve all info about operation
911 $operation = $this->get_quant();
912 $array=$operation->compute_array();
913
914 global $g_user;
915 $a_code=$this->db->get_array("select code from v_menu_dependency vmd where me_code=$1 and p_id=$2",
916 array( $operation->signature,$g_user->get_profile()));
917 if ( empty ($a_code)) {
918 $r=_("Menu invalide");
919 return $r;
920 }
921
922 // Prepare the form
923 // select the menu where the operation will be duplicated
924 $r=sprintf('<form id="%s" method="POST" ACTION="%s">',$p_id,NOALYSS_URL."/do.php?".http_build_query([
925 "ac"=>$a_code[0]['code'],"gDossier"=>Dossier::id()
926 ]));
927 $r.=Dossier::hidden();
928 $default_currency=new Acc_Currency($this->db,0);
929 // select the menu where the operation will be duplicated
930
931 $r.="<p>";
932 $r.="<ul style=\"margin-left:2rem;padding-left:0;list-style:none;\">";
933 $r.=sprintf("<li>%s %s</li>",_("Date"),$operation->det->jr_pj_number);
934 $r.=sprintf("<li>%s %s</li>",_("Libellé"),$operation->det->jr_comment);
935 $r.=sprintf("<li>%s %s %s</li>",_("Montant "),nbm($operation->det->jr_montant),$default_currency->get_code());
936 // Add info if the operation using a currency
937 if ( $operation->det->currency_id != 0 ) {
938 $currency=$this->db->get_value("select cr_code_iso from currency where id=$1",[$operation->det->currency_id]);
939 $r.=sprintf("<li>%s %s</li>",_('Devise'),$currency);
940 $r.=sprintf("<li>%s %s</li>",_("Taux"),$operation->det->currency_rate);
941 $array['p_currency_code']=$operation->det->currency_id;
942 $array['p_currency_rate']=$operation->det->currency_rate;
943 }
944 $r.="</ul>";
945 $r.="</p>";
946 if (count($a_code) == 1 ) {
947 $r.=HtmlInput::hidden("ac",$a_code[0]['code']);
948 $r.=sprintf(_("Voulez-vous aller à %s pour dupliquer cette opération ?"),$a_code[0]['code']);
949
950 } else {
951 $select=new ISelect("ac");
952 $select->value=array();
953 $nb_code=count($a_code);
954
955 for ($i=0;$i<$nb_code;$i++) {
956 $select->value[]=array("label"=>$a_code[$i]['code'],"value"=>$a_code[$i]['code']);
957 }
958 $r.=sprintf(_("Voulez-vous aller à %s pour dupliquer cette opération ?"),$select->input());
959
960 }
961
962 $r.="</p>";
963
964 // For Misc Operation , if a card is given then there is no accounting
965 // modify amount with currency if not in default currency
966 if ( $operation->signature==="ODS") {
967 $nb_array = count($array);
968 for ($i = 0; $i < $nb_array; $i++) {
969 if (isset ($array["qc_" . $i]) && $array["qc_" . $i] != "") {
970 $array["poste" . $i] = "";
971 }
972
973 }
974 $idx=0;
975 foreach ($operation->det->array as $item) {
976 if ($operation->det->currency_id != 0) {
977 $array['amount'. $idx] = $item['oc_amount'];
978 $idx++;
979 }
980 }
981
982 }elseif ( $operation->signature==="ACH" || $operation->signature=="VEN") {
983 $idx=0;
984 foreach ($operation->det->array as $item) {
985
986 // currency replace amount
987 if ($operation->det->currency_id != 0 ) {
988 $array['e_march'.$idx.'_tva_amount']=$item['oc_vat_amount'];
989 $array['e_march'.$idx.'_tva_amount']=$item['oc_amount'];
990 $array['e_march'.$idx.'_price']=$item['oc_price_unit'];
991 }
992
993 if ( isset ($item['qs_vat_sided']) && $item['qs_vat_sided'] != 0 ) {
994 $array['e_march'.$idx.'_tva_amount']=0;
995 }elseif (isset ($item['qp_vat_sided']) && $item['qp_vat_sided'] != 0 ){
996 $array['e_march'.$idx.'_tva_amount']=0;
997 }
998
999 $idx++;
1000 }
1001 }elseif ($operation->signature=='FIN') {
1002 $idx=0;
1003 foreach ($operation->det->array as $item) {
1004 if ($operation->det->currency_id != 0) {
1005 $array['e_other' . $idx . '_amount'] = $item['oc_amount'];
1006 $idx++;
1007 }
1008 }
1009 }
1010
1011 if ( DEBUGNOALYSS>1) {
1012 echo \Noalyss\Dbg::hidden_info("operation->det_array", $operation->det->array);
1013 echo \Noalyss\Dbg::hidden_info("operation->det", $operation->det);
1014 echo \Noalyss\Dbg::hidden_info("array", $array);
1015 }
1016 // transform the operation into hidden element
1017 $r.=HtmlInput::simple_array_to_hidden($array);
1018 $r.=HtmlInput::hidden("e_comm",$operation->det->jr_comment);
1019 $r.=HtmlInput::submit(uniqid(), _("Dupliquer"));
1020 $r.=HtmlInput::button_close("duplicate_operation_div");
1021 $r.='</form>';
1022
1023
1024 // return the form as a string
1025 return $r;
1026 }
1027
1028}
1029/////////////////////////////////////////////////////////////////////////////
1030
1031/**
1032 * @class Acc_Detail
1033 * @brief Contains the detail of an operation Acc_Operation
1034 * propery :
1035 * - $det
1036 - jr_id PKfrom table JRN
1037 - jr_def_id id of the ledger (FK to - _DEF- _DEF_ID)from table JRN
1038 - jr_montant AMOUNT of the operationfrom table JRN
1039 - jr_comment COMMENT from table JRN
1040 - jr_date DATEfrom table JRN
1041 - jr_grpt_id CODE to group - X rowsfrom table JRN
1042 - jr_internal INTERNAL CODEfrom table JRN
1043 - jr_tech_date DATE OF CHANGEfrom table JRN
1044 - jr_tech_per FK TO PARAM_PERIODEP_IDfrom table JRN
1045 - jrn_ech from table JRN
1046 - jr_ech DATE LIMIT OF PAYMENTfrom table JRN
1047 - jr_rapt from table JRN
1048 - jr_echfrom table JRN
1049 - jr_validfrom table JRN
1050 - jr_opid from table JRN
1051 - jr_c_opidfrom table JRN
1052 - jr_pj OID OF THE DOCUMENTfrom table JRN
1053 - jr_pj_name NAME OF THE DOCUMENTfrom table JRN
1054 - jr_pj_typefrom table JRN
1055 - jr_pj_number RECEIPT NBfrom table JRN
1056 - jr_mt INTERNAL CODEfrom table JRN
1057 - jr_raptfrom table JRN
1058 - jr_date_paid DATE OF PAYMENTfrom table JRN
1059 - jr_optype TYPE OF OPERATION NOR = NORMAL OPE=OPENING EXT=EXTOURNEfrom table JRN
1060 - currency_id FK TO CURRENCYIDfrom table JRN
1061 - currency_rate amountfrom table JRN
1062 - currency_rate_ref amount in CURRENT_HISTORYCH_VALUEfrom table JRN
1063 * - note from table JRN_NOTE
1064 - $jr_id JRN.JR_ID
1065 - $info
1066 */
1068{
1069 public $det;//!< Object with columns from JRN
1070 public $jr_id;//! $jr_id (int) JRN.JR_ID
1071 public $info;
1072
1073 function __construct($p_cn,$p_jrid=0)
1074 {
1075 parent::__construct($p_cn);
1076 $this->jr_id=$p_jrid;
1077 $this->det=new stdClass();
1078 }
1079 /**
1080 *@brief retrieve some common data from jrn as
1081 * the datum, the comment,payment limit...
1082 */
1083 function get()
1084 {
1085 $sql="SELECT jr_id
1086 , jr_def_id
1087 , jr_montant
1088 , jr_comment
1089 , jr_date
1090 , jr_grpt_id
1091 , jr_internal
1092 , jr_tech_date
1093 , jr_tech_per
1094 , jrn_ech
1095 , jr_ech
1096 , jr_rapt
1097 ,jr_ech
1098 , jr_valid
1099 , jr_opid
1100 , jr_c_opid
1101 , jr_pj
1102 , jr_pj_name
1103 , jr_pj_type,
1104 jr_pj_number
1105 , jr_mt
1106 ,jr_rapt
1107 ,jr_date_paid
1108 ,jr_optype
1109 ,currency_id
1110 ,currency_rate
1111 ,currency_rate_ref
1112 ,jr_document_xml
1113 FROM jrn where jr_id=$1";
1114 $array=$this->db->get_array($sql,array($this->jr_id));
1115 if ( count($array) == 0 ) throw new Exception('Aucune ligne trouvée');
1116 foreach ($array[0] as $key=>$val)
1117 {
1118 $this->det->$key=$val;
1119 }
1120 $sql="select n_text,n_html from jrn_note where jr_id=$1";
1121 $a=$this->db->get_row($sql,array($this->jr_id));
1122 if ( empty($a)) {
1123 $this->det->note="";
1124 $this->det->note_html=null;
1125 } else {
1126 $this->det->note=strip_tags($a['n_text']??"");
1127 $this->det->note_html=($a['n_html'] == "")?$a['n_text']:$a['n_html'];
1128 }
1129 }
1130 /**
1131 *
1132 */
1133 function compute_array()
1134 {
1135 $array=array();
1136 $array['desc']=$this->det->jr_comment;
1137 $array['e_date']="";
1138 $array['e_ech']="";
1139 $array['p_jrn']=$this->det->jr_def_id;
1140 return $array;
1141
1142 }
1143 function __toString(): string
1144 {
1145 $r= __CLASS__;
1146 $r.="this->signature ".$this->signature."\n";
1147 $r.="this->det ".print_r($this->det,true);
1148
1149 return $r;
1150
1151 }
1152}
1153/////////////////////////////////////////////////////////////////////////////
1154/**
1155 * @class Acc_Misc
1156 *@brief this class manage data from the JRNX and JRN
1157 * table
1158 *@note Data member are the column of the table
1159 */
1161{
1162 var $signature; /*!< signature of the obj ODS */
1163 var $array; /*!< an array containing the data from JRNX */
1164 function __construct($p_cn,$p_jrid=0)
1165 {
1166 parent::__construct($p_cn,$p_jrid);
1167 $this->signature='ODS';
1168 $this->det=new stdClass();
1169 }
1170 function get()
1171 {
1172 parent::get();
1173 $sql="
1174SELECT jx1.j_id
1175 ,jx1.j_date
1176 ,jx1.j_montant
1177 ,jx1.j_poste
1178 ,jx1.j_grpt
1179 ,jx1.j_rapt
1180 ,jx1.j_jrn_def
1181 ,jx1.j_debit
1182 ,jx1.j_text
1183 ,jx1.j_centralized
1184 ,jx1.j_internal
1185 ,jx1.j_tech_user
1186 ,jx1.j_tech_date
1187 ,jx1.j_tech_per
1188 ,jx1.j_qcode
1189 ,jx1.f_id
1190 ,oc1.oc_amount
1191 FROM jrnx jx1
1192 left join operation_currency oc1 using(j_id)
1193 where
1194 jx1.j_grpt = $1
1195 order by jx1.j_debit desc,jx1.j_poste
1196";
1197 $this->det->array=$this->db->get_array($sql,array($this->det->jr_grpt_id));
1198 }
1199 /***
1200 * Compute an array for using with Acc_Ledger::insert
1201 *
1202 */
1203 function compute_array()
1204 {
1205 $this->get();
1206 $array=parent::compute_array();
1207 $nb_array=count($this->det->array);
1208 $array['nb_item']=$nb_array;
1209
1210 for ($i=0;$i<$nb_array;$i++) {
1211 $array["qc_".$i]=$this->det->array[$i]['j_qcode'];
1212 $array["poste".$i]=$this->det->array[$i]['j_poste'];
1213 $array["amount".$i]=$this->det->array[$i]['j_montant'];
1214 if ( $this->det->array[$i]['j_debit'] == 't') {
1215 $array["ck".$i]=1;
1216 }
1217 $array["ld".$i]=$this->det->array[$i]['j_text'];
1218 }
1219
1220 return $array;
1221
1222 }
1223 function __toString(): string
1224 {
1225 $r= __CLASS__;
1226 $r.="this->signature ".$this->signature."\n";
1227 $r.="this->det ".print_r($this->det,true);
1228
1229 return $r;
1230
1231 }
1232}
1233/////////////////////////////////////////////////////////////////////////////
1234/**
1235 * @class Acc_Sold
1236 *@brief this class manage data from the QUANT_SOLD
1237 * table
1238 *@note Data member are the column of the table
1239 */
1241{
1242 function __construct($p_cn,$p_jrid=0)
1243 {
1244 parent::__construct($p_cn,$p_jrid);
1245 $this->signature='VEN';
1246 $this->det->array=new stdClass();
1247 }
1248 function get()
1249 {
1250 parent::get();
1251 $sql="
1252 select qs_id, qs_internal
1253 , jx1.j_id
1254 , qs1.qs_fiche
1255 , qs1.qs_quantite
1256 , qs1.qs_price
1257 , qs1.qs_vat
1258 , qs1.qs_vat_code
1259 , qs1.qs_client
1260 , qs1.qs_valid
1261 , jx1.j_text
1262 , qs_vat_sided
1263 , qs_unit
1264 , jx1.j_debit
1265 ,oc1.oc_amount
1266 ,oc1.oc_vat_amount
1267 ,oc1.oc_price_unit
1268 from quant_sold qs1
1269 join jrnx jx1 using(j_id)
1270 left join operation_currency oc1 using(j_id)
1271 where jx1.j_grpt = $1
1272 order by jx1.j_id;
1273 ";
1274 $this->det->array=$this->db->get_array($sql,array($this->det->jr_grpt_id));
1275 }
1276 /***
1277 * @brief Compute an array for using with Acc_Ledger::insert
1278 *
1279 */
1280 function compute_array()
1281 {
1282 $this->get();
1283 $array=parent::compute_array();
1284 $nb_array=count($this->det->array);
1285 $array['nb_item']=$nb_array;
1286
1287
1288 $array["e_client"]=$this->db->get_value("select ad_value from fiche_detail where f_id=$1 and ad_id=23",
1289 array($this->det->array[0]['qs_client']));
1290
1291 for ($i=0;$i<$nb_array;$i++) {
1292 $array["e_march".$i]=$this->db->get_value("select ad_value from fiche_detail where f_id=$1 and ad_id=23",
1293 array($this->det->array[$i]['qs_fiche']));
1294
1295 $array["e_march".$i."_price"]=$this->det->array[$i]['qs_unit'];
1296 $array["e_march".$i."_label"]=$this->det->array[$i]['j_text'];
1297 $array["e_march".$i."_tva_id"]=$this->det->array[$i]['qs_vat_code'];
1298 $array["e_march".$i."_tva_amount"]=$this->det->array[$i]['qs_vat'];
1299 $array["e_quant".$i]=$this->det->array[$i]['qs_quantite'];
1300 }
1301 $array['correct']=1;
1302 return $array;
1303
1304 }
1305 function __toString(): string
1306 {
1307 $r="";
1308 $r.="this->signature ".$this->signature."\n";
1309 $r.="this->det ".print_r($this->det,true);
1310
1311 return $r;
1312
1313 }
1314}
1315/////////////////////////////////////////////////////////////////////////////
1316/**
1317 * @class Acc_Purchase
1318 *@brief this class manage data from the QUANT_PURCHASE
1319 * table
1320 *@note Data member are the column of the table
1321
1322 */
1324{
1325 function __construct($p_cn,$p_jrid=0)
1326 {
1327 parent::__construct($p_cn,$p_jrid);
1328 $this->signature='ACH';
1329 }
1330
1331 function get()
1332 {
1333 parent::get();
1334 $sql="
1335 select qp_id, qp_internal
1336, jx1.j_id
1337, qp1.qp_fiche
1338, qp1.qp_quantite
1339, qp1.qp_price
1340, qp1.qp_vat
1341, qp1.qp_vat_code
1342, qp1.qp_nd_amount
1343, qp1.qp_nd_tva
1344, qp1.qp_nd_tva_recup
1345, qp1.qp_supplier
1346, qp1.qp_valid
1347, qp1.qp_dep_priv
1348, jx1.j_text
1349, qp1.qp_vat_sided
1350, qp1.qp_unit
1351, jx1.j_debit
1352,oc1.oc_amount
1353,oc1.oc_vat_amount
1354,oc1.oc_price_unit
1355from quant_purchase qp1
1356join jrnx jx1 using(j_id)
1357left join operation_currency oc1 using(j_id)
1358where jx1.j_grpt = $1
1359order by jx1.j_id
1360 ";
1361 $this->det->array=$this->db->get_array($sql,array($this->det->jr_grpt_id));
1362 }
1363
1364
1365 /***
1366 * @brief Compute an array for using with Acc_Ledger::insert
1367 *
1368 */
1369 function compute_array()
1370 {
1371 $this->get();
1372 $array=parent::compute_array();
1373 $nb_array=count($this->det->array);
1374 $array['nb_item']=$nb_array;
1375
1376
1377 $array["e_client"]=$this->db->get_value("select ad_value from fiche_detail where f_id=$1 and ad_id=23",
1378 array($this->det->array[0]['qp_supplier']));
1379
1380 for ($i=0;$i<$nb_array;$i++) {
1381 $array["e_march".$i]=$this->db->get_value("select ad_value from fiche_detail where f_id=$1 and ad_id=23",
1382 array($this->det->array[$i]['qp_fiche']));
1383
1384 $array["e_march".$i."_price"]=$this->det->array[$i]['qp_unit'];
1385 $array["e_march".$i."_label"]=$this->det->array[$i]['j_text'];
1386 $array["e_march".$i."_tva_id"]=$this->det->array[$i]['qp_vat_code'];
1387 $array["e_march".$i."_tva_amount"]=$this->det->array[$i]['qp_vat'];
1388 $array["e_quant".$i]=$this->det->array[$i]['qp_quantite'];
1389
1390 }
1391 $array['correct']=1;
1392
1393 return $array;
1394
1395 }
1396 function __toString(): string
1397 {
1398 $r= __CLASS__;
1399 $r.="this->signature ".$this->signature."\n";
1400 $r.="this->det ".print_r($this->det,true);
1401
1402 return $r;
1403
1404 }
1405
1406}
1407/////////////////////////////////////////////////////////////////////////////
1408/**
1409 * @class Acc_Fin
1410 *@brief this class manage data from the QUANT_FIN
1411 * table
1412 *@note Data member are the column of the table
1413 */
1414class Acc_Fin extends Acc_Detail
1415{
1416 function __construct($p_cn,$p_jrid=0)
1417 {
1418 parent::__construct($p_cn,$p_jrid);
1419 $this->signature='FIN';
1420 }
1421
1422 function get()
1423 {
1424 parent::get();
1425 $sql="SELECT qf_id
1426 ,qf_bank
1427 ,jr_id
1428 ,qf_other
1429 ,qf_amount,j_id
1430 ,oc1.oc_amount
1431 ,oc1.oc_vat_amount
1432 ,oc1.oc_price_unit
1433 FROM quant_fin
1434 left join operation_currency oc1 using(j_id)
1435 where
1436 jr_id = $1";
1437 $this->det->array=$this->db->get_array($sql,array($this->jr_id));
1438 }
1439 /***
1440 * Compute an array for using with Acc_Ledger::insert
1441 *
1442 */
1443 function compute_array()
1444 {
1445 $this->get();
1446 $array=parent::compute_array();
1447 $nb_array=count($this->det->array);
1448 $array['nb_item']=$nb_array;
1449
1450
1451 for ($i=0;$i<$nb_array;$i++) {
1452 $array["e_other".$i]=$this->db->get_value("select ad_value from fiche_detail where f_id=$1 and ad_id=23",
1453 array($this->det->array[$i]['qf_other']));
1454
1455 $array["e_other".$i."_amount"]=$this->det->array[$i]['qf_amount'];
1456 $array["e_other".$i."_comment"]=$this->det->jr_comment;
1457 }
1458 $array['correct']=1;
1459 return $array;
1460
1461 }
1462 function __toString(): string
1463 {
1464 $r= __CLASS__;
1465 $r.="this->signature ".$this->signature."\n";
1466 $r.="this->det ".print_r($this->det,true);
1467
1468 return $r;
1469
1470 }
1471}
isNumber($p_int)
isDate($p_date)
Verifie qu'une date est bien formaté en d.m.y et est valable.
noalyss_strlentrim($p_string)
h1($p_string, $p_class="")
Definition ac_common.php:72
noalyss_str_replace($search, $replace, $string)
nbm($p_number, $p_dec=2)
format the number with a sep.
global $g_user
if no group available , then stop
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
h( $row[ 'oa_description'])
$op jr_id
if(isNumber($jr_id)==0) $ledger_id
$input_from user
_("actif, passif,charge,...")
$input_from type
for($j=0;$j< $nb_row;$j++)($j%2==0)? 'even' $show
$p
Definition calendar.php:9
display currency , convert to euro , and save them if used.
Contains the detail of an operation Acc_Operation propery :
$det
Object with columns from JRN.
__construct($p_cn, $p_jrid=0)
constructor set automatically the attributes user and periode
$info
$jr_id (int) JRN.JR_ID
this class manage data from the QUANT_FIN table
compute_array()
Compute an array for using with Acc_Ledger::insert.
__construct($p_cn, $p_jrid=0)
constructor set automatically the attributes user and periode
Class for jrn, class acc_ledger for manipulating the ledger AND some acc.
this class manage data from the JRNX and JRN table
compute_array()
Compute an array for using with Acc_Ledger::insert.
__construct($p_cn, $p_jrid=0)
constructor set automatically the attributes user and periode
this file match the tables jrn & jrnx the purpose is to remove or save accountant writing to these ta...
prepare_sql_tiers()
prepare the query for getting the qcode of the tiers, when executing this SQL , an array of (jrn....
get_sum_other_tax()
get the sum of other tax linked to this operation
operation_update_comment($p_text)
add a comment to the operation (jrn.jr_text)
get_quant()
retrieve data from the table QUANT_*
form_clone_operation($p_id)
create a form to recreate the operation and returns it, it works the same as when you want to correct...
__construct($p_cn, $p_jrid=0)
constructor set automatically the attributes user and periode
insert_jrnx()
Insert into the table Jrn The needed data are :
static select_operation_type($p_status)
Return a select object to choose the type of operation.
get_internal()
Return the internal value, the property jr_id must be set before.
get_data($p_grpt)
Get data from jrnx where p_grpt=jrnx(j_grpt)
get_amount()
return amount of the jr_id
set_paid()
flag the operation as paid
update_receipt()
set the pj of a operation in jrn. the jr_id must be set
get_ledger()
return the jrn_def_id from jrn
insert_jrn()
Insert into the table Jrn, the amount is computed from jrnx thanks the group id ($p_grpt)
operation_update_date_limit($p_text)
add a limit of payment to the operation (jrn.jr_ech)
update_comment($p_text)
add a comment to the line (jrnx.j_text)
save_info($p_info, $p_type)
Save into jrn_info.
$qcode
< Qcode of item
get_jrnx_detail()
retrieve data from jrnx
prepare_sql_counterpart()
prepare the query for getting the qcode of the tiers, when executing this SQL , an array of (jrn....
get_currency_amount()
retrieve amount in currency for the operation
get_info()
retrieve info from the jrn_info, create 2 new arrays obj->info->command and obj->info->other the colu...
display_jrnx_detail($p_table)
display_jrnx_detail : get the data from get_jrnx_data and return a string with HTML code
find_tiers($pn_jrn_id, $pn_jrnx_id, $p_code)
Find the tiers of an operation , thanks the SQL prepared query prep_tiers and prep_counterpart.
set_id($p_id)
set the operation id (jrn.jr_id)
seek_internal($p_internal)
search an operation thankx it internal code
insert_related_action($p_string)
seek_group()
retrieve the grpt_id from jrn for a jr_id
this class manage data from the QUANT_PURCHASE table
__construct($p_cn, $p_jrid=0)
constructor set automatically the attributes user and periode
compute_array()
Compute an array for using with Acc_Ledger::insert.
this class manage data from the QUANT_SOLD table
__construct($p_cn, $p_jrid=0)
constructor set automatically the attributes user and periode
compute_array()
Compute an array for using with Acc_Ledger::insert.
static fetch_result($ret, $p_row=0, $p_col=0)
wrapper for the function pg_fetch_all
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static fetch_all($ret, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_all
static num_row($ret)
wrapper for the function pg_num_rows
class_action for manipulating actions action can be :
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
$c
Definition compute.php:48
$bal jrn
$SecUser db
$flag
Definition install.php:535
if( $delta< 0) elseif( $delta==0)
for($i=0;$i< $nb_jrn;$i++) $deb