diff --git a/include/balance.inc.php b/include/balance.inc.php index 7661e052f..859be100e 100644 --- a/include/balance.inc.php +++ b/include/balance.inc.php @@ -297,7 +297,7 @@ if ( isset($_GET['view'] ) ) $previous=(isset($_GET['previous_exc']))?1:0; $from_periode=$http->get("from_periode","number"); $to_periode=$http->get("to_periode","number"); - $row=$bal->get_row($from_periode,$to_periode); + $row=$bal->get_row($from_periode,$to_periode,$previous); $previous= (isset ($row[0]['sum_cred_previous']))?1:0; $periode=new Periode($cn); @@ -314,21 +314,17 @@ if ( isset($_GET['view'] ) ) if ( $previous == 1 ){ echo ''._("Débit N-1").''; echo ''._('Crédit N-1').''; - echo ''._('Solde Débiteur N-1').''; - echo ''._('Solde Créditeur N-1').''; - if ( isset($_GET['lvl1']) || isset($_GET['lvl2']) || isset($_GET['lvl3'])) - echo 'Solde N-1'; + echo ''._('Solde N-1').''; } echo ''._('Ouverture').''; echo ''._('Débit').''; echo ''._('Crédit').''; echo ''._('Solde').''; -// if ( isset($_GET['lvl1']) || isset($_GET['lvl2']) || isset($_GET['lvl3'])) -// echo 'Solde'; + $i=0; if ( $previous == 1) { - $a_sum=array('sum_cred','sum_deb','solde_deb','solde_cred','sum_cred_previous','sum_deb_previous','solde_deb_previous','solde_cred_previous'); + $a_sum=array('sum_cred','sum_deb','solde_deb','solde_cred','sum_deb_ope','sum_cred_ope','sum_cred_previous','sum_deb_previous','solde_previous'); } else { $a_sum=array('sum_cred','sum_deb','solde_deb','solde_cred','sum_deb_ope','sum_cred_ope') ; @@ -357,7 +353,9 @@ if ( isset($_GET['view'] ) ) else $tr="odd"; $view_history=HtmlInput::history_account($r['poste'], $r['poste'], "",$exercice); - + if ($previous == 1 ) { + $r['solde_previous']=bcsub($r['solde_deb_previous'],$r['solde_cred_previous']); + } /* * level x */ @@ -371,23 +369,22 @@ if ( isset($_GET['view'] ) ) echo ''; echo td(${'lvl'.$ind.'_old'},'style="font-weight:bold;"'); echo td(${'lvl'.$ind.'_old'}." "._("Total niveau")." ".$ind,'style="font-weight:bold;"'); + + // compare with previous exercice if ($previous==1) { echo td(nbm(${'lvl'.$ind}['sum_deb_previous']),'class="previous_year" style="font-weight:bold;"'); echo td(nbm(${'lvl'.$ind}['sum_cred_previous']),' class="previous_year" style="font-weight:bold;" '); - echo td(nbm(${'lvl'.$ind}['solde_deb_previous']),'class="previous_year" style="font-weight:bold;"'); - echo td(nbm(${'lvl'.$ind}['solde_cred_previous']),'class="previous_year" style="font-weight:bold;"'); - $delta_previous=bcsub(${'lvl'.$ind}['solde_cred_previous'],${'lvl'.$ind}['solde_deb_previous']); - $side_previous=($delta_previous > 0 ) ? "C":"D"; + $delta_previous=${'lvl'.$ind}['solde_previous']; + $side_previous=($delta_previous > 0 ) ? "D":"C"; echo td(nbm(abs($delta_previous))." $side_previous",'class="previous_year" style="text-align:right;font-weight:bold;" '); } - /*echo td(nbm(${'lvl'.$ind}['sum_deb']),'style="text-align:right;font-weight:bold;" '); - echo td(nbm(${'lvl'.$ind}['sum_cred']),'style="text-align:right;font-weight:bold;"');*/ + // Ouverture $solde3=bcsub(${'lvl'.$ind}['sum_deb_ope'],${'lvl'.$ind}['sum_cred_ope']); $side3=($solde3<0)?" C":" D"; $side3=($solde3==0)?" ":$side3; - echo td(nbm(abs($solde3)).$side3); + echo td(nbm(abs($solde3)).$side3,'style="text-align:right;font-weight:bold;"'); // Saldo debit $solde_deb=bcsub(${'lvl'.$ind}['sum_deb'],${'lvl'.$ind}['sum_deb_ope']); @@ -409,12 +406,12 @@ if ( isset($_GET['view'] ) ) } } - foreach($a_sum as $a) - { - $lvl1[$a]=bcadd($lvl1[$a],$r[$a]); - $lvl2[$a]=bcadd($lvl2[$a],$r[$a]); - $lvl3[$a]=bcadd($lvl3[$a],$r[$a]); - } + foreach($a_sum as $a) + { + $lvl1[$a]=bcadd($lvl1[$a],$r[$a]); + $lvl2[$a]=bcadd($lvl2[$a],$r[$a]); + $lvl3[$a]=bcadd($lvl3[$a],$r[$a]); + } // For the Total row , there is no accounting if ( $r['poste'] == "") { $tr="highlight"; @@ -429,12 +426,11 @@ if ( isset($_GET['view'] ) ) if ($previous == 1 ) { echo td(nbm($r['sum_deb_previous']),' class="previous_year"'); echo td(nbm($r['sum_cred_previous']),' class="previous_year" '); - echo td(nbm($r['solde_deb_previous']),' class="previous_year"'); - echo td(nbm($r['solde_cred_previous']),'class="previous_year" '); - if ( isset($_GET['lvl1']) || - isset($_GET['lvl2']) || - isset($_GET['lvl3'])) - echo ''; + $solde_previous=bcsub($r['solde_deb_previous'],$r['solde_cred_previous']); + $side=($solde_previous<0)?"D":"C"; + $side=($solde_previous==0)?"":$side; + $r['solde_previous']=$solde_previous; + echo td(nbm(abs($solde_previous))." ".$side,' class="previous_year"'); $summary_prev_tab=$bal->summary_add($summary_prev_tab, $r['poste'], diff --git a/include/class/acc_balance.class.php b/include/class/acc_balance.class.php index 0c65a2360..d0c956f9f 100644 --- a/include/class/acc_balance.class.php +++ b/include/class/acc_balance.class.php @@ -138,12 +138,17 @@ class Acc_Balance $per_sql_previous=sql_filter_per($this->db,$previous_start->p_id,$previous_end->p_id,'p_id','j_tech_per'); $sql=" with m as - ( select j_poste,sum(deb) as sdeb,sum(cred) as scred + ( select j_poste,sum(deb) as sdeb,sum(cred) as scred, + sum(deb_op) as sum_deb_ope , + sum(cred_op) as sum_cred_ope from (select j_poste, case when j_debit='t' then j_montant else 0 end as deb, - case when j_debit='f' then j_montant else 0 end as cred + case when j_debit='f' then j_montant else 0 end as cred , + case when j_debit='t' and jr_optype='OPE' then j_montant else 0 end as deb_op, + case when j_debit='f' and jr_optype='OPE' then j_montant else 0 end as cred_op from jrnx + join jrn on (j_grpt=jr_grpt_id) join tmp_pcmn on (j_poste=pcm_val) left join parm_periode on (j_tech_per = p_id) join jrn_def on (j_jrn_def=jrn_def_id) @@ -152,15 +157,11 @@ class Acc_Balance $and $filter_sql and $per_sql ) as sub_m group by j_poste order by j_poste ) , p as ( select j_poste,sum(deb) as sdeb, - sum(cred) as scred , - sum(deb_op) as sum_deb_ope , - sum(cred_op) as sum_cred_ope + sum(cred) as scred from (select j_poste, case when j_debit='t' then j_montant else 0 end as deb, - case when j_debit='f' then j_montant else 0 end as cred , - case when j_debit='t' and jr_optype='OPE' then j_montant else 0 end as deb_op, - case when j_debit='f' and jr_optype='OPE' then j_montant else 0 end as cred_op + case when j_debit='f' then j_montant else 0 end as cred from jrnx join tmp_pcmn on (j_poste=pcm_val) left join parm_periode on (j_tech_per = p_id) join jrn_def on (j_jrn_def=jrn_def_id) diff --git a/include/export/export_balance_pdf.php b/include/export/export_balance_pdf.php index 4879bca99..bc0d4eac7 100644 --- a/include/export/export_balance_pdf.php +++ b/include/export/export_balance_pdf.php @@ -110,11 +110,15 @@ $pPeriode=new Periode($cn); $a=$pPeriode->get_date_limit($from_periode); $b=$pPeriode->get_date_limit($to_periode); $per_text=" du ".$a['p_start']." au ".$b['p_end']; + +// If compare with previous exercice , +// we use the landscape mode if ($previous == 1 ) { $pdf=new PDFLand($cn); } else { $pdf= new PDF($cn); } + $pdf->setDossierInfo(" Balance ".$per_text); $pdf->AliasNbPages(); $pdf->AddPage(); @@ -129,9 +133,9 @@ if ($previous == 1 ){ $pdf->write_cell(20,6,'Solde N-1',0,0,'R'); } $pdf->write_cell(25,6,_('Ouverture'),0,0,'R'); -$pdf->write_cell(25,6,'Total Débit',0,0,'R'); -$pdf->write_cell(25,6,'Total Crédit',0,0,'R'); -$pdf->write_cell(25,6,'Solde Débiteur',0,0,'R'); +$pdf->write_cell(25,6,_('Total Débit'),0,0,'R'); +$pdf->write_cell(25,6,_('Total Crédit'),0,0,'R'); +$pdf->write_cell(25,6,_('Solde Débiteur'),0,0,'R'); $pdf->line_new(); $pdf->SetFont('DejaVuCond','',8); @@ -185,20 +189,19 @@ if (! empty($array)) if ($previous == 1 ) { $delta_previous=bcsub(${'nlvl'.$ind}['solde_cred_previous'],${'nlvl'.$ind}['solde_deb_previous']); $side_previous=($delta_previous < 0) ? "D":"C"; - $pdf->write_cell(30,6,"n-1 : " .nbm($delta_previous)." $side_previous",0,0,'R'); - $pdf->write_cell(30,6," n : ".nbm($delta)." $side",0,0,'R'); + $pdf->write_cell(60,6," ",0,0,'R'); $pdf->write_cell(22,6,nbm(${'nlvl'.$ind}['sum_deb_previous']),0,0,'R'); $pdf->write_cell(22,6,nbm(${'nlvl'.$ind}['sum_cred_previous']),0,0,'R'); - $pdf->write_cell(22,6,nbm(${'nlvl'.$ind}['solde_deb_previous']),0,0,'R'); - $pdf->write_cell(22,6,nbm(${'nlvl'.$ind}['solde_cred_previous']),0,0,'R'); + $pdf->write_cell(22,6,nbm(abs($delta_previous))." $side_previous",0,0,'R'); + } else { $pdf->write_cell(60,6," ",0,0,'R'); - $solde_lv=bcsub(${'nlvl'.$ind}['sum_deb_ope'],${'nlvl'.$ind}['sum_cred_ope']); - $side_lv=($solde_lv<0)?" D":" C"; - $side_lv=($solde_lv==0)?" ":$side_lv; - $pdf->write_cell(25,6,nbm(abs($solde_lv)).$side_lv,0,0,'R'); } + $solde_lv=bcsub(${'nlvl'.$ind}['sum_deb_ope'],${'nlvl'.$ind}['sum_cred_ope']); + $side_lv=($solde_lv<0)?" C":" D"; + $side_lv=($solde_lv==0)?" ":$side_lv; + $pdf->write_cell(25,6,nbm(abs($solde_lv)).$side_lv,0,0,'R'); $pdf->write_cell(25,6,nbm(bcsub(${'nlvl'.$ind}['sum_deb'],${'nlvl'.$ind}['sum_deb_ope'])),0,0,'R'); $pdf->write_cell(25,6,nbm(bcsub(${'nlvl'.$ind}['sum_cred'],${'nlvl'.$ind}['sum_cred_ope'])),0,0,'R'); $solde_lv=bcsub(${'nlvl'.$ind}['solde_deb'],${'nlvl'.$ind}['solde_cred']); @@ -240,8 +243,15 @@ if (! empty($array)) if ($previous == 1 ) { $pdf->write_cell(22,6,nbm($value['sum_deb_previous']),0,0,'R',$fill); $pdf->write_cell(22,6,nbm($value['sum_cred_previous']),0,0,'R',$fill); - $pdf->write_cell(22,6,nbm($value['solde_deb_previous']),0,0,'R',$fill); - $pdf->write_cell(22,6,nbm($value['solde_cred_previous']),0,0,'R',$fill); + +// $pdf->write_cell(22,6,nbm($value['solde_deb_previous']),0,0,'R',$fill); +// $pdf->write_cell(22,6,nbm($value['solde_cred_previous']),0,0,'R',$fill); + $solde_previous=bcsub($value['solde_cred_previous'],$value['solde_deb_previous']); + $side_previous=($solde_previous<0)?" D":" C"; + $side_previous=($solde_previous==0)?"":$side_previous; + + $pdf->write_cell(22,6,nbm(abs($solde_previous)).$side_previous,0,0,'R',$fill); + $tp_deb_previous=bcadd($tp_deb_previous,$value['sum_deb_previous']); $tp_cred_previous=bcadd($tp_cred_previous,$value['sum_cred_previous']); $tp_sold_previous=bcadd($tp_sold_previous,$value['solde_deb_previous']);