From 2068dfa6377e9ee7478cdaaa8460881d87729240 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Sun, 13 Feb 2005 16:08:21 +0000 Subject: [PATCH] Change for centralise to have the correct order, number for pj Change printing for the operation id update the patch sql for that --- html/admin/sql/patch/upgrade4.sql | 7 +++++ html/dossier_prefs.php | 6 +++++ html/jrn_csv.php | 6 +++-- html/jrn_pdf.php | 15 ++++------- include/central_inc.php | 40 +++++++++++++++++++++++++++- include/class_jrn.php | 43 +++++++++++++++++++------------ include/impress_inc.php | 7 ++--- include/impress_jrn.php | 11 +++++--- 8 files changed, 99 insertions(+), 36 deletions(-) diff --git a/html/admin/sql/patch/upgrade4.sql b/html/admin/sql/patch/upgrade4.sql index c392d1d83..688091add 100644 --- a/html/admin/sql/patch/upgrade4.sql +++ b/html/admin/sql/patch/upgrade4.sql @@ -22,6 +22,8 @@ comment on table parm_periode is 'Periode definition'; comment on table stock_goods is 'About the goods'; comment on table tmp_pcmn is 'Plan comptable minimum normalisé'; comment on table tva_rate is 'Rate of vat'; +create sequence s_central; + -- create index x_jr_grpt_id on jrn (jr_grpt_id); -- create index x_j_grpt on jrnx(j_grpt); create index x_poste on jrnx(j_poste ); @@ -30,6 +32,11 @@ delete from fiche where f_id not in (select f_id from jnt_fic_att_value); alter table jrn add j_pj int4; alter table jrn add jr_opid int4; update version set val=4; +alter table jrn add jr_c_opid int4; +create SEQUENCE s_central_order; +alter table centralized add c_order int4; + + -- decentralize delete from centralized; create sequence s_internal; diff --git a/html/dossier_prefs.php b/html/dossier_prefs.php index 7f574f41f..b1a124dc5 100644 --- a/html/dossier_prefs.php +++ b/html/dossier_prefs.php @@ -156,8 +156,14 @@ if ( $p_action=="closed") { if ( $p_action== "delete_per" ) { $p_per=$_GET["p_per"]; +// Check if the periode is not used + if ( CountSql($cn,"select * from jrnx where j_tech_per=$p_per") != 0 ) { + echo '

Désolé mais cette période est utilisée

'; + } else + { $Res=ExecSql($cn,"delete from parm_periode where p_id=$p_per"); ShowPeriode($cn); + } } if ( $p_action == "periode" ) { diff --git a/html/jrn_csv.php b/html/jrn_csv.php index 3e069741e..f5060a787 100644 --- a/html/jrn_csv.php +++ b/html/jrn_csv.php @@ -41,7 +41,7 @@ if ( $g_UserProperty['use_admin'] == 0 ) { } - $p_cent=( isset ( $_POST['cent']) )?'on':'off'; + $p_cent=( isset ( $_POST['central']) )?'on':'off'; $Jrn=new jrn($cn,$_POST['jrn_id']); // $Jrn->Access(); @@ -59,7 +59,9 @@ $Jrn->GetRow( $_POST['from_periode'], $desc=str_replace("","",$desc); $desc=str_replace("","",$desc); $desc=str_replace('"',"'",$desc); - printf("\"%s\"\t\"%s\"\t\"%s\"\t\"%s\"\t%8.4f\t%8.4f\n", + + printf("\"%s\"\t\"%s\"\t\"%s\"\t\"%s\"\t\"%s\"\t%8.4f\t%8.4f\n", + $op['j_id'], $op['internal'], $op['j_date'], $op['poste'], diff --git a/html/jrn_pdf.php b/html/jrn_pdf.php index 5cbbbb5be..70d3e1b47 100644 --- a/html/jrn_pdf.php +++ b/html/jrn_pdf.php @@ -64,7 +64,7 @@ $pdf->selectFont('./addon/fonts/Helvetica.afm'); // filter : 0 for Grand Livre otherwise 1 $filter=( $Jrn->id == 0)?0:1; -$offset=0;$limit=25;$step=25; +$offset=0;$limit=22;$step=22; $rap_deb=0;$rap_cred=0; while (1) { $a=0; @@ -76,12 +76,7 @@ while (1) { if ( $a_jrn==null) break; $offset+=$step; -// foreach ($a_jrn as $key=>$element) { -// echo_debug(__FILE__,__LINE__,"$key => $element"); -// foreach ($element as $c1=>$c2) -// echo_debug(__FILE__,__LINE__,"Array is $c1 => $c2"); -// } - $first_id=$a_jrn[0]['j_id']; + $first_id=$a_jrn[0]['int_j_id']; $Exercice=GetExercice($cn,$a_jrn[0]['periode']); @@ -102,7 +97,7 @@ while (1) { } $pdf->ezTable($a_jrn, - array ('internal'=>'Opération', + array ('j_id'=>' Numéro', 'j_date' => 'Date', 'poste'=>'Poste', 'description' => 'Description', @@ -125,7 +120,7 @@ while (1) { 'cred'=> array('justification'=>'right')))); $count=count($a_jrn)-1; - $last_id=$a_jrn[$count]['j_id']; + $last_id=$a_jrn[$count]['int_j_id']; $Exercice=GetExercice($cn,$a_jrn[$count]['periode']); if ( $l_centr == 1) { // Montant de rappel si centralisé @@ -148,7 +143,7 @@ $pdf->ezTable($apage, 'cols'=>array('deb'=> array('justification'=>'right'), 'cred'=> array('justification'=>'right')))); $count=count($a_jrn)-1; - $last_id=$a_jrn[$count]['j_id']; + $last_id=$a_jrn[$count]['int_j_id']; $Exercice=GetExercice($cn,$a_jrn[$count]['periode']); list($rap_deb,$rap_cred)=GetRappel($cn,$last_id,$Jrn->id,$Exercice,LAST,$filter,$l_centr); diff --git a/include/central_inc.php b/include/central_inc.php index b128a7a1e..7f28620d3 100644 --- a/include/central_inc.php +++ b/include/central_inc.php @@ -99,8 +99,46 @@ $sql="insert into centralized( c_j_id, $Ret=ExecSql($p_cn,$sql); if ($Res==false) { rollback($p_cn); EndSql($p_cn); return ERROR;} } - } + // Put jr_c_opid in centralized + // for each jrn_def_id + // get the op related to that jrn_def_id + $sql=sprintf("select jr_id from jrn + where + jr_tech_per=%d + order by jr_date,jr_grpt_id desc", + $p_periode + ); + + $Res2=ExecSql($p_cn,$sql); + $MaxLine=pg_NumRows($Res2); + for ($e=0;$e < $MaxLine;$e++) { + // each line is updated with a sequence + $line=pg_fetch_array($Res2,$e); + $jr_id=$line['jr_id']; + $sql=sprintf ("update jrn set + jr_c_opid = (select nextval('s_central')) + where jr_id =%d", + $jr_id); + $Ret=ExecSql($p_cn,$sql); + if ($Ret==false) { rollback($p_cn); EndSql($p_cn); return ERROR;} + } + // Set the order of the jrn + $Res=ExecSql($p_cn,"select c_id from centralized + inner join jrn on c_grp = jr_grpt_id + order by jr_c_opid, c_debit desc"); + for ( $e=0;$e < pg_NumRows($Res);$e++) { + $row=pg_fetch_array($Res,$e); + $sql=sprintf ("update centralized set + c_order = (select nextval('s_central_order')) + where c_id = %d",$row['c_id']); + $Res2=ExecSql($p_cn,$sql); + if ($Res2==false) { rollback($p_cn); EndSql($p_cn); return ERROR;} + + } + + + Commit($p_cn); EndSql($p_cn); diff --git a/include/class_jrn.php b/include/class_jrn.php index 19652797b..85c5157c1 100644 --- a/include/class_jrn.php +++ b/include/class_jrn.php @@ -62,7 +62,7 @@ class jrn { */ function GetRow($p_from,$p_to,$cent='off',$p_limit=-1,$p_offset=-1) { - echo_debug(__FILE__,__LINE__,"GetRow"); + echo_debug(__FILE__,__LINE__,"GetRow ( $p_from,$p_to,$cent,$p_limit,$p_offset)"); if ( $p_from == $p_to ) $periode=" jr_tech_per = $p_from "; @@ -73,14 +73,15 @@ class jrn { // Grand livre == 0 if ( $this->id != 0 ) { - if ( $cent='off' ) { + if ( $cent=='off' ) { + echo_debug(__FILE__,__LINE__,"journaux non centralisé"); // Journaux non centralisés - $Res=ExecSql($this->db,"select j_id,to_char(j_date,'DD.MM.YYYY') as j_date, + $Res=ExecSql($this->db,"select j_id,j_id as int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date, jr_internal, case j_debit when 't' then j_montant::text else ' ' end as deb_montant, case j_debit when 'f' then j_montant::text else ' ' end as cred_montant, j_debit as debit,j_poste as poste,jr_montant , ". - "pcm_lib as description,j_grpt as grp,jr_comment , + "pcm_lib as description,j_grpt as grp,jr_comment||' ('||c_internal||')' as jr_comment , jr_rapt as oc, j_tech_per as periode from jrnx left join jrn on ". "jr_grpt_id=j_grpt ". " left join tmp_pcmn on pcm_val=j_poste ". @@ -89,9 +90,9 @@ class jrn { $cond_limite); }else { // Journaux centralisés - - $Sql="select c_id as j_id, - c_j_id, + echo_debug(__FILE__,__LINE__,"journaux centralisé"); + $Sql="select jr_opid as j_id, + c_order as int_j_id, to_char (c_date,'DD.MM.YYYY') as j_date , c_internal as jr_internal, case c_debit when 't' then c_montant::text else ' ' end as deb_montant, @@ -99,7 +100,7 @@ class jrn { c_debit as j_debit, c_poste as poste, pcm_lib as description, - jr_comment, + jr_comment||' ('||c_internal||')' as jr_comment, jr_montant, c_grp as grp, c_comment as comment, @@ -108,20 +109,22 @@ class jrn { from centralized left join jrn on ". "jr_grpt_id=c_grp left join tmp_pcmn on pcm_val=c_poste where ". " c_jrn_def=".$this->id." and ". - $periode." order by c_id "; + $periode." order by c_order "; $Res=ExecSql($this->db,$Sql.$cond_limite); } } else { // Grand Livre if ( $cent == 'off') { + echo_debug(__FILE__,__LINE__,"Grand livre non centralisé"); // Non centralisé - $Res=ExecSql($this->db,"select j_id,to_char(j_date,'DD.MM.YYYY') as j_date, + $Res=ExecSql($this->db,"select j_id,j_id as int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date, jr_internal, case j_debit when 't' then j_montant::text else ' ' end as deb_montant, case j_debit when 'f' then j_montant::text else ' ' end as cred_montant, j_debit as debit,j_poste as poste,". - "pcm_lib as description,j_grpt as grp,jr_comment as jr_comment, + "pcm_lib as description,j_grpt as grp, + jr_comment||' ('||c_internal||')' as jr_comment, jr_montant, jr_rapt as oc, j_tech_per as periode from jrnx left join jrn on ". "jr_grpt_id=j_grpt left join tmp_pcmn on pcm_val=j_poste where ". @@ -129,8 +132,11 @@ class jrn { $cond_limite); } else { + echo_debug(__FILE__,__LINE__,"Grand livre centralisé"); // Centralisé - $Sql="select c_id as j_id, + $Sql="select jr_c_opid as j_id, + c_order as int_j_id, + c_j_id, to_char (c_date,'DD.MM.YYYY') as j_date , c_internal as jr_internal, @@ -139,15 +145,15 @@ class jrn { c_debit as j_debit, c_poste as poste, pcm_lib as description, - jr_comment, + jr_comment||' ('||c_internal||')' as jr_comment, jr_montant, c_grp as grp, - c_comment as comment, + c_comment||' ('||c_internal||')' as comment, c_rapt as oc, c_periode as periode from centralized left join jrn on ". "jr_grpt_id=c_grp left join tmp_pcmn on pcm_val=c_poste where ". - $periode." order by c_id "; + $periode." order by c_order "; $Res=ExecSql($this->db,$Sql.$cond_limite); } // Grand Livre } @@ -172,6 +178,7 @@ class jrn { if ( $case != $line['grp'] ) { $case=$line['grp']; $array[]=array ( + 'int_j_id' => $line['int_j_id'], 'j_id'=>$line['j_id'], 'j_date' => $line['j_date'], 'internal'=>$line['jr_internal'], @@ -182,7 +189,8 @@ class jrn { 'periode' =>$line['periode'] ); $array[]=array ( - 'j_id'=>$line['j_id'], + 'int_j_id' => $line['int_j_id'], + 'j_id'=>'', 'j_date' => '', 'internal'=>'', 'deb_montant'=>$mont_deb, @@ -194,7 +202,8 @@ class jrn { }else { $array[]=array ( - 'j_id'=>$line['j_id'], + 'int_j_id' => $line['int_j_id'], + 'j_id'=>'', 'j_date' => '', 'internal'=>'', 'deb_montant'=>$mont_deb, diff --git a/include/impress_inc.php b/include/impress_inc.php index 60e8d9999..cb3148d1b 100644 --- a/include/impress_inc.php +++ b/include/impress_inc.php @@ -630,15 +630,16 @@ function GetRappel($p_cn,$p_jrnx_id,$p_jrn_id,$p_exercice,$which,$p_type,$p_cent if ( $p_central == 1 ) { $c_line=CountSql($p_cn,"select * from centralized left join parm_periode on c_periode=p_id ". " where c_jrn_def=$p_jrn_id and p_exercice='".$p_exercice."'". - " and c_id $cmp $p_jrnx_id "); + " and c_order $cmp $p_jrnx_id "); if ($c_line == 0 ) { return array (0,0); } $sql="select sum(c_montant) as tot_amount ". " from centralized ". " left join parm_periode on c_periode=p_id ". + " inner join jrn on jr_grpt_id=c_grp ". " where c_jrn_def=$p_jrn_id and ". " p_exercice='".$p_exercice."'". - " and c_id $cmp $p_jrnx_id " ; + " and c_order $cmp $p_jrnx_id " ; $Res=ExecSql($p_cn,$sql." and c_debit='t' "); if ( pg_NumRows($Res) == 0 ) $deb=0; @@ -673,7 +674,7 @@ function GetRappel($p_cn,$p_jrnx_id,$p_jrn_id,$p_exercice,$which,$p_type,$p_cent " left join parm_periode on c_periode=p_id ". " where ". " p_exercice='".$p_exercice."'". - " and c_id $cmp $p_jrnx_id " ; + " and c_order $cmp $p_jrnx_id " ; $Res=ExecSql($p_cn,$sql." and c_debit='t' "); if ( pg_NumRows($Res) == 0 ) $deb=0; diff --git a/include/impress_jrn.php b/include/impress_jrn.php index 89c63ec32..49f05cf01 100644 --- a/include/impress_jrn.php +++ b/include/impress_jrn.php @@ -28,7 +28,8 @@ if ( isset( $_POST['bt_html'] ) ) { include("class_jrn.php"); $p_cent=( isset ( $_POST['cent']) )?'on':'off'; // $POST=from_periode, to_periode, jrn_id, cent - + $d=var_export($_POST,true); + echo_debug(__FILE__,__LINE__,$d); $Jrn=new jrn($cn,$_POST['jrn_id']); $Jrn->GetName(); $Jrn->GetRow( $_POST['from_periode'], @@ -73,8 +74,12 @@ include("class_jrn.php"); echo ""; foreach ( $Jrn->row as $op ) { - echo "". - "". + echo ""; + // centralized + if ( $p_cent == 'on') { + echo ""; + } + echo "". "". "". "".
".$op['internal']."
".$op['j_id']."".$op['internal']."".$op['j_date']."".$op['poste']."".$op['description']."