diff --git a/html/document/fr_be/bnb.form b/html/document/fr_be/bnb.form
index 8bf132c2c..0c30bd0b1 100644
--- a/html/document/fr_be/bnb.form
+++ b/html/document/fr_be/bnb.form
@@ -146,13 +146,14 @@ $C794=round([794%S],2)*(-1)
#
$S1=abs($C2-$C29)
$S2=$C22+$C23+$C24+$C25+$C26+$C27
-$S3=$C29+$C50+$C51+$C52+$C53+$C54+$C55+$C56+$C57+$C58+$C490+$C491+$C41+$C40
$S4=$C30+$C31+$C32+$C33+$C34+$C35+$C36
+$S3=$C29+$C50+$C51+$C52+$C53+$C54+$C55+$C56+$C57+$C58+$C490+$C491+$C41+$C40+$S4
+
$S5=$C40+$C41
$S6=$C50+$C51+$C52+$C53
$S7=$C54+$C55+$C56+$C57+$C58
$S8=$C490+$C491
-$S9=$S1+$S3+$C3
+$S9=$S1+$S3
$S10=$C10+$C11+$C12+$C13+$C14+$C15
$S11=$C160+$C161+$C162+$C163+$C164+$C165
$S12=$C17+$C42+$C43+$C44+$C45+$C46+$C47+$C48+$C492+$C493
diff --git a/include/export_balance_pdf.php b/include/export_balance_pdf.php
index 246275b04..d2ee64bd9 100644
--- a/include/export_balance_pdf.php
+++ b/include/export_balance_pdf.php
@@ -117,78 +117,105 @@ $lvl2_old='';
$lvl3_old='';
bcscale(2);
+if (! empty($array))
+ {
+ $i=0;
+ foreach ($array as $key=>$value)
+ {
+ $i++;
+ /*
+ * level x
+ */
+ if ( $value['poste']=='') continue;
+ foreach (array(3,2,1) as $ind)
+ {
+ $r=$value;
+ if ( ! isset($_GET['lvl'.$ind]))continue;
+
+ if (${'lvl'.$ind.'_old'} == '') ${'lvl'.$ind.'_old'}=substr($r['poste'],0,$ind);
+ if ( ${'lvl'.$ind.'_old'} != substr($r['poste'],0,$ind))
+ {
+ $pdf->SetFont('DejaVu','B',7);
+ $pdf->Cell(30,6,"Totaux ".$ind);
+ $pdf->Cell(80,6,${'lvl'.$ind.'_old'});
+ $pdf->Cell(20,6,nbm(${'nlvl'.$ind}['sum_deb']),0,0,'R');
+ $pdf->Cell(20,6,nbm(${'nlvl'.$ind}['sum_cred']),0,0,'R');
+ $pdf->Cell(20,6,nbm(${'nlvl'.$ind}['solde_deb']),0,0,'R');
+ $pdf->Cell(20,6,nbm(${'nlvl'.$ind}['solde_cred']),0,0,'R');
+ $pdf->Ln();
+ $pdf->SetFont('DejaVuCond','',7);
+ ${'lvl'.$ind.'_old'}=substr($r['poste'],0,$ind);
+ foreach(array('sum_cred','sum_deb','solde_deb','solde_cred') as $a)
+ {
+ ${'nlvl'.$ind}[$a]=0;
+ }
+ }
+ }
+ foreach(array('sum_cred','sum_deb','solde_deb','solde_cred') as $a)
+ {
+ $nlvl1[$a]=bcadd($nlvl1[$a],$r[$a]);
+ $nlvl2[$a]=bcadd($nlvl2[$a],$r[$a]);
+ $nlvl3[$a]=bcadd($nlvl3[$a],$r[$a]);
+ }
+
+ if ( $i % 2 == 0 )
+ {
+ $pdf->SetFillColor(220,221,255);
+ $fill=1;
+ }
+ else
+ {
+ $pdf->SetFillColor(0,0,0);
+ $fill=0;
+ }
+
+ $pdf->Cell(30,6,$value['poste'],0,0,'L',$fill);
+ $pdf->Cell(80,6,$value['label'],0,0,'L',$fill);
+ $pdf->Cell(20,6,nbm($value['sum_deb']),0,0,'R',$fill);
+ $pdf->Cell(20,6,nbm($value['sum_cred']),0,0,'R',$fill);
+ $pdf->Cell(20,6,nbm($value['solde_deb']),0,0,'R',$fill);
+ $pdf->Cell(20,6,nbm($value['solde_cred']),0,0,'R',$fill);
+ $pdf->Ln();
+ $tp_deb=bcadd($tp_deb,$value['sum_deb']);
+ $tp_cred=bcadd($tp_cred,$value['sum_cred']);
+ $tp_sold=bcadd($tp_sold,$value['solde_deb']);
+ $tp_solc=bcadd($tp_solc,$value['solde_cred']);
-for ($i=0;$iSetFont('DejaVu','B',7);
- $pdf->Cell(30,6,"Totaux ".$ind);
- $pdf->Cell(80,6,${'lvl'.$ind.'_old'});
- $pdf->Cell(20,6,nbm(${'nlvl'.$ind}['sum_deb']),0,0,'R');
- $pdf->Cell(20,6,nbm(${'nlvl'.$ind}['sum_cred']),0,0,'R');
- $pdf->Cell(20,6,nbm(${'nlvl'.$ind}['solde_deb']),0,0,'R');
- $pdf->Cell(20,6,nbm(${'nlvl'.$ind}['solde_cred']),0,0,'R');
- $pdf->Ln();
- $pdf->SetFont('DejaVuCond','',7);
- ${'lvl'.$ind.'_old'}=substr($r['poste'],0,$ind);
- foreach(array('sum_cred','sum_deb','solde_deb','solde_cred') as $a)
- {
- ${'nlvl'.$ind}[$a]=0;
- }
- }
- }
- foreach(array('sum_cred','sum_deb','solde_deb','solde_cred') as $a)
- {
- $nlvl1[$a]=bcadd($nlvl1[$a],$r[$a]);
- $nlvl2[$a]=bcadd($nlvl2[$a],$r[$a]);
- $nlvl3[$a]=bcadd($nlvl3[$a],$r[$a]);
- }
-
- if ( $i % 2 == 0 )
- {
- $pdf->SetFillColor(220,221,255);
- $fill=1;
- }
- else
- {
- $pdf->SetFillColor(0,0,0);
- $fill=0;
- }
-
- $pdf->Cell(30,6,$array[$i]['poste'],0,0,'L',$fill);
- $pdf->Cell(80,6,$array[$i]['label'],0,0,'L',$fill);
- $pdf->Cell(20,6,nbm($array[$i]['sum_deb']),0,0,'R',$fill);
- $pdf->Cell(20,6,nbm($array[$i]['sum_cred']),0,0,'R',$fill);
- $pdf->Cell(20,6,nbm($array[$i]['solde_deb']),0,0,'R',$fill);
- $pdf->Cell(20,6,nbm($array[$i]['solde_cred']),0,0,'R',$fill);
+ }
+ foreach (array(3,2,1) as $ind)
+ {
+ $r=$value;
+ if ( ! isset($_GET['lvl'.$ind]))continue;
+
+ if (${'lvl'.$ind.'_old'} == '') ${'lvl'.$ind.'_old'}=substr($r['poste'],0,$ind);
+ if ( ${'lvl'.$ind.'_old'} != substr($r['poste'],0,$ind))
+ {
+ $pdf->SetFont('DejaVu','B',7);
+ $pdf->Cell(30,6,"Totaux ".$ind);
+ $pdf->Cell(80,6,${'lvl'.$ind.'_old'});
+ $pdf->Cell(20,6,nbm(${'nlvl'.$ind}['sum_deb']),0,0,'R');
+ $pdf->Cell(20,6,nbm(${'nlvl'.$ind}['sum_cred']),0,0,'R');
+ $pdf->Cell(20,6,nbm(${'nlvl'.$ind}['solde_deb']),0,0,'R');
+ $pdf->Cell(20,6,nbm(${'nlvl'.$ind}['solde_cred']),0,0,'R');
+ $pdf->Ln();
+ $pdf->SetFont('DejaVuCond','',7);
+ ${'lvl'.$ind.'_old'}=substr($r['poste'],0,$ind);
+ foreach(array('sum_cred','sum_deb','solde_deb','solde_cred') as $a)
+ {
+ ${'nlvl'.$ind}[$a]=0;
+ }
+ }
+ }
+
+ // Totaux
+ $pdf->SetFont('DejaVuCond','B',8);
+ $pdf->Cell(110,6,'Totaux');
+ $pdf->Cell(20,6,nbm($tp_deb),'T',0,'R',0);
+ $pdf->Cell(20,6,nbm($tp_cred),'T',0,'R',0);
+ $pdf->Cell(20,6,nbm($tp_sold),'T',0,'R',0);
+ $pdf->Cell(20,6,nbm($tp_solc),'T',0,'R',0);
$pdf->Ln();
- $tp_deb=bcadd($tp_deb,$array[$i]['sum_deb']);
- $tp_cred=bcadd($tp_cred,$array[$i]['sum_cred']);
- $tp_sold=bcadd($tp_sold,$array[$i]['solde_deb']);
- $tp_solc=bcadd($tp_solc,$array[$i]['solde_cred']);
-
-}
-// Totaux
-$pdf->SetFont('DejaVuCond','B',8);
-$pdf->Cell(110,6,'Totaux');
-$pdf->Cell(20,6,nbm($tp_deb),'T',0,'R',0);
-$pdf->Cell(20,6,nbm($tp_cred),'T',0,'R',0);
-$pdf->Cell(20,6,nbm($tp_sold),'T',0,'R',0);
-$pdf->Cell(20,6,nbm($tp_solc),'T',0,'R',0);
-$pdf->Ln();
-
+ } // if ! empty
$fDate=date('dmy-Hi');
$pdf->Output('balance-'.$fDate.'.pdf','I');