diff --git a/include/balance.inc.php b/include/balance.inc.php index 68e81c86c..3a3ec0585 100644 --- a/include/balance.inc.php +++ b/include/balance.inc.php @@ -153,7 +153,7 @@ $from_poste->set_attribute('ipopup','ipop_account'); $from_poste->set_attribute('label','from_poste_label'); $from_poste->set_attribute('account','from_poste'); -$from_poste->value=(isset($_GET['from_poste']))?$_GET['from_poste']:""; +$from_poste->value=HtmlInput::default_value_get('from_poste',''); $from_span=new ISpan("from_poste_label",""); $to_poste=new IPoste(); @@ -162,7 +162,7 @@ $to_poste->set_attribute('ipopup','ipop_account'); $to_poste->set_attribute('label','to_poste_label'); $to_poste->set_attribute('account','to_poste'); -$to_poste->value=(isset($_GET['to_poste']))?$_GET['to_poste']:""; +$to_poste->value=HtmlInput::default_value_get('to_poste',''); $to_span=new ISpan("to_poste_label",""); echo "
"; @@ -179,6 +179,18 @@ echo '

'; echo _("Avec la balance de l'année précédente")." ".$previous_exc->input(); echo '

'; echo '
'; +?> +
+ + value=1; + $is_summary=HtmlInput::default_value_get("summary", 0); + $summary->set_check($is_summary); + echo $summary->input(); + ?> +
+'; echo HtmlInput::submit("view",_("Visualisation")); echo ''; @@ -200,7 +212,7 @@ if ( isset ($_GET['view'] ) ) HtmlInput::submit('bt_pdf',"Export PDF"). HtmlInput::hidden("ac",$_REQUEST['ac']). HtmlInput::hidden("act","PDF:balance"). - + HtmlInput::hidden("summary", $is_summary). HtmlInput::hidden("from_periode",$_GET['from_periode']). HtmlInput::hidden("to_periode",$_GET['to_periode']); echo HtmlInput::hidden('p_filter',$_GET['p_filter']); @@ -324,6 +336,10 @@ if ( isset($_GET['view'] ) ) bcscale(2); $nb_row = count($row); + + // Compute for the summary + $summary_tab=$bal->summary_init(); + $summary_prev_tab=$bal->summary_init(); foreach ($row as $r) { $i++; @@ -384,6 +400,9 @@ if ( isset($_GET['view'] ) ) if ( $r['poste'] == "") { $tr="highlight"; } + + $summary_tab=$bal->summary_add($summary_tab,$r['poste'],$r['sum_deb'],$r['sum_cred']); + echo ''; echo td($view_history); echo td(h($r['label'])); @@ -392,7 +411,16 @@ if ( isset($_GET['view'] ) ) 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 ''; + if ( isset($_GET['lvl1']) || + isset($_GET['lvl2']) || + isset($_GET['lvl3'])) + echo ''; + + $summary_prev_tab=$bal->summary_add($summary_prev_tab, + $r['poste'], + $r['sum_deb_previous'], + $r['sum_cred_previous']); + } echo td(nbm($r['sum_deb']),'style="text-align:right;"'); echo td(nbm($r['sum_cred']),'style="text-align:right;"'); @@ -400,10 +428,26 @@ if ( isset($_GET['view'] ) ) echo td(nbm($r['solde_cred']),'style="text-align:right;"'); if ( isset($_GET['lvl1']) || isset($_GET['lvl2']) || isset($_GET['lvl3'])) echo ''; echo ''; - + } echo ''; - + // display the summary + if ($is_summary==1) { + if ( $previous == 1) { + echo '
'; + echo '

'; + echo _("Résumé Exercice précédent"); + echo '

'; + $bal->summary_display($summary_prev_tab); + echo "
"; + } + echo '
'; + echo '

'; + echo _("Résumé Exercice courant"); + echo '

