noalyss Version-9
lettering.class.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * NOALYSS is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * NOALYSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with NOALYSS; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21// Copyright Author Dany De Bontridder danydb@aevalys.eu
22
23/* !\file
24 * \brief letter the accounting entry (row level)
25 */
26
27/**
28 * @brief mother class for the lettering by account and by card
29 * use the tables jnt_letter, letter_deb and letter_cred
30 * - "account"=>"account", => the accounting of the j_id (use by Lettering_Account)
31 * - "quick_code"=>"quick_code", => the quick_code of the j_id (used by Lettering_Card)
32 * - "start"=>"start", => date of the first day
33 * - "end"=>"end", => date of the last day
34 * - "sql_ledger"=>"sql_ledger" => the sql clause to filter on the available ledgers
35 */
37{
38
39 protected $variable=array("account"=>"account", /* the accounting of the j_id (use by Lettering_Account) */
40 "quick_code"=>"quick_code", /* the quick_code of the j_id (used by Lettering_Card) */
41 "start"=>"start", /* date of the first day */
42 "end"=>"end", /* date of the last day */
43 "sql_ledger"=>"sql_ledger" /* the sql clause to filter on the available ledgers */
44 )
45
46 ;
47 var $db;
48 var $start;
49 var $end;
51
52 /**
53 * constructor
54 * @param $p_init resource to database
55 * @note by default start and end are the 1.1.exercice to 31.12.exercice
56 */
57 function __construct( $p_init)
58 {
59 $this->db=$p_init;
60 $a=new Noalyss_user($p_init);
61 $exercice=$a->get_exercice();
62 if ($exercice>0)
63 {
64 $periode=new Periode($p_init);
65 $aLimite=$periode->get_limit($exercice);
66 $this->start=$aLimite[0]->first_day();
67 $this->end=$aLimite[1]->last_day();
68 }
69 else
70 {
71 $this->start='01.01.'.$exercice;
72 $this->end='31.12.'.$exercice;
73 }
74 // available ledgers
75 $this->sql_ledger=noalyss_str_replace('jrn_def_id', 'jr_def_id', $a->get_ledger_sql('ALL', 3));
76 }
77
78 public function get_parameter($p_string)
79 {
80 if (array_key_exists($p_string, $this->variable))
81 {
82 $idx=$this->variable[$p_string];
83 return $this->$idx;
84 }
85 else
86 throw new Exception(__FILE__.":".__LINE__.$p_string.'Erreur attribut inexistant');
87 }
88
89 public function set_parameter($p_string, $p_value)
90 {
91 if (array_key_exists($p_string, $this->variable))
92 {
93 $idx=$this->variable[$p_string];
94 $this->$idx=$p_value;
95 }
96 else
97 throw new Exception(__FILE__.":".__LINE__.$p_string.'Erreur attribut inexistant');
98 }
99
100 /**
101 * @brief Use to just insert a couple of lettered operation but do not make a link between operation
102 */
103 function insert_couple($j_id1, $j_id2)
104 {
105
106 /* take needed data */
107 $first=$this->db->get_value('select j_debit from jrnx where j_id=$1', array($j_id1));
108 if ($this->db->count()==0)
109 throw new Exception('Opération non existante');
110
111 $second=$this->db->get_value('select j_debit from jrnx where j_id=$1', array($j_id2));
112 if ($this->db->count()==0)
113 throw new Exception('Opération non existante');
114 $sql_already="select distinct(jl_id)
115 from jnt_letter
116 left outer join letter_deb using (jl_id)
117 left outer join letter_cred using (jl_id)
118 where
119 letter_deb.j_id = $1 or letter_cred.j_id=$1";
120 $let1=0; $let2=0;
121 $already=$this->db->get_array($sql_already, array($j_id1));
122 if (count($already)>0)
123 {
124 if (count($already)==1)
125 {
126 // retrieve the letter
127 $let1=$this->db->get_value("select distinct(jl_id)
128 from jnt_letter
129 left outer join letter_deb using (jl_id)
130 left outer join letter_cred using (jl_id)
131 where
132 letter_deb.j_id = $1 or letter_cred.j_id=$1", array($j_id1));
133 }
134 else
135 {
136 return;
137 }
138 }
139
140 $already=$this->db->get_array($sql_already, array($j_id2));
141 if (count($already)>0)
142 {
143 if (count($already)==1)
144 {
145 // retrieve the letter
146 $let2=$this->db->get_value("select distinct(jl_id)
147 from jnt_letter
148 left outer join letter_deb using (jl_id)
149 left outer join letter_cred using (jl_id)
150 where
151 letter_deb.j_id = $1 or letter_cred.j_id=$1", array($j_id2));
152 }
153 else
154 {
155 return;
156 }
157 }
158 $jl_id=0;
159 // already linked together
160 if ($let1!=0&&$let1==$let2)
161 return;
162
163 // already linked
164 if ($let1!=0&&$let2!=0&&$let1!=$let2)
165 return;
166
167 // none is linked
168 if ($let1==0&&$let2==0)
169 {
170 $jl_id=$this->db->get_next_seq("jnt_letter_jl_id_seq");
171 $this->db->exec_sql('insert into jnt_letter(jl_id) values($1)', array($jl_id));
172 }
173 // one is linked but not the other
174 if ($let1==0&&$let2!=0)
175 $jl_id=$let2;
176 if ($let1!=0&&$let2==0)
177 $jl_id=$let1;
178
179 /* insert */
180 if ($first=='t')
181 {
182 // save into letter_deb
183 if ($let1==0)
184 $ld_id=$this->db->get_value('insert into letter_deb(j_id,jl_id) values($1,$2) returning ld_id',
185 array($j_id1, $jl_id));
186 }
187 else
188 {
189 if ($let1==0)
190 $lc_id=$this->db->get_value('insert into letter_cred(j_id,jl_id) values($1,$2) returning lc_id',
191 array($j_id1, $jl_id));
192 }
193 if ($second=='t')
194 {
195 // save into letter_deb
196 if ($let2==0)
197 $ld_id=$this->db->get_value('insert into letter_deb(j_id,jl_id) values($1,$2) returning ld_id',
198 array($j_id2, $jl_id));
199 }
200 else
201 {
202 if ($let2==0)
203 $lc_id=$this->db->get_value('insert into letter_cred(j_id,jl_id) values($1,$2) returning lc_id',
204 array($j_id2, $jl_id));
205 }
206 }
207
208 public function get_info()
209 {
210 return var_export(self::$variable, true);
211 }
212
213 public function verify()
214 {
215 // Verify that the elt we want to add is correct
216 }
217
218 /**
219 * @brief save from array, letter the accounting (or card) and create a link between operation
220 *
221 * @param $p_array
222 @code
223 gDossier => string '13' (length=2)
224 letter_j_id => is an array of j_id value
225 ck => array of j_id to letter with j_id
226 j_id => row to link
227 @endcode
228 */
229 public function save($p_array)
230 {
231
232 if (!isset($p_array['letter_j_id']))
233 {
234 // if nothing selected then remove
235 $this->db->exec_sql('delete from jnt_letter where jl_id=$1', array($p_array['jnt_id']));
236 return;
237 }
238 $nb_letter_j_id=count($p_array['letter_j_id']);
239
240 if ($nb_letter_j_id == 0 ) {
241 $this->db->exec_sql('delete from jnt_letter where jl_id=$1', array($p_array['jnt_id']));
242 return;
243 }
244 try
245 {
246 $this->db->start();
247
248 $this->db->exec_sql('delete from jnt_letter where jl_id=$1', array($p_array['jnt_id']));
249
250 $jl_id=$this->db->get_next_seq("jnt_letter_jl_id_seq");
251 $this->db->exec_sql('insert into jnt_letter(jl_id) values($1)', array($jl_id));
252
253 // save the source
254 $deb=$this->db->get_value('select j_debit,j_montant from jrnx where j_id=$1', array($p_array['j_id']));
255 if ($deb=='t')
256 {
257 // save into letter_deb
258 $ld_id=$this->db->get_value('insert into letter_deb(j_id,jl_id) values($1,$2) returning ld_id',
259 array($p_array['j_id'], $jl_id));
260 }
261 else
262 {
263 $lc_id=$this->db->get_value('insert into letter_cred(j_id,jl_id) values($1,$2) returning lc_id',
264 array($p_array['j_id'], $jl_id));
265 }
266 // save dest
267 for ($i=0; $i<$nb_letter_j_id; $i++)
268 {
269 if (! isset($p_array['ck'][$i]) || $p_array['ck'][$i] == "-2" ) { continue ; }
270
271 // save the dest
272 $deb=$this->db->get_value('select j_debit,j_montant from jrnx where j_id=$1',
273 array($p_array['ck'][$i]));
274 if ($deb=='t')
275 {
276 // save into letter_deb
277 $ld_id=$this->db->get_value('insert into letter_deb(j_id,jl_id) values($1,$2) returning ld_id',
278 array($p_array['ck'][$i], $jl_id));
279 }
280 else
281 {
282 $lc_id=$this->db->get_value('insert into letter_cred(j_id,jl_id) values($1,$2) returning lc_id',
283 array($p_array['ck'][$i], $jl_id));
284 }
285 $acc_reconciliation_lettering=new Acc_Reconciliation_Lettering($this->db);
286 $acc_reconciliation_lettering->insert_reconcilied($p_array['ck'][$i], $p_array['j_id']);
287 } //end for
288
289 }
290 catch (Exception $exc)
291 {
292 echo $exc->getMessage();
293 error_log($exc->getTraceAsString());
294 $this->db->rollback();
295 return;
296 }
297
298
299 $this->db->commit();
300 }
301
302 /**
303 * @brief retrieve * row thanks a condition
304 */
305 public function seek($cond, $p_array=null)
306 {
307 /*
308 $sql="select * from * where $cond";
309 return $this->cn->get_array($cond,$p_array)
310 */
311 }
312
313 public function insert()
314 {
315 if ($this->verify()!=0)
316 return;
317 }
318
319 /**
320 * show all the record from jrnx and their status (linked or not)
321 * it fills the array $this->content
322 */
323 protected function show_all()
324 {
325 $this->get_all();
326 $r="";
327 ob_start();
328 include(NOALYSS_TEMPLATE.'/letter_all.php');
329 $r=ob_get_contents();
330 ob_end_clean();
331 return $r;
332 }
333
334 function get_linked($p_jlid)
335 {
336 $sql="select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,
337 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,jr_pj_number,
338 coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter
339 from jrnx join jrn on (j_grpt = jr_grpt_id)
340 where
341 j_id in (select j_id from letter_cred where jl_id=$1
342 union all
343 select j_id from letter_deb where jl_id=$1)
344 order by j_date";
345
346 $this->linked=$this->db->get_array($sql, array($p_jlid));
347 }
348
349 /**
350 * show only the lettered records from jrnx
351 * it fills the array $this->content
352 */
353 protected function show_lettered()
354 {
355 $this->get_letter();
356 $r="";
357 ob_start();
358 include(NOALYSS_TEMPLATE.'/letter_all.php');
359 $r=ob_get_contents();
360 ob_end_clean();
361 return $r;
362 }
363
364 /**
365 * show only the lettered records from jrnx
366 * it fills the array $this->content
367 */
368 protected function show_lettered_diff()
369 {
370 $this->get_letter_diff();
371 $r="";
372 ob_start();
373 include(NOALYSS_TEMPLATE.'/letter_all.php');
374 $r=ob_get_contents();
375 ob_end_clean();
376 return $r;
377 }
378
379 /**
380 * show only the not lettered records from jrnx
381 * it fills the array $this->content
382 */
383 protected function show_not_lettered()
384 {
385 $this->get_unletter();
386 $r="";
387 ob_start();
388 include(NOALYSS_TEMPLATE.'/letter_all.php');
389 $r=ob_get_contents();
390 ob_end_clean();
391 return $r;
392 }
393 /**
394 * @brief for some reason , sometimes, a record in letter_X doesn't have his counterpart
395 * in letter_Y
396 */
398 {
399 $this->db->exec_sql("delete from letter_cred lc where jl_id not in (select jl_id from letter_deb)");
400 $this->db->exec_sql("delete from letter_deb lc where jl_id not in (select jl_id from letter_cred)");
401 }
402 /**
403 * wrapper : it call show_all, show_lettered or show_not_lettered depending
404 * of the parameter
405 * @param $p_type poss. values are all, unletter, letter
406 */
407 public function show_list($p_type)
408 {
409
410 switch ($p_type)
411 {
412 case 'all':
413 return $this->show_all();
414 break;
415 case 'unletter':
416 return $this->show_not_lettered();
417 break;
418 case 'letter':
419 return $this->show_lettered();
420 break;
421 case 'letter_diff':
422 return $this->show_lettered_diff();
423 break;
424 }
425 throw new Exception("[$p_type] is no unknown");
426 }
427
428 public function show_letter($p_jid)
429 {
430 $j_debit=$this->db->get_value('select j_Debit from jrnx where j_id=$1', array($p_jid));
431 $amount_init=$this->db->get_value('select j_montant from jrnx where j_id=$1', array($p_jid));
432
433 $this->get_filter($p_jid);
434 // retrieve jnt_letter.id
435 $sql="select distinct(jl_id) from jnt_letter left outer join letter_deb using (jl_id) left outer join letter_cred using (jl_id)
436 where letter_deb.j_id = $1 or letter_cred.j_id=$2";
437 $a_jnt_id=$this->db->get_array($sql, array($p_jid, $p_jid));
438
439 if (count($a_jnt_id)==0)
440 {
441 $jnt_id=-2;
442 }
443 else
444 {
445 $jnt_id=$a_jnt_id[0]['jl_id'];
446 }
447 $this->get_linked($jnt_id);
448 ob_start();
449 require_once NOALYSS_TEMPLATE.'/letter_prop.php';
450 $r=ob_get_contents();
451 ob_end_clean();
452 $r.=HtmlInput::hidden('j_id', $p_jid);
453 $r.=HtmlInput::hidden('jnt_id', $jnt_id);
454
455 return $r;
456 }
457
458 public function update()
459 {
460 if ($this->verify()!=0)
461 return;
462 }
463
464 public function load()
465 {
466
467 throw new Exception('load not implemented');
468 }
469
470 public function delete()
471 {
472 throw new Exception('delete not implemented');
473 }
474
475}
476
477/**
478 * only for operation retrieved thanks a account (jrnx.j_poste)
479 * manage the accounting entries for a given account
480 */
482{
483
484 function __construct($p_init, $p_account=null)
485 {
486 parent::__construct($p_init);
487 $this->account=$p_account;
488 $this->object_type='account';
489 }
490
491 /**
492 * fills the this->content, datas are filtered thanks
493 * - fil_deb poss values t (debit), f(credit), ' ' (everything)
494 * - fil_amount_max max amount
495 * - fil_amount_min min amount
496 * - $this->start min date
497 * - $this->end max date
498 * - this->account: accounting
499 */
500 public function get_filter($p_jid=0)
501 {
502 $filter_deb='';
503 if (isset($this->fil_deb))
504 {
505 switch ($this->fil_deb)
506 {
507 case 0:
508 $filter_deb=" and j_debit='t' ";
509 break;
510 case 1:
511 $filter_deb=" and j_debit='f' ";
512 break;
513 case 2:
514 $filter_deb=" ";
515 break;
516 }
517 }
518 $filter_amount="";
519 if (isset($this->fil_amount_max)&&
520 isset($this->fil_amount_min)&&
521 isNumber($this->fil_amount_max)==1&&
522 isNumber($this->fil_amount_min)==1&&
523 ($this->fil_amount_max!=0||$this->fil_amount_min!=0))
524 $filter_amount=" and (j_montant >= $this->fil_amount_min and j_montant<=$this->fil_amount_max "
525 . " or (coalesce(comptaproc.get_letter_jnt($p_jid),-1)= coalesce(comptaproc.get_letter_jnt(j_id),-1) "
526 . " and coalesce(comptaproc.get_letter_jnt($p_jid),-1) <> -1 )) ";
527 $sql="
528 select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,
529 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
530 coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter,
531 jr_pj_number,
532 round(j_montant/currency_rate,4) as currency_amount,
533 currency_rate,
534 currency_rate_ref,
535 (select cr_code_iso from currency where currency_id=currency.id) as cr_code_iso
536 from jrnx join jrn on (j_grpt = jr_grpt_id)
537 where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
538 and $this->sql_ledger
539 $filter_deb
540 $filter_amount
541 order by j_date,j_id";
542
543 $this->content=$this->db->get_array($sql, array($this->account, $this->start, $this->end));
544 }
545
546 /**
547 * fills this->content with all the operation for the this->account(jrnx.j_poste)
548 */
549 public function get_all()
550 {
551 $sql=" with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
552 from
553 ( select jl_id,coalesce(sum(j_montant),0) as cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
554 left join (select jl_id,coalesce(sum(j_montant),0) as deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using (jl_id)) ,
555 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
556 select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
557 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
558 coalesce(let_diff.jl_id,-1) as letter,
559 diff_letter1 as letter_diff,
560 round(j_montant/currency_rate,4) as currency_amount,
561 currency_id,
562 currency_rate,
563 currency_rate_ref,
564 (select cr_code_iso from currency where currency_id=currency.id) as cr_code_iso
565 from jrnx join jrn on (j_grpt = jr_grpt_id)
566 left join letter_jl using (j_id)
567 left join let_diff using (jl_id)
568 where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
569 and $this->sql_ledger
570
571 order by j_date,j_id";
572 $this->content=$this->db->get_array($sql, array($this->account, $this->start, $this->end));
573 }
574
575 /**
576 * same as get_all but only for lettered operation
577 */
578 public function get_letter()
579 {
580 $sql="
581 with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
582 from
583 ( select jl_id,coalesce(sum(j_montant),0) as cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
584 left join (select jl_id,coalesce(sum(j_montant),0) as deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using (jl_id)) ,
585 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
586 select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
587 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
588 let_diff.jl_id as letter,
589 diff_letter1 as letter_diff,
590 round(j_montant/currency_rate,4) as currency_amount,
591 currency_id,
592 currency_rate,
593 currency_rate_ref,
594 (select cr_code_iso from currency where currency_id=currency.id) as cr_code_iso
595 from jrnx join jrn on (j_grpt = jr_grpt_id)
596 join letter_jl using (j_id)
597 left join let_diff using (jl_id)
598 where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
599 and $this->sql_ledger
600 order by j_date,j_id";
601 $this->content=$this->db->get_array($sql, array($this->account, $this->start, $this->end));
602 }
603
604 /**
605 * same as get_all but only for lettered operation
606 */
607 public function get_letter_diff()
608 {
609 $sql="
610 with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
611 from
612 ( select jl_id,coalesce(sum(j_montant),0) as cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
613 left join (select jl_id,coalesce(sum(j_montant),0) as deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using (jl_id)) ,
614 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
615 select distinct j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
616 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
617 let_diff.jl_id as letter,
618 diff_letter1 as letter_diff,
619 round(j_montant/currency_rate,4) as currency_amount,
620 currency_id,
621 currency_rate,
622 currency_rate_ref,
623 (select cr_code_iso from currency where currency_id=currency.id) as cr_code_iso
624 from
625 jrnx join jrn on (j_grpt = jr_grpt_id)
626 join letter_jl using (j_id)
627 join let_diff using (jl_id)
628 where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
629 and $this->sql_ledger
630 and diff_letter1 <> 0
631 order by j_date,j_id";
632 $this->content=$this->db->get_array($sql, array($this->account, $this->start, $this->end));
633 }
634
635 /**
636 * same as get_all but only for unlettered operation
637 */
638 public function get_unletter()
639 {
640 $sql="
641 with letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
642 select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
643 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
644 -1 as letter,
645 0 as letter_diff,
646 round(j_montant/currency_rate,4) as currency_amount,
647 currency_id,
648 currency_rate,
649 currency_rate_ref,
650 (select cr_code_iso from currency where currency_id=currency.id) as cr_code_iso
651 from jrnx join jrn on (j_grpt = jr_grpt_id)
652 where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
653 and $this->sql_ledger
654 and j_id not in (select j_id from letter_jl)
655 order by j_date,j_id";
656 $this->content=$this->db->get_array($sql, array($this->account, $this->start, $this->end));
657 }
658
659}
660
661/**
662 * only for operation retrieved thanks a quick_code
663 * manage the accounting entries for a given card
664 */
666{
667
668 /**
669 * constructor
670 * @param $p_init db resource
671 * @param $p_qcode quick_code of the jrnx.j_id
672 */
673 function __construct($p_init, $p_qcode=null)
674 {
675 parent::__construct($p_init);
676 $this->quick_code=$p_qcode;
677 $this->object_type='card';
678 }
679
680 /**
681 * fills the this->content, datas are filtered thanks
682 * - fil_deb poss values t (debit), f(credit), ' ' (everything)
683 * - fil_amount_max max amount
684 * - fil_amount_min min amount
685 * - $this->start min date
686 * - $this->end max date
687 * - this->quick_code: quick_code
688 */
689 public function get_filter($p_jid=0)
690 {
691 $filter_deb='';
692 if (isset($this->fil_deb))
693 {
694 switch ($this->fil_deb)
695 {
696 case 0:
697 $filter_deb=" and j_debit='t' ";
698 break;
699 case 1:
700 $filter_deb=" and j_debit='f' ";
701 break;
702 case 2:
703 $filter_deb=" ";
704 break;
705 }
706 }
707 $filter_amount="";
708 if (isset($this->fil_amount_max)&&
709 isset($this->fil_amount_min)&&
710 isNumber($this->fil_amount_max)==1&&
711 isNumber($this->fil_amount_min)==1&&
712 ($this->fil_amount_max!=0||$this->fil_amount_min!=0))
713 $filter_amount=" and (j_montant between $this->fil_amount_min and $this->fil_amount_max or (coalesce(comptaproc.get_letter_jnt($p_jid),-1)= coalesce(comptaproc.get_letter_jnt(j_id),-1) and coalesce(comptaproc.get_letter_jnt($p_jid),-1) <> -1 )) ";
714 $sql="
715 with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
716 from
717 ( select jl_id,coalesce(sum(j_montant),0) as cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
718 left join (select jl_id,coalesce(sum(j_montant),0) as deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using (jl_id)) ,
719 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
720 select distinct j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
721 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
722 coalesce(let_diff.jl_id,-1) as letter,
723 diff_letter1 as letter_diff,
724 round(j_montant/currency_rate,4) as currency_amount,
725 currency_rate,
726 currency_rate_ref,
727 (select cr_code_iso from currency where currency_id=currency.id) as cr_code_iso
728 from jrnx join jrn on (j_grpt = jr_grpt_id)
729 left join letter_jl using (j_id)
730 left join let_diff using (jl_id)
731 where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
732 and $this->sql_ledger
733 $filter_deb
734 $filter_amount
735 order by j_date,j_id";
736
737 $this->content=$this->db->get_array($sql, array($this->quick_code, $this->start, $this->end));
738 }
739
740 /**
741 * fills this->content with all the operation for the this->quick_code(j_qcode)
742 */
743 public function get_all()
744 {
745 $sql="
746 with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
747 from
748 ( select jl_id,coalesce(sum(j_montant),0) as cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
749 left join (select jl_id,coalesce(sum(j_montant),0) as deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using (jl_id)) ,
750 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
751 select DISTINCT j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
752 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
753 coalesce(let_diff.jl_id,-1) as letter,
754 diff_letter1 as letter_diff,
755 round(j_montant/currency_rate,4) as currency_amount,
756 currency_rate,
757 currency_id,
758 currency_rate_ref,
759 (select cr_code_iso from currency where currency_id=currency.id) as cr_code_iso
760 from jrnx join jrn on (j_grpt = jr_grpt_id)
761 left join letter_jl using (j_id)
762 left join let_diff using (jl_id)
763 where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
764 and $this->sql_ledger
765
766 order by j_date,j_id";
767 $this->content=$this->db->get_array($sql, array($this->quick_code, $this->start, $this->end));
768 }
769
770 /**
771 * same as get_all but only for lettered operation
772 */
773 public function get_letter()
774 {
775 $sql="
776 with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
777 from
778 ( select jl_id,coalesce(sum(j_montant),0) as cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
779 left join (select jl_id,coalesce(sum(j_montant),0) as deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using (jl_id)) ,
780 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
781 select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
782 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
783 let_diff.jl_id as letter,
784 diff_letter1 as letter_diff,
785 round(j_montant/currency_rate,4) as currency_amount,
786 currency_rate,
787 currency_id,
788 currency_rate_ref,
789 (select cr_code_iso from currency where currency_id=currency.id) as cr_code_iso
790 from jrnx join jrn on (j_grpt = jr_grpt_id)
791 join letter_jl using (j_id)
792 left join let_diff using (jl_id)
793 where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
794 and $this->sql_ledger
795 order by j_date,j_id";
796 $this->content=$this->db->get_array($sql, array($this->quick_code, $this->start, $this->end));
797 }
798
799 public function get_letter_diff()
800 {
801 $sql="
802 with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
803 from
804 ( select jl_id,coalesce(sum(j_montant),0) as cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
805 left join (select jl_id,coalesce(sum(j_montant),0) as deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using (jl_id)) ,
806 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
807 select distinct j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
808 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
809 let_diff.jl_id as letter,
810 diff_letter1 as letter_diff,
811 round(j_montant/currency_rate,4) as currency_amount,
812 currency_id,
813 currency_rate,
814 currency_rate_ref,
815 (select cr_code_iso from currency where currency_id=currency.id) as cr_code_iso
816 from jrnx join jrn on (j_grpt = jr_grpt_id)
817 left join letter_jl using (j_id)
818 left join let_diff using (jl_id)
819 where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
820 and $this->sql_ledger
821 and diff_letter1 <>0
822 order by j_date,j_id";
823 $this->content=$this->db->get_array($sql, array($this->quick_code, $this->start, $this->end));
824 }
825
826 /**
827 * same as get_all but only for unlettered operation
828 */
829 public function get_unletter()
830 {
831 $sql="
832 select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
833 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
834 -1 as letter,
835 0 as letter_diff,
836 round(j_montant/currency_rate,4) as currency_amount,
837 currency_id,
838 currency_rate,
839 currency_rate_ref,
840 (select cr_code_iso from currency where currency_id=currency.id) as cr_code_iso
841 from jrnx join jrn on (j_grpt = jr_grpt_id)
842 where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
843 and $this->sql_ledger
844 and j_id not in (select j_id from letter_deb join jnt_letter using (jl_id) union select j_id from letter_cred join jnt_letter using (jl_id) )
845 order by j_date,j_id";
846 $this->content=$this->db->get_array($sql, array($this->quick_code, $this->start, $this->end));
847 }
848
849 /**
850 * fill $this->content with the rows from this query
851 * Columns are
852 * - j_id, id of jrnx
853 * - j_date, date opeation (yyyy.mm.dd)
854 * - to_char(j_date,'DD.MM.YYYY') as j_date_fmt,
855 * - jr_pj_number, receipt number
856 * - j_montant, amount of the rows
857 * - j_debit, Debit or credit
858 * - jr_comment, label of the operation
859 * - jr_internal, internal number
860 * - jr_id, id of jrn
861 * - jr_def_id, id of the ledger (jrn_def.jrn_def_id)
862 * - coalesce(let_diff.jl_id,-1) as letter, id of the lettering , -1 means unlettered
863 * - diff_letter1 as letter_diff, delta between lettered operation
864 * - extract ('days' from coalesce(jr_date_paid,now())-coalesce(jr_ech,jr_date)) as day_paid, days between operation and payment
865 * - jd1.jrn_def_type type of the ledger (FIN, ODS,VEN or ACH)
866 *
867 *
868 * @param type $p_type value is unlet for unlettered operation or let for everything
869 */
871 {
872 $sql_let=($p_type=='unlet')?' let_diff.jl_id is null and':'';
873 $sql=" with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
874 from
875 ( select jl_id,coalesce(sum(j_montant),0) as cred_amount from letter_cred join jrnx using (j_id) group by jl_id) as CRED
876 left join (select jl_id,coalesce(sum(j_montant),0) as deb_amount from letter_deb join jrnx using (j_id) group by jl_id) as DEB using (jl_id)) ,
877 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
878 select DISTINCT j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
879 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
880 coalesce(let_diff.jl_id,-1) as letter,
881 diff_letter1 as letter_diff,
882 extract ('days' from coalesce(jr_date_paid,now())-jr_date) as day_paid,
883 jd1.jrn_def_type
884 from jrnx join jrn on (j_grpt = jr_grpt_id)
885 join jrn_def as jd1 on (jrn.jr_def_id=jd1.jrn_def_id)
886 left join letter_jl using (j_id)
887 left join let_diff using (jl_id)
888 where
889 {$sql_let}
890 j_qcode = upper($1)
891 and j_date >= to_date($2,'DD.MM.YYYY')
892 and {$this->sql_ledger}
893 and jrn_def_type in ('VEN','ACH')
894 order by j_date,j_id";
895 $this->content=$this->db->get_array($sql, array($this->quick_code, $this->start));
896 }
897
898}
isNumber($p_int)
Definition: ac_common.php:215
noalyss_str_replace($search, $replace, $string)
Definition: ac_common.php:1553
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$idx
catch(Exception $e) $exercice
else $card content[$j]['j_montant']
static hidden($p_name, $p_value, $p_id="")
only for operation retrieved thanks a account (jrnx.j_poste) manage the accounting entries for a give...
get_all()
fills this->content with all the operation for the this->account(jrnx.j_poste)
get_unletter()
same as get_all but only for unlettered operation
get_letter_diff()
same as get_all but only for lettered operation
get_letter()
same as get_all but only for lettered operation
__construct($p_init, $p_account=null)
get_filter($p_jid=0)
fills the this->content, datas are filtered thanks
only for operation retrieved thanks a quick_code manage the accounting entries for a given card
get_letter()
same as get_all but only for lettered operation
__construct($p_init, $p_qcode=null)
constructor
get_unletter()
same as get_all but only for unlettered operation
get_balance_ageing($p_type)
fill $this->content with the rows from this query Columns are
get_all()
fills this->content with all the operation for the this->quick_code(j_qcode)
get_filter($p_jid=0)
fills the this->content, datas are filtered thanks
mother class for the lettering by account and by card use the tables jnt_letter, letter_deb and lette...
show_list($p_type)
wrapper : it call show_all, show_lettered or show_not_lettered depending of the parameter
get_linked($p_jlid)
__construct( $p_init)
constructor
show_not_lettered()
show only the not lettered records from jrnx it fills the array $this->content
remove_incoherent()
for some reason , sometimes, a record in letter_X doesn't have his counterpart in letter_Y
show_lettered_diff()
show only the lettered records from jrnx it fills the array $this->content
seek($cond, $p_array=null)
retrieve * row thanks a condition
show_all()
show all the record from jrnx and their status (linked or not) it fills the array $this->content
insert_couple($j_id1, $j_id2)
Use to just insert a couple of lettered operation but do not make a link between operation.
show_lettered()
show only the lettered records from jrnx it fills the array $this->content
set_parameter($p_string, $p_value)
show_letter($p_jid)
get_parameter($p_string)
save($p_array)
save from array, letter the accounting (or card) and create a link between operation
For the periode tables parm_periode and jrn_periode.
$SecUser db
for($i=0;$i< $nb_jrn;$i++) $deb