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