'; + $bal->summary_display($summary_tab); + echo "
"; + } }// end submit echo ""; ?> diff --git a/include/class/class_acc_balance.php b/include/class/class_acc_balance.php index 733402937..446142fa8 100644 --- a/include/class/class_acc_balance.php +++ b/include/class/class_acc_balance.php @@ -63,7 +63,7 @@ class Acc_Balance global $g_user; // filter on requested periode $per_sql=sql_filter_per($this->db,$p_from_periode,$p_to_periode,'p_id','j_tech_per'); - + bcscale(2); $and=""; $jrn=""; @@ -206,26 +206,29 @@ class Acc_Balance $a['sum_cred']=round($r['sum_cred'],2); $a['solde_deb']=round(( $a['sum_deb'] >= $a['sum_cred'] )? $a['sum_deb']- $a['sum_cred']:0,2); $a['solde_cred']=round(( $a['sum_deb'] <= $a['sum_cred'] )?$a['sum_cred']-$a['sum_deb']:0,2); + + + if ($p_previous_exc==1) { $a['sum_deb_previous']=round($r['sum_deb_previous'],2); $a['sum_cred_previous']=round($r['sum_cred_previous'],2); $a['solde_deb_previous']=round(( $a['sum_deb_previous'] >= $a['sum_cred_previous'] )? $a['sum_deb_previous']- $a['sum_cred_previous']:0,2); $a['solde_cred_previous']=round(( $a['sum_deb_previous'] <= $a['sum_cred_previous'] )?$a['sum_cred_previous']-$a['sum_deb_previous']:0,2); - $tot_cred_previous+= $a['sum_cred_previous']; - $tot_deb_previous+= $a['sum_deb_previous']; - $tot_deb_saldo_previous+= $a['solde_deb_previous']; - $tot_cred_saldo_previous+= $a['solde_cred_previous']; + $tot_cred_previous = bcadd ($tot_cred_previous, $a['sum_cred_previous']); + $tot_deb_previous = bcadd( $tot_deb_previous,$a['sum_deb_previous']); + $tot_deb_saldo_previous = bcadd ($tot_deb_saldo_previous ,$a['solde_deb_previous']); + $tot_cred_saldo_previous = bcadd ($tot_cred_saldo_previous,$a['solde_cred_previous']); } if ($p_previous_exc==0 && $this->unsold==true && $a['solde_cred']==0 && $a['solde_deb']==0) continue; if ($p_previous_exc==1 && $this->unsold==true && $a['solde_cred']==0 && $a['solde_deb']==0 && $a['solde_cred_previous']==0 && $a['solde_deb_previous']==0) continue; $array[$i]=$a; - $tot_cred+= $a['sum_cred']; - $tot_deb+= $a['sum_deb']; - $tot_deb_saldo+= $a['solde_deb']; - $tot_cred_saldo+= $a['solde_cred']; - - + $tot_cred= bcadd ($tot_cred,$a['sum_cred']); + $tot_deb= bcadd($tot_deb, $a['sum_deb']); + $tot_deb_saldo= bcadd($tot_deb_saldo, $a['solde_deb']); + $tot_cred_saldo= bcadd($tot_cred_saldo,$a['solde_cred']); + + }//for i // Add the saldo $i+=1; @@ -275,6 +278,132 @@ class Acc_Balance } } + /** + * @brief create an empty array for computing the summary + */ + function summary_init() + { + $array=[]; + $array["1_5"]=["deb"=>0,"cred"=>0]; + $array["6"]=["deb"=>0,"cred"=>0]; + $array["7"]=["deb"=>0,"cred"=>0]; + return $array; + } + /** + * Add the current amount (d /c) to the right item in the array, in order + * to compute a summary (1 to 5 , 6 charge and 7 profit ), + * the return value is an array + * @see Acc_Balance::summary_init() + * @param array $p_array array with the result + * @param string $p_accounting accounting + * @param numeric $p_deb + * @param numeric $p_cred + * @return array + */ + function summary_add($p_array,$p_accounting,$p_deb,$p_cred) + { + if (trim($p_accounting)=="") return $p_array; + // Summary + $first_digit=trim($p_accounting); + $first_digit_trim=$first_digit[0]; + if ( $first_digit_trim >0 && $first_digit_trim < 6) { + $p_array["1_5"]["deb"]=bcadd( $p_array["1_5"]["deb"],$p_deb); + $p_array["1_5"]["cred"]=bcadd( $p_array["1_5"]["cred"],$p_cred); + } + elseif ($first_digit_trim == "6") { + $p_array["6"]["deb"]=bcadd( $p_array["6"]["deb"],$p_deb); + $p_array["6"]["cred"]=bcadd( $p_array["6"]["cred"],$p_cred); + } + elseif ($first_digit_trim=="7") { + $p_array["7"]["deb"]=bcadd( $p_array["7"]["deb"],$p_deb); + $p_array["7"]["cred"]=bcadd( $p_array["7"]["cred"],$p_cred); + + } + return $p_array; + } + /** + * Display the summary of result in HTML + * @see Acc_Balance::summary_init() + * @param array $p_array + */ + function summary_display($p_array) + { + echo ""; + echo ""; + echo td(_("Class 1-5")); + $diff=bcsub($p_array["1_5"]["deb"],$p_array["1_5"]["cred"]); + echo td(nbm(abs($diff),2)); + $side=($diff < 0)?"C":"D"; + $side=($diff == 0)?"=":$side; + echo td($side); + echo ""; + echo ""; + echo td(_("Class 6")); + $diff6=bcsub($p_array["6"]["deb"],$p_array["6"]["cred"]); + echo td(nbm(abs($diff6),2),' class="num"'); + $side=($diff6 < 0)?"C":"D"; + $side=($diff6 == 0)?"=":$side; + echo td($side); + echo ""; + echo ""; + echo td(_("Class 7")); + $diff7=bcsub($p_array["7"]["deb"],$p_array["7"]["cred"]); + echo td(nbm(abs($diff7),2),' class="num"'); + $side=($diff7 < 0)?"C":"D"; + $side=($diff7 == 0)?"=":$side; + echo td($side); + echo ""; + echo ""; + echo td(_("Solde 6/7")); + $diff=bcadd($diff6,$diff7); + echo td(nbm(abs($diff),2),' class="num"'); + $side=($diff < 0)?"C":"D"; + $side=($diff == 0)?"=":$side; + echo td($side); + echo ""; + echo "
"; + } + /** + * Display the summary of result in PDF + * @param array $p_array + * @param PDF $p_pdf + * @see Acc_Balance::summary_init() + */ + function summary_display_pdf($p_array,$p_pdf) + { + $p_pdf->write_cell(30,6,_("Class 1-5")); + $diff=bcsub($p_array["1_5"]["deb"],$p_array["1_5"]["cred"]); + $p_pdf->write_cell(50,6, + nbm(abs($diff),2),0,0,'R'); + $side=($diff < 0)?"C":"D"; + $side=($diff == 0)?"=":$side; + $p_pdf->write_cell(10,6,$side); + $p_pdf->line_new(); + + $p_pdf->write_cell(30,6,_("Class 6")); + $diff6=bcsub($p_array["6"]["deb"],$p_array["6"]["cred"]); + $p_pdf->write_cell(50,6,nbm(abs($diff6),2),0,0,'R'); + $side=($diff6 < 0)?"C":"D"; + $side=($diff6 == 0)?"=":$side; + $p_pdf->write_cell(10,6,$side); + $p_pdf->line_new(); + + $p_pdf->write_cell(30,6,_("Class 7")); + $diff7=bcsub($p_array["7"]["deb"],$p_array["7"]["cred"]); + $p_pdf->write_cell(50,6,nbm(abs($diff7),2),0,0,'R'); + $side=($diff7 < 0)?"C":"D"; + $side=($diff7 == 0)?"=":$side; + $p_pdf->write_cell(10,6,$side); + $p_pdf->line_new(); + + $p_pdf->write_cell(30,6,_("Solde 6/7")); + $diff=bcadd($diff6,$diff7); + $p_pdf->write_cell(50,6,nbm(abs($diff),2),0,0,'R'); + $side=($diff < 0)?"C":"D"; + $side=($diff == 0)?"=":$side; + $p_pdf->write_cell(10,6,$side); + $p_pdf->line_new(); + } static function test_me () { require 'class/class_user.php'; diff --git a/include/export/export_balance_pdf.php b/include/export/export_balance_pdf.php index e54d00e6b..8fe6fea34 100644 --- a/include/export/export_balance_pdf.php +++ b/include/export/export_balance_pdf.php @@ -45,6 +45,11 @@ $g_user->Check(); $bal=new Acc_Balance($cn); +// Compute for the summary +$summary_tab=$bal->summary_init(); +$summary_prev_tab=$bal->summary_init(); +$is_summary=HtmlInput::default_value_get("summary", 0); + extract ($_GET, EXTR_SKIP); $bal->jrn=null; switch( $_GET['p_filter']) @@ -208,6 +213,9 @@ if (! empty($array)) $pdf->LongLine(30,6,$value['poste'],0,'L',$fill); $pdf->LongLine(60,6,$value['label'],0,'L',$fill); + $summary_tab=$bal->summary_add($summary_tab,$value['poste'], + $value['sum_deb'], + $value['sum_cred']); 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); @@ -217,6 +225,10 @@ if (! empty($array)) $tp_cred_previous=bcadd($tp_cred_previous,$value['sum_cred_previous']); $tp_sold_previous=bcadd($tp_sold_previous,$value['solde_deb_previous']); $tp_solc_previous=bcadd($tp_solc_previous,$value['solde_cred_previous']); + $summary_prev_tab=$bal->summary_add($summary_prev_tab, + $value['poste'], + $value['sum_deb_previous'], + $value['sum_cred_previous']); } $pdf->write_cell(25,6,nbm($value['sum_deb']),0,0,'R',$fill); $pdf->write_cell(25,6,nbm($value['sum_cred']),0,0,'R',$fill); @@ -275,6 +287,22 @@ if (! empty($array)) $pdf->write_cell(25,6,nbm($tp_solc),'T',0,'R',0); $pdf->line_new(); } /** empty */ + // display the summary + if ($is_summary==1) { + if ($previous==1) { + $pdf->SetFont('DejaVuCond', 'B', 8); + $pdf->write_cell(50, 8, _("Résumé Exercice précédent")); + $pdf->line_new(); + $pdf->SetFont('DejaVuCond', '', 7); + $bal->summary_display_pdf($summary_prev_tab, $pdf); + $pdf->line_new(); + } + $pdf->SetFont('DejaVuCond', 'B', 8); + $pdf->write_cell(50, 8, _("Résumé Exercice courant")); + $pdf->line_new(); + $pdf->SetFont('DejaVuCond', '', 7); + $bal->summary_display_pdf($summary_tab, $pdf); +} $fDate=date('dmy-Hi'); $pdf->Output('balance-'.$fDate.'.pdf','D');