noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
balance.inc.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS 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  *   NOALYSS 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 NOALYSS; 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 danydb@aevalys.eu
00020 /*! \file
00021  * \brief Show the balance and let you print it or export to PDF
00022  *        file included by user_impress
00023  *
00024  * some variable are already defined ($cn, $g_user ...)
00025  */
00026 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
00027 include_once ("ac_common.php");
00028 include_once("class_acc_balance.php");
00029 require_once("class_iselect.php");
00030 require_once("class_ispan.php");
00031 require_once("class_icheckbox.php");
00032 require_once("class_ihidden.php");
00033 require_once('class_acc_ledger.php');
00034 require_once('class_periode.php');
00035 require_once('class_exercice.php');
00036 global $g_user;
00037 $gDossier=dossier::id();
00038 $exercice=(isset($_GET['exercice']))?$_GET['exercice']:$g_user->get_exercice();
00039 
00040 
00041 echo '<div class="content">';
00042 /*
00043  * Let you change the exercice
00044  */
00045 echo '<fieldset  class="noprint"><legend>'._('Choississez un autre exercice').'</legend>';;
00046 echo '<form method="GET">';
00047 echo 'Choississez un autre exercice :';
00048 $ex=new Exercice($cn);
00049 $wex=$ex->select('exercice',$exercice,' onchange="submit(this)"');
00050 echo $wex->input();
00051 echo dossier::hidden();
00052 echo HtmlInput::get_to_hidden(array('ac','type'));
00053 echo '</form>';
00054 echo '</fieldset>';
00055 
00056 
00057 // Show the form for period
00058 echo '<FORM  method="get">';
00059 echo HtmlInput::get_to_hidden(array('ac'));
00060 echo HtmlInput::hidden('type','bal');
00061 echo HtmlInput::get_to_hidden(array('exercice'));
00062 echo dossier::hidden();
00063 
00064 
00065 
00066 // filter on the current year
00067 $from=(isset($_GET["from_periode"]))?$_GET['from_periode']:"";
00068 $input_from=new IPeriod("from_periode",$from,$exercice);
00069 $input_from->show_end_date=false;
00070 $input_from->type=ALL;
00071 $input_from->cn=$cn;
00072 $input_from->filter_year=true;
00073 $input_from->user=$g_user;
00074 
00075 echo 'Depuis :'.$input_from->input();
00076 // filter on the current year
00077 $to=(isset($_GET["to_periode"]))?$_GET['to_periode']:"";
00078 $input_to=new IPeriod("to_periode",$to,$exercice);
00079 $input_to->show_start_date=false;
00080 $input_to->filter_year=true;
00081 $input_to->type=ALL;
00082 $input_to->cn=$cn;
00083 $input_to->user=$g_user;
00084 echo ' jusque :'.$input_to->input();
00085 
00086 //-------------------------------------------------
00087 
00088 
00089 /*  add a all ledger choice */
00090 echo 'Filtre ';
00091 $rad=new IRadio();
00092 $array_ledger=$g_user->get_ledger('ALL',3);
00093 $array=get_array_column($array_ledger,'jrn_def_id');
00094 $selected=(isset($_GET['balr_jrn']))?$_GET['balr_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');
00105 echo HtmlInput::button_choice_ledger(array('div'=>'','type'=>'ALL','all_type'=>1));
00106 echo '</li>';
00107 if (  isset($_GET['p_filter']) && $_GET['p_filter']==2) $rad->selected='t';
00108 else $rad->selected=false;
00109 echo '<li>'.$rad->input('p_filter',2)._('Filtré par catégorie').HtmlInput::select_cat($array_cat).'</li>';
00110 echo '</ul>';
00111 echo _('Totaux par sous-niveaux');
00112 $ck_lev1=new ICheckBox('lvl1');
00113 $ck_lev2=new ICheckBox('lvl2');
00114 $ck_lev3=new ICheckBox('lvl3');
00115 $ck_lev1->value=1;
00116 $ck_lev2->value=1;
00117 $ck_lev3->value=1;
00118 
00119 
00120 echo '<ul style="list-style-type:none">';
00121 
00122 if (HtmlInput::default_value('lvl1',false,$_GET) !== false)
00123   $ck_lev1->selected=true;
00124 if (HtmlInput::default_value('lvl2',false,$_GET) !== false)
00125   $ck_lev2->selected=true;
00126 if (HtmlInput::default_value('lvl3',false,$_GET) !== false)
00127   $ck_lev3->selected=true;
00128 echo '<li>'.$ck_lev1->input()._('Niveau 1').'</li>';
00129 echo '<li>'.$ck_lev2->input()._('Niveau 2').'</li>';
00130 echo '<li>'.$ck_lev3->input()._('Niveau 3').'</li>';
00131 echo '</ul>';
00132 
00133 $unsold=new ICheckBox('unsold');
00134 if (HtmlInput::default_value('unsold',false,$_GET) !== false)
00135   $unsold->selected=true;
00136 
00137 // previous exercice if checked
00138 $previous_exc=new ICheckBox('previous_exc');
00139 if (HtmlInput::default_value('previous_exc',false,$_GET) !== false)
00140   $previous_exc->selected=true;
00141 
00142 
00143 $from_poste=new IPoste();
00144 $from_poste->name="from_poste";
00145 $from_poste->set_attribute('ipopup','ipop_account');
00146 $from_poste->set_attribute('label','from_poste_label');
00147 $from_poste->set_attribute('account','from_poste');
00148 
00149 $from_poste->value=(isset($_GET['from_poste']))?$_GET['from_poste']:"";
00150 $from_span=new ISpan("from_poste_label","");
00151 
00152 $to_poste=new IPoste();
00153 $to_poste->name="to_poste";
00154 $to_poste->set_attribute('ipopup','ipop_account');
00155 $to_poste->set_attribute('label','to_poste_label');
00156 $to_poste->set_attribute('account','to_poste');
00157 
00158 $to_poste->value=(isset($_GET['to_poste']))?$_GET['to_poste']:"";
00159 $to_span=new ISpan("to_poste_label","");
00160 
00161 echo "<div>";
00162 echo _("Plage de postes")." :".$from_poste->input();
00163 echo $from_span->input();
00164 echo " "._("jusque")." :".$to_poste->input();
00165 echo $to_span->input();
00166 echo "</div>";
00167 echo '<div>';
00168 echo '<p>';
00169 echo _("Uniquement comptes non soldés")." ".$unsold->input();
00170 echo '</p>';
00171 echo '<p>';
00172 echo _("Avec la balance de l'année précédente")." ".$previous_exc->input();
00173 echo '</p>';
00174 echo '</div>';
00175 echo HtmlInput::submit("view",_("Visualisation"));
00176 echo '</form>';
00177 echo '<hr>';
00178 //-----------------------------------------------------
00179 // Form
00180 //-----------------------------------------------------
00181 // Show the export button
00182 if ( isset ($_GET['view']  ) )
00183 {
00184 
00185     $hid=new IHidden();
00186 
00187 
00188     echo "<table>";
00189     echo '<TR>';
00190     echo '<TD><form method="GET" ACTION="export.php">'.
00191     dossier::hidden().
00192     HtmlInput::submit('bt_pdf',"Export PDF").
00193     HtmlInput::hidden("ac",$_REQUEST['ac']).
00194     HtmlInput::hidden("act","PDF:balance").
00195 
00196     HtmlInput::hidden("from_periode",$_GET['from_periode']).
00197     HtmlInput::hidden("to_periode",$_GET['to_periode']);
00198     echo HtmlInput::hidden('p_filter',$_GET['p_filter']);
00199     for ($e=0;$e<count($selected);$e++)
00200         if (isset($selected[$e]) && in_array ($selected[$e],$array))
00201             echo    HtmlInput::hidden("r_jrn[$e]",$selected[$e]);
00202     for ($e=0;$e<count($array_cat);$e++)
00203         if (isset($select_cat[$e]))
00204             echo    HtmlInput::hidden("r_cat[$e]",$e);
00205 
00206     echo HtmlInput::hidden("from_poste",$_GET['from_poste']).
00207     HtmlInput::hidden("to_poste",$_GET['to_poste']);
00208     echo HtmlInput::get_to_hidden(array('lvl1','lvl2','lvl3','unsold','previous_exc'));
00209 
00210     echo "</form></TD>";
00211 
00212     echo '<TD><form method="GET" ACTION="export.php">'.
00213     HtmlInput::submit('bt_csv',"Export CSV").
00214     dossier::hidden().
00215     HtmlInput::hidden("act","CSV:balance").
00216     HtmlInput::hidden("from_periode",$_GET['from_periode']).
00217     HtmlInput::hidden("to_periode",$_GET['to_periode']);
00218     echo HtmlInput::get_to_hidden(array('ac'));
00219     echo HtmlInput::hidden('p_filter',$_GET['p_filter']);
00220     for ($e=0;$e<count($selected);$e++){
00221         if (isset($selected[$e]) && in_array ($selected[$e],$array)){
00222                 echo    HtmlInput::hidden("r_jrn[$e]",$selected[$e]);
00223             }
00224     }
00225     for ($e=0;$e<count($array_cat);$e++)
00226         if (isset($select_cat[$e]))
00227             echo    HtmlInput::hidden("r_cat[$e]",$e);
00228 
00229     echo   HtmlInput::hidden("from_poste",$_GET['from_poste']).
00230     HtmlInput::hidden("to_poste",$_GET['to_poste']);
00231     echo HtmlInput::get_to_hidden(array('unsold','previous_exc'));
00232 
00233     echo "</form></TD>";
00234         echo '<td style="vertical-align:top">';
00235         echo HtmlInput::print_window();
00236         echo '</td>';
00237     echo "</TR>";
00238 
00239     echo "</table>";
00240 }
00241 
00242 
00243 //-----------------------------------------------------
00244 // Display result
00245 //-----------------------------------------------------
00246 if ( isset($_GET['view'] ) )
00247 {
00248     $bal=new Acc_Balance($cn);
00249     if ( $_GET['p_filter']==1)
00250     {
00251         for ($e=0;$e<count($selected);$e++)
00252             if (isset($selected[$e]) && in_array ($selected[$e],$array))
00253                 $bal->jrn[]=$selected[$e];
00254     }
00255     if ( $_GET['p_filter'] == 0 )
00256     {
00257         $bal->jrn=null;
00258     }
00259     if ( $_GET['p_filter'] == 2 && isset ($_GET['r_cat']))
00260     {
00261         $bal->filter_cat($_GET['r_cat']);
00262     }
00263     $bal->from_poste=$_GET['from_poste'];
00264     $bal->to_poste=$_GET['to_poste'];
00265     if ( isset($_GET['unsold']))  $bal->unsold=true;
00266     $previous=(isset($_GET['previous_exc']))?1:0;
00267     
00268     $row=$bal->get_row($_GET['from_periode'],
00269                        $_GET['to_periode'],
00270             $previous);
00271     $previous= (isset ($row[0]['sum_cred_previous']))?1:0;
00272 
00273     $periode=new Periode($cn);
00274     $a=$periode->get_date_limit($_GET['from_periode']);
00275     $b=$periode->get_date_limit($_GET['to_periode']);
00276     echo "<h2 class=\"info\"> période du ".$a['p_start']." au ".$b['p_end']."</h2>";
00277         echo '<span style="display:block">';
00278         echo _('Filtre').HtmlInput::infobulle(24);
00279         echo HtmlInput::filter_table("t_balance", "0,1","1");
00280         echo '</span>';
00281     echo '<table id="t_balance" width="100%">';
00282     echo '<th>Poste Comptable</th>';
00283     echo '<th>Libell&eacute;</th>';
00284     if ( $previous == 1 ){
00285         echo '<th>D&eacute;bit N-1</th>';
00286         echo '<th>Cr&eacute;dit N-1</th>';
00287         echo '<th>Solde D&eacute;biteur N-1</th>';
00288         echo '<th>Solde Cr&eacute;diteur N-1</th>';
00289     }
00290     echo '<th>D&eacute;bit</th>';
00291     echo '<th>Cr&eacute;dit</th>';
00292     echo '<th>Solde D&eacute;biteur </th>';
00293     echo '<th>Solde Cr&eacute;diteur</th>';
00294     $i=0;
00295     if ( $previous == 1) {
00296         $a_sum=array('sum_cred','sum_deb','solde_deb','solde_cred','sum_cred_previous','sum_deb_previous','solde_deb_previous','solde_cred_previous');
00297     }
00298     else {
00299               $a_sum=array('sum_cred','sum_deb','solde_deb','solde_cred') ;
00300     }
00301     foreach($a_sum as $a)
00302       {
00303         $lvl1[$a]=0;
00304         $lvl2[$a]=0;
00305         $lvl3[$a]=0;
00306       }
00307     $lvl1_old='';
00308     $lvl2_old='';
00309     $lvl3_old='';
00310 
00311     bcscale(2);
00312     foreach ($row as $r)
00313     {
00314         $i++;
00315         if ( $i%2 == 0 )
00316             $tr="even";
00317         else
00318             $tr="odd";
00319         $view_history= sprintf('<A class="detail" style="text-decoration:underline" HREF="javascript:view_history_account(\'%s\',\'%s\')" >%s</A>',
00320                                $r['poste'], $gDossier, $r['poste']);
00321 
00322         /*
00323          * level x
00324          */
00325         foreach (array(3,2,1) as $ind)
00326           {
00327             if ( ! isset($_GET['lvl'.$ind]))continue;
00328             if (${'lvl'.$ind.'_old'} == '')       ${'lvl'.$ind.'_old'}=mb_substr($r['poste'],0,$ind);
00329             if ( ${'lvl'.$ind.'_old'} != mb_substr($r['poste'],0,$ind))
00330               {
00331 
00332                 echo '<tr >';
00333                 echo td("Total niveau ".$ind,'style="font-weight:bold;"');
00334                 echo td(${'lvl'.$ind.'_old'},'style="font-weight:bold;"');
00335                 if ($previous==1) {
00336                     echo td(nbm(${'lvl'.$ind}['sum_deb_previous']),'style="text-align:right;font-weight:bold;"');
00337                     echo td(nbm(${'lvl'.$ind}['sum_cred_previous']),'style="text-align:right;font-weight:bold;"');
00338                     echo td(nbm(${'lvl'.$ind}['solde_deb_previous']),'style="text-align:right;font-weight:bold;"');
00339                     echo td(nbm(${'lvl'.$ind}['solde_cred_previous']),'style="text-align:right;font-weight:bold;"');
00340                 }
00341                 echo td(nbm(${'lvl'.$ind}['sum_deb']),'style="text-align:right;font-weight:bold;"');
00342                 echo td(nbm(${'lvl'.$ind}['sum_cred']),'style="text-align:right;font-weight:bold;"');
00343                 echo td(nbm(${'lvl'.$ind}['solde_deb']),'style="text-align:right;font-weight:bold;"');
00344                 echo td(nbm(${'lvl'.$ind}['solde_cred']),'style="text-align:right;font-weight:bold;"');
00345 
00346                 echo '</tr>';
00347                 ${'lvl'.$ind.'_old'}=mb_substr($r['poste'],0,$ind);
00348                 foreach($a_sum as $a)
00349                   {
00350                     ${'lvl'.$ind}[$a]=0;
00351                   }
00352               }
00353           }
00354           
00355           foreach($a_sum as $a)
00356             {
00357               $lvl1[$a]=bcadd($lvl1[$a],$r[$a]);
00358               $lvl2[$a]=bcadd($lvl2[$a],$r[$a]);
00359               $lvl3[$a]=bcadd($lvl3[$a],$r[$a]);
00360             }
00361         echo '<TR class="'.$tr.'">';
00362         echo td($view_history);
00363         echo td(h($r['label']));
00364         if ($previous == 1 ) {
00365             echo td(nbm($r['sum_deb_previous']),'style="text-align:right;"');
00366             echo td(nbm($r['sum_cred_previous']),'style="text-align:right;"');
00367             echo td(nbm($r['solde_deb_previous']),'style="text-align:right;"');
00368             echo td(nbm($r['solde_cred_previous']),'style="text-align:right;"');
00369         }
00370         echo td(nbm($r['sum_deb']),'style="text-align:right;"');
00371         echo td(nbm($r['sum_cred']),'style="text-align:right;"');
00372         echo td(nbm($r['solde_deb']),'style="text-align:right;"');
00373         echo td(nbm($r['solde_cred']),'style="text-align:right;"');
00374         echo '</TR>';
00375 
00376     }
00377     echo '</table>';
00378 
00379 }// end submit
00380 echo "</div>";
00381 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations