balance.inc.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of PHPCOMPTA.
00004  *
00005  *   PhpCompta is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   PhpCompta is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with PHPCOMPTA; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 // Auteur Dany De Bontridder ddebontridder@yahoo.fr
00020 // /* $Revision: 4949 $ */
00021 /*! \file
00022  * \brief Show the balance and let you print it or export to PDF
00023  *        file included by user_impress
00024  *
00025  * some variable are already defined ($cn, $g_user ...)
00026  */
00027 
00028 include_once ("ac_common.php");
00029 include_once("class_acc_balance.php");
00030 require_once("class_iselect.php");
00031 require_once("class_ispan.php");
00032 require_once("class_icheckbox.php");
00033 require_once("class_ihidden.php");
00034 require_once('class_acc_ledger.php');
00035 require_once('class_periode.php');
00036 require_once('class_exercice.php');
00037 global $g_user;
00038 $gDossier=dossier::id();
00039 $exercice=(isset($_GET['exercice']))?$_GET['exercice']:$g_user->get_exercice();
00040 
00041 
00042 echo '<div class="content">';
00043 /*
00044  * Let you change the exercice
00045  */
00046 echo '<fieldset><legend>'._('Choississez un autre exercice').'</legend>';;
00047 echo '<form method="GET">';
00048 echo 'Choississez un autre exercice :';
00049 $ex=new Exercice($cn);
00050 $wex=$ex->select('exercice',$exercice,' onchange="submit(this)"');
00051 echo $wex->input();
00052 echo dossier::hidden();
00053 echo HtmlInput::get_to_hidden(array('ac','type'));
00054 echo '</form>';
00055 echo '</fieldset>';
00056 
00057 
00058 // Show the form for period
00059 echo '<FORM  method="get">';
00060 echo HtmlInput::get_to_hidden(array('ac'));
00061 echo HtmlInput::hidden('type','bal');
00062 echo HtmlInput::get_to_hidden(array('exercice'));
00063 echo dossier::hidden();
00064 
00065 
00066 
00067 // filter on the current year
00068 $from=(isset($_GET["from_periode"]))?$_GET['from_periode']:"";
00069 $input_from=new IPeriod("from_periode",$from,$exercice);
00070 $input_from->show_end_date=false;
00071 $input_from->type=ALL;
00072 $input_from->cn=$cn;
00073 $input_from->filter_year=true;
00074 $input_from->user=$g_user;
00075 
00076 echo 'Depuis :'.$input_from->input();
00077 // filter on the current year
00078 $to=(isset($_GET["to_periode"]))?$_GET['to_periode']:"";
00079 $input_to=new IPeriod("to_periode",$to,$exercice);
00080 $input_to->show_start_date=false;
00081 $input_to->filter_year=true;
00082 $input_to->type=ALL;
00083 $input_to->cn=$cn;
00084 $input_to->user=$g_user;
00085 echo ' jusque :'.$input_to->input();
00086 
00087 //-------------------------------------------------
00088 
00089 
00090 /*  add a all ledger choice */
00091 echo 'Filtre ';
00092 $rad=new IRadio();
00093 $array_ledger=$g_user->get_ledger('ALL',3);
00094 $selected=(isset($_GET['r_jrn']))?$_GET['r_jrn']:null;
00095 $select_cat=(isset($_GET['r_cat']))?$_GET['r_cat']:null;
00096 $array_cat=Acc_Ledger::array_cat();
00097 
00098 echo '<ul style="list-style-type:none">';
00099 if ( ! isset($_GET['p_filter']) || $_GET['p_filter']==0) $rad->selected='t';
00100 else $rad->selected=false;
00101 echo '<li>'.$rad->input('p_filter',0).'Aucun filtre, tous les journaux'.'</li>';
00102 if (  isset($_GET['p_filter']) && $_GET['p_filter']==1) $rad->selected='t';
00103 else $rad->selected=false;
00104 echo '<li>'.$rad->input('p_filter',1).'Filtré par journal'.HtmlInput::select_ledger($array_ledger,$selected).'</li>';
00105 if (  isset($_GET['p_filter']) && $_GET['p_filter']==2) $rad->selected='t';
00106 else $rad->selected=false;
00107 echo '<li>'.$rad->input('p_filter',2).'Filtré par catégorie'.HtmlInput::select_cat($array_cat).'</li>';
00108 echo '</ul>';
00109 echo 'Totaux par sous-niveaux';
00110 $ck_lev1=new ICheckBox('lvl1');
00111 $ck_lev2=new ICheckBox('lvl2');
00112 $ck_lev3=new ICheckBox('lvl3');
00113 $ck_lev1->value=1;
00114 $ck_lev2->value=1;
00115 $ck_lev3->value=1;
00116 
00117 
00118 echo '<ul style="list-style-type:none">';
00119 
00120 if (HtmlInput::default_value('lvl1',false,$_GET) !== false)
00121   $ck_lev1->selected=true;
00122 if (HtmlInput::default_value('lvl2',false,$_GET) !== false)
00123   $ck_lev2->selected=true;
00124 if (HtmlInput::default_value('lvl3',false,$_GET) !== false)
00125   $ck_lev3->selected=true;
00126 echo '<li>'.$ck_lev1->input().'Niveau 1</li>';
00127 echo '<li>'.$ck_lev2->input().'Niveau 2</li>';
00128 echo '<li>'.$ck_lev3->input().'Niveau 3</li>';
00129 echo '</ul>';
00130 
00131 $unsold=new ICheckBox('unsold');
00132 if (HtmlInput::default_value('unsold',false,$_GET) !== false)
00133   $unsold->selected=true;
00134 
00135 
00136 $from_poste=new IPoste();
00137 $from_poste->name="from_poste";
00138 $from_poste->set_attribute('ipopup','ipop_account');
00139 $from_poste->set_attribute('label','from_poste_label');
00140 $from_poste->set_attribute('account','from_poste');
00141 
00142 $from_poste->value=(isset($_GET['from_poste']))?$_GET['from_poste']:"";
00143 $from_span=new ISpan("from_poste_label","");
00144 
00145 $to_poste=new IPoste();
00146 $to_poste->name="to_poste";
00147 $to_poste->set_attribute('ipopup','ipop_account');
00148 $to_poste->set_attribute('label','to_poste_label');
00149 $to_poste->set_attribute('account','to_poste');
00150 
00151 $to_poste->value=(isset($_GET['to_poste']))?$_GET['to_poste']:"";
00152 $to_span=new ISpan("to_poste_label","");
00153 
00154 echo "<div>";
00155 echo "Plage de postes :".$from_poste->input();
00156 echo $from_span->input();
00157 echo " jusque :".$to_poste->input();
00158 echo $to_span->input();
00159 echo "</div>";
00160 echo '<div>';
00161 echo "Uniquement comptes non soldés ".$unsold->input();
00162 echo '</div>';
00163 echo HtmlInput::submit("view","Visualisation");
00164 echo '</form>';
00165 echo '<hr>';
00166 //-----------------------------------------------------
00167 // Form
00168 //-----------------------------------------------------
00169 // Show the export button
00170 if ( isset ($_GET['view']  ) )
00171 {
00172 
00173     $hid=new IHidden();
00174 
00175     echo "<table>";
00176     echo '<TR>';
00177     echo '<TD><form method="GET" ACTION="export.php">'.
00178     dossier::hidden().
00179     HtmlInput::submit('bt_pdf',"Export PDF").
00180     HtmlInput::hidden("ac",$_REQUEST['ac']).
00181     HtmlInput::hidden("act","PDF:balance").
00182 
00183     HtmlInput::hidden("from_periode",$_GET['from_periode']).
00184     HtmlInput::hidden("to_periode",$_GET['to_periode']);
00185     echo HtmlInput::hidden('p_filter',$_GET['p_filter']);
00186     for ($e=0;$e<count($array_ledger);$e++)
00187         if (isset($selected[$e]))
00188             echo    HtmlInput::hidden("r_jrn[$e]",$e);
00189     for ($e=0;$e<count($array_cat);$e++)
00190         if (isset($select_cat[$e]))
00191             echo    HtmlInput::hidden("r_cat[$e]",$e);
00192 
00193     echo HtmlInput::hidden("from_poste",$_GET['from_poste']).
00194     HtmlInput::hidden("to_poste",$_GET['to_poste']);
00195     echo HtmlInput::get_to_hidden(array('lvl1','lvl2','lvl3','unsold'));
00196 
00197     echo "</form></TD>";
00198 
00199     echo '<TD><form method="GET" ACTION="export.php">'.
00200     HtmlInput::submit('bt_csv',"Export CSV").
00201     dossier::hidden().
00202     HtmlInput::hidden("act","CSV:balance").
00203     HtmlInput::hidden("from_periode",$_GET['from_periode']).
00204     HtmlInput::hidden("to_periode",$_GET['to_periode']);
00205     echo HtmlInput::get_to_hidden(array('ac'));
00206     echo HtmlInput::hidden('p_filter',$_GET['p_filter']);
00207     if (isset($_GET ['r_jrn']))
00208         if (isset($selected[$e]))
00209             echo    HtmlInput::hidden("r_jrn[$e]",$e);
00210     for ($e=0;$e<count($array_cat);$e++)
00211         if (isset($select_cat[$e]))
00212             echo    HtmlInput::hidden("r_cat[$e]",$e);
00213 
00214     echo   HtmlInput::hidden("from_poste",$_GET['from_poste']).
00215     HtmlInput::hidden("to_poste",$_GET['to_poste']);
00216     echo HtmlInput::get_to_hidden(array('unsold'));
00217 
00218     echo "</form></TD>";
00219         echo '<td style="vertical-align:top">';
00220         echo HtmlInput::print_window();
00221         echo '</td>';
00222     echo "</TR>";
00223 
00224     echo "</table>";
00225 }
00226 
00227 
00228 //-----------------------------------------------------
00229 // Display result
00230 //-----------------------------------------------------
00231 if ( isset($_GET['view'] ) )
00232 {
00233     $bal=new Acc_Balance($cn);
00234     if ( $_GET['p_filter']==1)
00235     {
00236         for ($e=0;$e<count($array_ledger);$e++)
00237             if (isset($selected[$e]))
00238                 $bal->jrn[]=$array_ledger[$e]['jrn_def_id'];
00239     }
00240     if ( $_GET['p_filter'] == 0 )
00241     {
00242         $bal->jrn=null;
00243     }
00244     if ( $_GET['p_filter'] == 2 && isset ($_GET['r_cat']))
00245     {
00246         $bal->filter_cat($_GET['r_cat']);
00247     }
00248     $bal->from_poste=$_GET['from_poste'];
00249     $bal->to_poste=$_GET['to_poste'];
00250     if ( isset($_GET['unsold']))
00251       $bal->unsold=true;
00252     $row=$bal->get_row($_GET['from_periode'],
00253                        $_GET['to_periode']);
00254     $periode=new Periode($cn);
00255     $a=$periode->get_date_limit($_GET['from_periode']);
00256     $b=$periode->get_date_limit($_GET['to_periode']);
00257     echo "<h2 class=\"info\"> période du ".$a['p_start']." au ".$b['p_end']."</h2>";
00258 
00259     echo '<table width="100%">';
00260     echo '<th>Poste Comptable</th>';
00261     echo '<th>Libell&eacute;</th>';
00262     echo '<th>D&eacute;bit</th>';
00263     echo '<th>Cr&eacute;dit</th>';
00264     echo '<th>Solde D&eacute;biteur </th>';
00265     echo '<th>Solde Cr&eacute;diteur</th>';
00266 
00267     $i=0;
00268     foreach(array('sum_cred','sum_deb','solde_deb','solde_cred') as $a)
00269       {
00270         $lvl1[$a]=0;
00271         $lvl2[$a]=0;
00272         $lvl3[$a]=0;
00273       }
00274     $lvl1_old='';
00275     $lvl2_old='';
00276     $lvl3_old='';
00277 
00278     bcscale(2);
00279     foreach ($row as $r)
00280     {
00281         $i++;
00282         if ( $i%2 == 0 )
00283             $tr="even";
00284         else
00285             $tr="odd";
00286         $view_history= sprintf('<A class="detail" style="text-decoration:underline" HREF="javascript:view_history_account(\'%s\',\'%s\')" >%s</A>',
00287                                $r['poste'], $gDossier, $r['poste']);
00288 
00289         /*
00290          * level x
00291          */
00292         foreach (array(3,2,1) as $ind)
00293           {
00294             if ( ! isset($_GET['lvl'.$ind]))continue;
00295             if (${'lvl'.$ind.'_old'} == '')       ${'lvl'.$ind.'_old'}=mb_substr($r['poste'],0,$ind);
00296             if ( ${'lvl'.$ind.'_old'} != mb_substr($r['poste'],0,$ind))
00297               {
00298 
00299                 echo '<tr style="font-size:12px;font-height:bold">';
00300                 echo td("Total niveau ".$ind);
00301                 echo td(${'lvl'.$ind.'_old'});
00302                 echo td(nbm(${'lvl'.$ind}['sum_deb']),'style="text-align:right"');
00303                 echo td(nbm(${'lvl'.$ind}['sum_cred']),'style="text-align:right"');
00304                 echo td(nbm(${'lvl'.$ind}['solde_deb']),'style="text-align:right"');
00305                 echo td(nbm(${'lvl'.$ind}['solde_cred']),'style="text-align:right"');
00306 
00307                 echo '</tr>';
00308                 ${'lvl'.$ind.'_old'}=mb_substr($r['poste'],0,$ind);
00309                 foreach(array('sum_cred','sum_deb','solde_deb','solde_cred') as $a)
00310                   {
00311                     ${'lvl'.$ind}[$a]=0;
00312                   }
00313               }
00314           }
00315           foreach(array('sum_cred','sum_deb','solde_deb','solde_cred') as $a)
00316             {
00317               $lvl1[$a]=bcadd($lvl1[$a],$r[$a]);
00318               $lvl2[$a]=bcadd($lvl2[$a],$r[$a]);
00319               $lvl3[$a]=bcadd($lvl3[$a],$r[$a]);
00320             }
00321         echo '<TR class="'.$tr.'">';
00322         echo td($view_history);
00323         echo td(h($r['label']));
00324         echo td(nbm($r['sum_deb']),'style="text-align:right"');
00325         echo td(nbm($r['sum_cred']),'style="text-align:right"');
00326         echo td(nbm($r['solde_deb']),'style="text-align:right"');
00327         echo td(nbm($r['solde_cred']),'style="text-align:right"');
00328         echo '</TR>';
00329 
00330     }
00331     echo '</table>';
00332 
00333 }// end submit
00334 echo "</div>";
00335 ?>