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