00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 require_once ('class_user.php');
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 class Lettering
00037 {
00038
00039 protected $variable=array("account"=>"account",
00040 "quick_code"=>"quick_code",
00041 "start"=>"start",
00042 "end"=>"end",
00043 "sql_ledger"=>"sql_ledger"
00044 )
00045 ;
00046
00047
00048
00049
00050
00051 function __construct ($p_init)
00052 {
00053 $this->db=$p_init;
00054 $a=new User($p_init);
00055 $exercice=$a->get_exercice();
00056 $this->start='01.01.'.$exercice;
00057 $this->end='31.12.'.$exercice;
00058
00059 $this->sql_ledger=str_replace('jrn_def_id','jr_def_id',$a->get_ledger_sql('ALL',3));
00060
00061 }
00062 public function get_parameter($p_string)
00063 {
00064 if ( array_key_exists($p_string,$this->variable) )
00065 {
00066 $idx=$this->variable[$p_string];
00067 return $this->$idx;
00068 }
00069 else
00070 throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur attribut inexistant');
00071 }
00072 public function set_parameter($p_string,$p_value)
00073 {
00074 if ( array_key_exists($p_string,$this->variable) )
00075 {
00076 $idx=$this->variable[$p_string];
00077 $this->$idx=$p_value;
00078 }
00079 else
00080 throw new Exception (__FILE__.":".__LINE__.$p_string.'Erreur attribut inexistant');
00081 }
00082
00083
00084
00085 function insert_couple($j_id1,$j_id2)
00086 {
00087
00088
00089 $first=$this->db->get_value('select j_debit from jrnx where j_id=$1',array($j_id1));
00090 if ( $this->db->count() == 0 ) throw new Exception ('Opération non existante');
00091
00092 $second=$this->db->get_value('select j_debit from jrnx where j_id=$1',array($j_id2));
00093 if ( $this->db->count() == 0 ) throw new Exception ('Opération non existante');
00094 $sql_already="select distinct(jl_id)
00095 from jnt_letter
00096 left outer join letter_deb using (jl_id)
00097 left outer join letter_cred using (jl_id)
00098 where
00099 letter_deb.j_id = $1 or letter_cred.j_id=$1";
00100 $let1=0;$let2=0;
00101 $already=$this->db->get_array($sql_already,array($j_id1));
00102 if ( count ($already ) > 0) {
00103 if ( count($already)==1) {
00104
00105 $let1=$this->db->get_value("select distinct(jl_id)
00106 from jnt_letter
00107 left outer join letter_deb using (jl_id)
00108 left outer join letter_cred using (jl_id)
00109 where
00110 letter_deb.j_id = $1 or letter_cred.j_id=$1",array($j_id1));
00111 }else
00112 {
00113 return;
00114 }
00115 }
00116
00117 $already=$this->db->get_array($sql_already,array($j_id2));
00118 if ( count ($already ) > 0) {
00119 if ( count($already)==1) {
00120
00121 $let2=$this->db->get_value("select distinct(jl_id)
00122 from jnt_letter
00123 left outer join letter_deb using (jl_id)
00124 left outer join letter_cred using (jl_id)
00125 where
00126 letter_deb.j_id = $1 or letter_cred.j_id=$1",array($j_id2));
00127 }else {
00128 return;
00129 }
00130 }
00131 $jl_id=0;
00132
00133 if ( $let1 != 0 && $let1 == $let2 )return;
00134
00135
00136 if ( $let1 != 0 && $let2!=0 && $let1 != $let2 )return;
00137
00138
00139 if ( $let1 == 0 && $let2==0)
00140 {
00141 $jl_id=$this->db->get_next_seq("jnt_letter_jl_id_seq");
00142 $this->db->exec_sql('insert into jnt_letter(jl_id) values($1)',
00143 array($jl_id));
00144 }
00145
00146 if ( $let1 == 0 && $let2 != 0 ) $jl_id=$let2;
00147 if ( $let1 != 0 && $let2 == 0 ) $jl_id=$let1;
00148
00149
00150 if ( $first == 't')
00151 {
00152
00153 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));
00154 }
00155 else
00156 {
00157 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));
00158 }
00159 if ( $second == 't')
00160 {
00161
00162 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));
00163 }
00164 else
00165 {
00166 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));
00167 }
00168
00169 }
00170 public function get_info()
00171 {
00172 return var_export(self::$variable,true);
00173 }
00174 public function verify()
00175 {
00176
00177 }
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187 public function save($p_array)
00188 {
00189 if ( ! isset ($p_array['letter_j_id'])) return;
00190 $this->db->exec_sql('delete from jnt_letter where jl_id=$1',array($p_array['jnt_id']));
00191
00192 $this->db->start();
00193 $jl_id=$this->db->get_next_seq("jnt_letter_jl_id_seq");
00194 $this->db->exec_sql('insert into jnt_letter(jl_id) values($1)',
00195 array($jl_id));
00196
00197
00198 $deb=$this->db->get_value('select j_debit,j_montant from jrnx where j_id=$1',array($p_array['j_id']));
00199 if ( $deb == 't')
00200 {
00201
00202 $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));
00203 }
00204 else
00205 {
00206 $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));
00207 }
00208 $count=0;
00209
00210 for($i=0;$i<count($p_array['letter_j_id']);$i++)
00211 {
00212 if (isset ($p_array['ck'][$i]) && $p_array['ck'][$i] !="-2")
00213 {
00214
00215 $deb=$this->db->get_value('select j_debit,j_montant from jrnx where j_id=$1',array($p_array['ck'][$i]));
00216 if ( $deb == 't')
00217 {
00218 $count++;
00219
00220 $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));
00221 }
00222 else
00223 {
00224 $count++;
00225 $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));
00226 }
00227 }
00228 }
00229
00230
00231 if ( $count==0)
00232 {
00233 $this->db->rollback();
00234 }
00235 $this->db->commit();
00236 }
00237
00238
00239
00240 public function seek($cond,$p_array=null)
00241 {
00242
00243
00244
00245
00246 }
00247 public function insert()
00248 {
00249 if ( $this->verify() != 0 ) return;
00250
00251 }
00252
00253
00254
00255
00256 protected function show_all()
00257 {
00258 $this->get_all();
00259 $r="";
00260 ob_start();
00261 include('template/letter_all.php');
00262 $r=ob_get_contents();
00263 ob_end_clean();
00264 return $r;
00265 }
00266 function get_linked($p_jlid)
00267 {
00268 $sql="select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,
00269 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
00270 coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter
00271 from jrnx join jrn on (j_grpt = jr_grpt_id)
00272 where
00273 j_id in (select j_id from letter_cred where jl_id=$1
00274 union all
00275 select j_id from letter_deb where jl_id=$1)
00276 order by j_date";
00277
00278 $this->linked=$this->db->get_array($sql,array($p_jlid));
00279 }
00280
00281
00282
00283
00284 protected function show_lettered()
00285 {
00286 $this->get_letter();
00287 $r="";
00288 ob_start();
00289 include('template/letter_all.php');
00290 $r=ob_get_contents();
00291 ob_end_clean();
00292 return $r;
00293 }
00294
00295
00296
00297
00298 protected function show_lettered_diff()
00299 {
00300 $this->get_letter_diff();
00301 $r="";
00302 ob_start();
00303 include('template/letter_all.php');
00304 $r=ob_get_contents();
00305 ob_end_clean();
00306 return $r;
00307 }
00308
00309
00310
00311
00312
00313
00314 protected function show_not_lettered()
00315 {
00316 $this->get_unletter();
00317 $r="";
00318 ob_start();
00319 include('template/letter_all.php');
00320 $r=ob_get_contents();
00321 ob_end_clean();
00322 return $r;
00323 }
00324
00325
00326
00327
00328
00329 public function show_list($p_type)
00330 {
00331 switch($p_type)
00332 {
00333 case 'all':
00334 return $this->show_all();
00335 break;
00336 case 'unletter':
00337 return $this->show_not_lettered();
00338 break;
00339 case 'letter':
00340 return $this->show_lettered();
00341 break;
00342 case 'letter_diff':
00343 return $this->show_lettered_diff();
00344 break;
00345 }
00346 throw new Exception ("[$p_type] is no unknown");
00347 }
00348
00349 public function show_letter($p_jid)
00350 {
00351 $j_debit=$this->db->get_value('select j_Debit from jrnx where j_id=$1',array($p_jid));
00352 $amount_init=$this->db->get_value('select j_montant from jrnx where j_id=$1',array($p_jid));
00353
00354 $this->get_filter($p_jid);
00355
00356 $sql="select distinct(jl_id) from jnt_letter left outer join letter_deb using (jl_id) left outer join letter_cred using (jl_id)
00357 where letter_deb.j_id = $1 or letter_cred.j_id=$2";
00358 $a_jnt_id=$this->db->get_array($sql,array($p_jid,$p_jid));
00359
00360 if (count($a_jnt_id)==0 )
00361 {
00362 $jnt_id=-2;
00363 } else
00364 {
00365 $jnt_id=$a_jnt_id[0]['jl_id'];
00366 }
00367 $this->get_linked($jnt_id);
00368 ob_start();
00369 require_once('template/letter_prop.php');
00370 $r=ob_get_contents();
00371 ob_end_clean();
00372 $r.=HtmlInput::hidden('j_id',$p_jid);
00373 $r.=HtmlInput::hidden('jnt_id',$jnt_id);
00374
00375 return $r;
00376 }
00377
00378 public function update()
00379 {
00380 if ( $this->verify() != 0 ) return;
00381 }
00382
00383 public function load()
00384 {}
00385
00386 public function delete()
00387 {
00388 throw new Exception ('delete not implemented');
00389 }
00390
00391
00392
00393 static function test_me()
00394 {}
00395
00396 }
00397
00398
00399
00400
00401
00402 class Lettering_Account extends Lettering
00403 {
00404 function __construct($p_init,$p_account=null)
00405 {
00406 parent::__construct($p_init);
00407 $this->account=$p_account;
00408 $this->object_type='account';
00409 }
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420 public function get_filter($p_jid=0)
00421 {
00422 $filter_deb='';
00423 if (isset($this->fil_deb))
00424 {
00425 switch ($this->fil_deb)
00426 {
00427 case 0:
00428 $filter_deb=" and j_debit='t' ";
00429 break;
00430 case 1:
00431 $filter_deb=" and j_debit='f' ";
00432 break;
00433 case 2:
00434 $filter_deb=" ";
00435 break;
00436 }
00437
00438 }
00439 $filter_amount="";
00440 if ( isset ($this->fil_amount_max ) &&
00441 isset ($this->fil_amount_min ) &&
00442 isNumber($this->fil_amount_max)==1 &&
00443 isNumber($this->fil_amount_min)==1 &&
00444 ($this->fil_amount_max != 0 || $this->fil_amount_min != 0) )
00445 $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 )) ";
00446 $sql="
00447 select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,
00448 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
00449 coalesce(comptaproc.get_letter_jnt(j_id),-1) as letter
00450 from jrnx join jrn on (j_grpt = jr_grpt_id)
00451 where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
00452 and $this->sql_ledger
00453 $filter_deb
00454 $filter_amount
00455 order by j_date,j_id";
00456
00457 $this->content=$this->db->get_array($sql,array($this->account,$this->start,$this->end));
00458 }
00459
00460
00461
00462
00463 public function get_all()
00464 {
00465 $sql=" with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
00466 from
00467 ( 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
00468 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)) ,
00469 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
00470 select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
00471 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
00472 coalesce(let_diff.jl_id,-1) as letter,
00473 diff_letter1 as letter_diff
00474 from jrnx join jrn on (j_grpt = jr_grpt_id)
00475 left join letter_jl using (j_id)
00476 left join let_diff using (jl_id)
00477 where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
00478 and $this->sql_ledger
00479
00480 order by j_date,j_id";
00481 $this->content=$this->db->get_array($sql,array($this->account,$this->start,$this->end));
00482 }
00483
00484
00485
00486 public function get_letter()
00487 {
00488 $sql="
00489 with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
00490 from
00491 ( 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
00492 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)) ,
00493 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
00494 select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
00495 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
00496 let_diff.jl_id as letter,
00497 diff_letter1 as letter_diff
00498 from jrnx join jrn on (j_grpt = jr_grpt_id)
00499 join letter_jl using (j_id)
00500 left join let_diff using (jl_id)
00501 where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
00502 and $this->sql_ledger
00503 order by j_date,j_id";
00504 $this->content=$this->db->get_array($sql,array($this->account,$this->start,$this->end));
00505 }
00506
00507
00508
00509 public function get_letter_diff()
00510 {
00511 $sql="
00512 with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
00513 from
00514 ( 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
00515 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)) ,
00516 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
00517 select distinct j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
00518 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
00519 let_diff.jl_id as letter,
00520 diff_letter1 as letter_diff
00521 from
00522 jrnx join jrn on (j_grpt = jr_grpt_id)
00523 join letter_jl using (j_id)
00524 join let_diff using (jl_id)
00525 where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
00526 and $this->sql_ledger
00527 and diff_letter1 <> 0
00528 order by j_date,j_id";
00529 $this->content=$this->db->get_array($sql,array($this->account,$this->start,$this->end));
00530 }
00531
00532
00533
00534
00535 public function get_unletter()
00536 {
00537 $sql="
00538 with letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
00539 select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
00540 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
00541 -1 as letter,
00542 0 as letter_diff
00543 from jrnx join jrn on (j_grpt = jr_grpt_id)
00544 where j_poste = $1 and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
00545 and $this->sql_ledger
00546 and j_id not in (select j_id from letter_jl)
00547 order by j_date,j_id";
00548 $this->content=$this->db->get_array($sql,array($this->account,$this->start,$this->end));
00549 }
00550
00551 }
00552
00553
00554
00555
00556 class Lettering_Card extends Lettering
00557 {
00558
00559
00560
00561
00562
00563 function __construct($p_init,$p_qcode=null)
00564 {
00565 parent::__construct($p_init);
00566 $this->quick_code=$p_qcode;
00567 $this->object_type='card';
00568 }
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578 public function get_filter($p_jid=0)
00579 {
00580 $filter_deb='';
00581 if (isset($this->fil_deb))
00582 {
00583 switch ($this->fil_deb)
00584 {
00585 case 0:
00586 $filter_deb=" and j_debit='t' ";
00587 break;
00588 case 1:
00589 $filter_deb=" and j_debit='f' ";
00590 break;
00591 case 2:
00592 $filter_deb=" ";
00593 break;
00594 }
00595
00596 }
00597 $filter_amount="";
00598 if ( isset ($this->fil_amount_max ) &&
00599 isset ($this->fil_amount_min ) &&
00600 isNumber($this->fil_amount_max)==1 &&
00601 isNumber($this->fil_amount_min)==1 &&
00602 ($this->fil_amount_max != 0 || $this->fil_amount_min != 0) )
00603 $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 )) ";
00604 $sql="
00605 with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
00606 from
00607 ( 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
00608 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)) ,
00609 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
00610 select distinct j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
00611 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
00612 coalesce(let_diff.jl_id,-1) as letter,
00613 diff_letter1 as letter_diff
00614 from jrnx join jrn on (j_grpt = jr_grpt_id)
00615 left join letter_jl using (j_id)
00616 left join let_diff using (jl_id)
00617 where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
00618 and $this->sql_ledger
00619 $filter_deb
00620 $filter_amount
00621 order by j_date,j_id";
00622
00623 $this->content=$this->db->get_array($sql,array($this->quick_code,$this->start,$this->end));
00624 }
00625
00626
00627
00628 public function get_all()
00629 {
00630 $sql="
00631 with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
00632 from
00633 ( 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
00634 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)) ,
00635 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
00636 select DISTINCT j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
00637 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
00638 coalesce(let_diff.jl_id,-1) as letter,
00639 diff_letter1 as letter_diff
00640 from jrnx join jrn on (j_grpt = jr_grpt_id)
00641 left join letter_jl using (j_id)
00642 left join let_diff using (jl_id)
00643 where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
00644 and $this->sql_ledger
00645
00646 order by j_date,j_id";
00647 $this->content=$this->db->get_array($sql,array($this->quick_code,$this->start,$this->end));
00648 }
00649
00650
00651
00652
00653 public function get_letter()
00654 {
00655 $sql="
00656 with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
00657 from
00658 ( 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
00659 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)) ,
00660 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
00661 select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
00662 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
00663 let_diff.jl_id as letter,
00664 diff_letter1 as letter_diff
00665 from jrnx join jrn on (j_grpt = jr_grpt_id)
00666 join letter_jl using (j_id)
00667 left join let_diff using (jl_id)
00668 where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
00669 and $this->sql_ledger
00670 order by j_date,j_id";
00671 $this->content=$this->db->get_array($sql,array($this->quick_code,$this->start,$this->end));
00672 }
00673 public function get_letter_diff()
00674 {
00675 $sql="
00676 with let_diff as (select jl_id,deb_amount-cred_amount as diff_letter1
00677 from
00678 ( 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
00679 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)) ,
00680 letter_jl as (select jl_id,j_id from letter_cred union all select jl_id,j_id from letter_deb)
00681 select distinct j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
00682 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
00683 let_diff.jl_id as letter,
00684 diff_letter1 as letter_diff
00685 from jrnx join jrn on (j_grpt = jr_grpt_id)
00686 left join letter_jl using (j_id)
00687 left join let_diff using (jl_id)
00688 where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
00689 and $this->sql_ledger
00690 and diff_letter1 <>0
00691 order by j_date,j_id";
00692 $this->content=$this->db->get_array($sql,array($this->quick_code,$this->start,$this->end));
00693 }
00694
00695
00696
00697 public function get_unletter()
00698 {
00699 $sql="
00700 select j_id,j_date,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,jr_pj_number,
00701 j_montant,j_debit,jr_comment,jr_internal,jr_id,jr_def_id,
00702 -1 as letter,
00703 0 as letter_diff
00704 from jrnx join jrn on (j_grpt = jr_grpt_id)
00705 where j_qcode = upper($1) and j_date >= to_date($2,'DD.MM.YYYY') and j_date <= to_date ($3,'DD.MM.YYYY')
00706 and $this->sql_ledger
00707 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) )
00708 order by j_date,j_id";
00709 $this->content=$this->db->get_array($sql,array($this->quick_code,$this->start,$this->end));
00710 }
00711
00712 }