25 require_once NOALYSS_INCLUDE.
'/class/class_user.php';
40 "quick_code"=>
"quick_code",
43 "sql_ledger"=>
"sql_ledger"
56 $this->start=
'01.01.'.$exercice;
57 $this->end=
'31.12.'.$exercice;
59 $this->sql_ledger=str_replace(
'jrn_def_id',
'jr_def_id',
$a->get_ledger_sql(
'ALL',3));
64 if ( array_key_exists($p_string,$this->variable) )
66 $idx=$this->variable[$p_string];
70 throw new Exception (__FILE__.
":".__LINE__.$p_string.
'Erreur attribut inexistant');
74 if ( array_key_exists($p_string,$this->variable) )
76 $idx=$this->variable[$p_string];
80 throw new Exception (__FILE__.
":".__LINE__.$p_string.
'Erreur attribut inexistant');
89 $first=$this->
db->get_value(
'select j_debit from jrnx where j_id=$1',array($j_id1));
90 if ( $this->
db->count() == 0 )
throw new Exception (
'Opération non existante');
92 $second=$this->
db->get_value(
'select j_debit from jrnx where j_id=$1',array($j_id2));
93 if ( $this->
db->count() == 0 )
throw new Exception (
'Opération non existante');
94 $sql_already=
"select distinct(jl_id)
96 left outer join letter_deb using (jl_id)
97 left outer join letter_cred using (jl_id)
99 letter_deb.j_id = $1 or letter_cred.j_id=$1";
101 $already=$this->
db->get_array($sql_already,array($j_id1));
102 if ( count ($already ) > 0) {
103 if ( count($already)==1) {
105 $let1=$this->
db->get_value(
"select distinct(jl_id)
107 left outer join letter_deb using (jl_id)
108 left outer join letter_cred using (jl_id)
110 letter_deb.j_id = $1 or letter_cred.j_id=$1",array($j_id1));
117 $already=$this->
db->get_array($sql_already,array($j_id2));
118 if ( count ($already ) > 0) {
119 if ( count($already)==1) {
121 $let2=$this->
db->get_value(
"select distinct(jl_id)
123 left outer join letter_deb using (jl_id)
124 left outer join letter_cred using (jl_id)
126 letter_deb.j_id = $1 or letter_cred.j_id=$1",array($j_id2));
133 if ( $let1 != 0 && $let1 == $let2 )
return;
136 if ( $let1 != 0 && $let2!=0 && $let1 != $let2 )
return;
139 if ( $let1 == 0 && $let2==0)
141 $jl_id=$this->
db->get_next_seq(
"jnt_letter_jl_id_seq");
142 $this->
db->exec_sql(
'insert into jnt_letter(jl_id) values($1)',
146 if ( $let1 == 0 && $let2 != 0 ) $jl_id=$let2;
147 if ( $let1 != 0 && $let2 == 0 ) $jl_id=$let1;
153 if ($let1 == 0) $ld_id=$this->
db->get_value(
'insert into letter_deb(j_id,jl_id) values($1,$2) returning ld_id',array($j_id1,$jl_id));
157 if ($let1 == 0)$lc_id=$this->
db->get_value(
'insert into letter_cred(j_id,jl_id) values($1,$2) returning lc_id',array($j_id1,$jl_id));
162 if ($let2 == 0)$ld_id=$this->
db->get_value(
'insert into letter_deb(j_id,jl_id) values($1,$2) returning ld_id',array($j_id2,$jl_id));
166 if ($let2 == 0)$lc_id=$this->
db->get_value(
'insert into letter_cred(j_id,jl_id) values($1,$2) returning lc_id',array($j_id2,$jl_id));
172 return var_export(self::$variable,
true);
189 if ( ! isset (
$p_array[
'letter_j_id']))
return;
190 $this->
db->exec_sql(
'delete from jnt_letter where jl_id=$1',array(
$p_array[
'jnt_id']));
193 $jl_id=$this->
db->get_next_seq(
"jnt_letter_jl_id_seq");
194 $this->
db->exec_sql(
'insert into jnt_letter(jl_id) values($1)',
198 $deb=$this->
db->get_value(
'select j_debit,j_montant from jrnx where j_id=$1',array(
$p_array[
'j_id']));
202 $ld_id=$this->
db->get_value(
'insert into letter_deb(j_id,jl_id) values($1,$2) returning ld_id',array(
$p_array[
'j_id'],$jl_id));
206 $lc_id=$this->
db->get_value(
'insert into letter_cred(j_id,jl_id) values($1,$2) returning lc_id',array(
$p_array[
'j_id'],$jl_id));
210 for($i=0;$i<count(
$p_array[
'letter_j_id']);$i++)
215 $deb=$this->
db->get_value(
'select j_debit,j_montant from jrnx where j_id=$1',array(
$p_array[
'ck'][$i]));
220 $ld_id=$this->
db->get_value(
'insert into letter_deb(j_id,jl_id) values($1,$2) returning ld_id',array(
$p_array[
'ck'][$i],$jl_id));
225 $lc_id=$this->
db->get_value(
'insert into letter_cred(j_id,jl_id) values($1,$2) returning lc_id',array(
$p_array[
'ck'][$i],$jl_id));
233 $this->
db->rollback();
249 if ( $this->
verify() != 0 )
return;
261 include(NOALYSS_TEMPLATE.
'/letter_all.php');
262 $r=ob_get_contents();
268 $sql=
"select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,
269 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,jr_pj_number,
270 coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter
271 from jrnx join jrn on (j_grpt = jr_grpt_id)
273 j_id in (select j_id from letter_cred where jl_id=$1
275 select j_id from letter_deb where jl_id=$1)
278 $this->linked=$this->
db->get_array(
$sql,array($p_jlid));
289 include(NOALYSS_TEMPLATE.
'/letter_all.php');
290 $r=ob_get_contents();
300 $this->get_letter_diff();
303 include(NOALYSS_TEMPLATE.
'/letter_all.php');
304 $r=ob_get_contents();
316 $this->get_unletter();
319 include(NOALYSS_TEMPLATE.
'/letter_all.php');
320 $r=ob_get_contents();
346 throw new Exception (
"[$p_type] is no unknown");
351 $j_debit=$this->
db->get_value(
'select j_Debit from jrnx where j_id=$1',array($p_jid));
352 $amount_init=$this->
db->get_value(
'select j_montant from jrnx where j_id=$1',array($p_jid));
354 $this->get_filter($p_jid);
356 $sql=
"select distinct(jl_id) from jnt_letter left outer join letter_deb using (jl_id) left outer join letter_cred using (jl_id)
357 where letter_deb.j_id = $1 or letter_cred.j_id=$2";
358 $a_jnt_id=$this->
db->get_array(
$sql,array($p_jid,$p_jid));
360 if (count($a_jnt_id)==0 )
365 $jnt_id=$a_jnt_id[0][
'jl_id'];
369 require_once NOALYSS_TEMPLATE.
'/letter_prop.php';
370 $r=ob_get_contents();
380 if ( $this->
verify() != 0 )
return;
386 public function delete()
388 throw new Exception (
'delete not implemented');
406 parent::__construct($p_init);
407 $this->account=$p_account;
408 $this->object_type=
'account';
423 if (isset($this->fil_deb))
425 switch ($this->fil_deb)
428 $filter_deb=
" and j_debit='t' ";
431 $filter_deb=
" and j_debit='f' ";
440 if ( isset ($this->fil_amount_max ) &&
441 isset ($this->fil_amount_min ) &&
442 isNumber($this->fil_amount_max)==1 &&
443 isNumber($this->fil_amount_min)==1 &&
444 ($this->fil_amount_max != 0 || $this->fil_amount_min != 0) )
445 $filter_amount=
" and (j_montant >= $this->fil_amount_min and j_montant<=$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 )) ";
447 select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,
448 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
449 coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter,
451 from jrnx join jrn on (j_grpt = jr_grpt_id)
452 where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
453 and $this->sql_ledger
456 order by j_date,j_id";
458 $this->
content=$this->
db->get_array(
$sql,array($this->account,$this->start,$this->end));
466 $sql=
" with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
468 ( 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
469 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)) ,
470 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
471 select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
472 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
473 coalesce(let_diff.jl_id,-1) as letter,
474 diff_letter1 as letter_diff
475 from jrnx join jrn on (j_grpt = jr_grpt_id)
476 left join letter_jl using (j_id)
477 left join let_diff using (jl_id)
478 where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
479 and $this->sql_ledger
481 order by j_date,j_id";
482 $this->
content=$this->
db->get_array(
$sql,array($this->account,$this->start,$this->end));
490 with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
492 ( 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
493 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)) ,
494 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
495 select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
496 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
497 let_diff.jl_id as letter,
498 diff_letter1 as letter_diff
499 from jrnx join jrn on (j_grpt = jr_grpt_id)
500 join letter_jl using (j_id)
501 left join let_diff using (jl_id)
502 where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
503 and $this->sql_ledger
504 order by j_date,j_id";
505 $this->
content=$this->
db->get_array(
$sql,array($this->account,$this->start,$this->end));
513 with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
515 ( 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
516 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)) ,
517 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
518 select distinct j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
519 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
520 let_diff.jl_id as letter,
521 diff_letter1 as letter_diff
523 jrnx join jrn on (j_grpt = jr_grpt_id)
524 join letter_jl using (j_id)
525 join let_diff using (jl_id)
526 where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
527 and $this->sql_ledger
528 and diff_letter1 <> 0
529 order by j_date,j_id";
530 $this->
content=$this->
db->get_array(
$sql,array($this->account,$this->start,$this->end));
539 with letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
540 select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
541 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
544 from jrnx join jrn on (j_grpt = jr_grpt_id)
545 where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
546 and $this->sql_ledger
547 and j_id not in (select j_id from letter_jl)
548 order by j_date,j_id";
549 $this->
content=$this->
db->get_array(
$sql,array($this->account,$this->start,$this->end));
566 parent::__construct($p_init);
567 $this->quick_code=$p_qcode;
568 $this->object_type=
'card';
582 if (isset($this->fil_deb))
584 switch ($this->fil_deb)
587 $filter_deb=
" and j_debit='t' ";
590 $filter_deb=
" and j_debit='f' ";
599 if ( isset ($this->fil_amount_max ) &&
600 isset ($this->fil_amount_min ) &&
601 isNumber($this->fil_amount_max)==1 &&
602 isNumber($this->fil_amount_min)==1 &&
603 ($this->fil_amount_max != 0 || $this->fil_amount_min != 0) )
604 $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 )) ";
606 with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
608 ( 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
609 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)) ,
610 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
611 select distinct j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
612 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
613 coalesce(let_diff.jl_id,-1) as letter,
614 diff_letter1 as letter_diff
615 from jrnx join jrn on (j_grpt = jr_grpt_id)
616 left join letter_jl using (j_id)
617 left join let_diff using (jl_id)
618 where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
619 and $this->sql_ledger
622 order by j_date,j_id";
624 $this->
content=$this->
db->get_array(
$sql,array($this->quick_code,$this->start,$this->end));
632 with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
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 coalesce(let_diff.jl_id,-1) as letter,
640 diff_letter1 as letter_diff
641 from jrnx join jrn on (j_grpt = jr_grpt_id)
642 left join letter_jl using (j_id)
643 left join let_diff using (jl_id)
644 where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
645 and $this->sql_ledger
647 order by j_date,j_id";
648 $this->
content=$this->
db->get_array(
$sql,array($this->quick_code,$this->start,$this->end));
657 with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
659 ( 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
660 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)) ,
661 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
662 select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
663 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
664 let_diff.jl_id as letter,
665 diff_letter1 as letter_diff
666 from jrnx join jrn on (j_grpt = jr_grpt_id)
667 join letter_jl using (j_id)
668 left join let_diff using (jl_id)
669 where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
670 and $this->sql_ledger
671 order by j_date,j_id";
672 $this->
content=$this->
db->get_array(
$sql,array($this->quick_code,$this->start,$this->end));
677 with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
679 ( 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
680 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)) ,
681 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
682 select distinct j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
683 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
684 let_diff.jl_id as letter,
685 diff_letter1 as letter_diff
686 from jrnx join jrn on (j_grpt = jr_grpt_id)
687 left join letter_jl using (j_id)
688 left join let_diff using (jl_id)
689 where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
690 and $this->sql_ledger
692 order by j_date,j_id";
693 $this->
content=$this->
db->get_array(
$sql,array($this->quick_code,$this->start,$this->end));
701 select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
702 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
705 from jrnx join jrn on (j_grpt = jr_grpt_id)
706 where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
707 and $this->sql_ledger
708 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) )
709 order by j_date,j_id";
710 $this->
content=$this->
db->get_array(
$sql,array($this->quick_code,$this->start,$this->end));
735 $sql_let = (
$p_type ==
'unlet')?
' let_diff.jl_id is null and':
'';
737 " with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
739 ( 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
740 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)) ,
741 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
742 select DISTINCT j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
743 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
744 coalesce(let_diff.jl_id,-1) as letter,
745 diff_letter1 as letter_diff,
746 extract ('days' from coalesce(jr_date_paid,now())-coalesce(jr_ech,jr_date)) as day_paid,
748 from jrnx join jrn on (j_grpt = jr_grpt_id)
749 join jrn_def as jd1 on (jrn.jr_def_id=jd1.jrn_def_id)
750 left join letter_jl using (j_id)
751 left join let_diff using (jl_id)
755 and j_date >= to_date($2,'DD.MM.YYYY')
756 and {$this->sql_ledger}
757 order by j_date,j_id";
758 $this->
content=$this->
db->get_array(
$sql,array($this->quick_code,$this->start));
insert_couple($j_id1, $j_id2)
Use to just insert a couple of lettered operation.
mother class for the lettering by account and by card use the tables jnt_letter, letter_deb and lette...
get_all()
fills this->content with all the operation for the this->quick_code(j_qcode)
__construct($p_init)
constructor
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
only for operation retrieved thanks a quick_code manage the accounting entries for a given card ...
set_parameter($p_string, $p_value)
only for operation retrieved thanks a account (jrnx.j_poste) manage the accounting entries for a give...
get_filter($p_jid=0)
fills the this->content, datas are filtered thanks
Data & function about connected users.
get_unletter()
same as get_all but only for unlettered operation
static test_me()
Unit test for the class.
save($p_array)
save from array
get_balance_ageing($p_type)
fill $this->content with the rows from this query Columns are
show_lettered()
show only the lettered records from jrnx it fills the array $this->content
for($i=0;$i<$nb_jrn;$i++) $deb
__construct($p_init, $p_qcode=null)
constructor
get_letter_diff()
same as get_all but only for lettered operation
get_letter()
same as get_all but only for lettered operation
show_not_lettered()
show only the not lettered records from jrnx it fills the array $this->content
get_unletter()
same as get_all but only for unlettered operation
get_filter($p_jid=0)
fills the this->content, datas are filtered thanks
get_letter()
same as get_all but only for lettered operation
get_all()
fills this->content with all the operation for the this->account(jrnx.j_poste)
show_list($p_type)
wrapper : it call show_all, show_lettered or show_not_lettered depending of the parameter ...
show_all()
show all the record from jrnx and their status (linked or not) it fills the array $this->content ...
else $card content[$j]['j_montant']
__construct($p_init, $p_account=null)