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 // Copyright(2004) 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>'._('Exercice').'</legend>';;
00046 echo '<form method="GET">';
00047 echo _('Choisissez 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 echo '<br>';
00086 echo HtmlInput::button_action(_('Avancé'), " if (\$('balance_advanced_div').style.display=='none') { \$('balance_advanced_div').show();} else { \$('balance_advanced_div').hide();}");
00087 //-------------------------------------------------
00088 echo '<div id="balance_advanced_div" style="display:none">';
00089 
00090 /*  add a all ledger choice */
00091 echo _('Filtre')." ";
00092 $rad=new IRadio();
00093 $array_ledger=$g_user->get_ledger('ALL',3);
00094 $array=get_array_column($array_ledger,'jrn_def_id');
00095 $selected=(isset($_GET['r_jrn']))?$_GET['r_jrn']:null;
00096 $select_cat=(isset($_GET['r_cat']))?$_GET['r_cat']:null;
00097 $array_cat=Acc_Ledger::array_cat();
00098 
00099 echo '<ul style="list-style-type:none">';
00100 if ( ! isset($_GET['p_filter']) || $_GET['p_filter']==0) $rad->selected='t';
00101 else $rad->selected=false;
00102 echo '<li>'.$rad->input('p_filter',0)._('Aucun filtre, tous les journaux').'</li>';
00103 if (  isset($_GET['p_filter']) && $_GET['p_filter']==1) $rad->selected='t';
00104 else $rad->selected=false;
00105 echo '<li>'.$rad->input('p_filter',1)._('Filtré par journal');
00106 echo HtmlInput::button_choice_ledger(array('div'=>'','type'=>'ALL','all_type'=>1));
00107 echo '</li>';
00108 if (  isset($_GET['p_filter']) && $_GET['p_filter']==2) $rad->selected='t';
00109 else $rad->selected=false;
00110 echo '<li>'.$rad->input('p_filter',2)._('Filtré par catégorie').HtmlInput::select_cat($array_cat).'</li>';
00111 echo '</ul>';
00112 echo _('Totaux par sous-niveaux');
00113 $ck_lev1=new ICheckBox('lvl1');
00114 $ck_lev2=new ICheckBox('lvl2');
00115 $ck_lev3=new ICheckBox('lvl3');
00116 $ck_lev1->value=1;
00117 $ck_lev2->value=1;
00118 $ck_lev3->value=1;
00119 
00120 
00121 echo '<ul style="list-style-type:none">';
00122 
00123 if (HtmlInput::default_value('lvl1',false,$_GET) !== false)
00124   $ck_lev1->selected=true;
00125 if (HtmlInput::default_value('lvl2',false,$_GET) !== false)
00126   $ck_lev2->selected=true;
00127 if (HtmlInput::default_value('lvl3',false,$_GET) !== false)
00128   $ck_lev3->selected=true;
00129 echo '<li>'.$ck_lev1->input()._('Niveau 1').'</li>';
00130 echo '<li>'.$ck_lev2->input()._('Niveau 2').'</li>';
00131 echo '<li>'.$ck_lev3->input()._('Niveau 3').'</li>';
00132 echo '</ul>';
00133 
00134 $unsold=new ICheckBox('unsold');
00135 if (HtmlInput::default_value('unsold',false,$_GET) !== false)
00136   $unsold->selected=true;
00137 
00138 // previous exercice if checked
00139 $previous_exc=new ICheckBox('previous_exc');
00140 if (HtmlInput::default_value('previous_exc',false,$_GET) !== false)
00141   $previous_exc->selected=true;
00142 
00143 
00144 $from_poste=new IPoste();
00145 $from_poste->name="from_poste";
00146 $from_poste->set_attribute('ipopup','ipop_account');
00147 $from_poste->set_attribute('label','from_poste_label');
00148 $from_poste->set_attribute('account','from_poste');
00149 
00150 $from_poste->value=(isset($_GET['from_poste']))?$_GET['from_poste']:"";
00151 $from_span=new ISpan("from_poste_label","");
00152 
00153 $to_poste=new IPoste();
00154 $to_poste->name="to_poste";
00155 $to_poste->set_attribute('ipopup','ipop_account');
00156 $to_poste->set_attribute('label','to_poste_label');
00157 $to_poste->set_attribute('account','to_poste');
00158 
00159 $to_poste->value=(isset($_GET['to_poste']))?$_GET['to_poste']:"";
00160 $to_span=new ISpan("to_poste_label","");
00161 
00162 echo "<div>";
00163 echo _("Plage de postes")." :".$from_poste->input();
00164 echo $from_span->input();
00165 echo " "._("jusque")." :".$to_poste->input();
00166 echo $to_span->input();
00167 echo "</div>";
00168 echo '<div>';
00169 echo '<p>';
00170 echo _("Uniquement comptes non soldés")." ".$unsold->input();
00171 echo '</p>';
00172 echo '<p>';
00173 echo _("Avec la balance de l'année précédente")." ".$previous_exc->input();
00174 echo '</p>';
00175 echo '</div>';
00176 echo '</div>';
00177 echo HtmlInput::submit("view",_("Visualisation"));
00178 echo '</form>';
00179 echo '<hr>';
00180 //-----------------------------------------------------
00181 // Form
00182 //-----------------------------------------------------
00183 // Show the export button
00184 if ( isset ($_GET['view']  ) )
00185 {
00186 
00187     $hid=new IHidden();
00188 
00189 
00190     echo "<table>";
00191     echo '<TR>';
00192     echo '<TD><form method="GET" ACTION="export.php">'.
00193     dossier::hidden().
00194     HtmlInput::submit('bt_pdf',"Export PDF").
00195     HtmlInput::hidden("ac",$_REQUEST['ac']).
00196     HtmlInput::hidden("act","PDF:balance").
00197 
00198     HtmlInput::hidden("from_periode",$_GET['from_periode']).
00199     HtmlInput::hidden("to_periode",$_GET['to_periode']);
00200     echo HtmlInput::hidden('p_filter',$_GET['p_filter']);
00201     for ($e=0;$e<count($selected);$e++)
00202         if (isset($selected[$e]) && in_array ($selected[$e],$array))
00203             echo    HtmlInput::hidden("r_jrn[$e]",$selected[$e]);
00204     for ($e=0;$e<count($array_cat);$e++)
00205         if (isset($select_cat[$e]))
00206             echo    HtmlInput::hidden("r_cat[$e]",$e);
00207 
00208     echo HtmlInput::hidden("from_poste",$_GET['from_poste']).
00209     HtmlInput::hidden("to_poste",$_GET['to_poste']);
00210     echo HtmlInput::get_to_hidden(array('lvl1','lvl2','lvl3','unsold','previous_exc'));
00211 
00212     echo "</form></TD>";
00213 
00214     echo '<TD><form method="GET" ACTION="export.php">'.
00215     HtmlInput::submit('bt_csv',"Export CSV").
00216     dossier::hidden().
00217     HtmlInput::hidden("act","CSV:balance").
00218     HtmlInput::hidden("from_periode",$_GET['from_periode']).
00219     HtmlInput::hidden("to_periode",$_GET['to_periode']);
00220     echo HtmlInput::get_to_hidden(array('ac'));
00221     echo HtmlInput::hidden('p_filter',$_GET['p_filter']);
00222     for ($e=0;$e<count($selected);$e++){
00223         if (isset($selected[$e]) && in_array ($selected[$e],$array)){
00224                 echo    HtmlInput::hidden("r_jrn[$e]",$selected[$e]);
00225             }
00226     }
00227     for ($e=0;$e<count($array_cat);$e++)
00228         if (isset($select_cat[$e]))
00229             echo    HtmlInput::hidden("r_cat[$e]",$e);
00230 
00231     echo   HtmlInput::hidden("from_poste",$_GET['from_poste']).
00232     HtmlInput::hidden("to_poste",$_GET['to_poste']);
00233     echo HtmlInput::get_to_hidden(array('unsold','previous_exc'));
00234 
00235     echo "</form></TD>";
00236         echo '<td style="vertical-align:top">';
00237         echo HtmlInput::print_window();
00238         echo '</td>';
00239     echo "</TR>";
00240 
00241     echo "</table>";
00242 }
00243 
00244 
00245 //-----------------------------------------------------
00246 // Display result
00247 //-----------------------------------------------------
00248 if ( isset($_GET['view'] ) )
00249 {
00250     $bal=new Acc_Balance($cn);
00251     if ( $_GET['p_filter']==1)
00252     {
00253         for ($e=0;$e<count($selected);$e++)
00254             if (isset($selected[$e]) && in_array ($selected[$e],$array))
00255                 $bal->jrn[]=$selected[$e];
00256     }
00257     if ( $_GET['p_filter'] == 0 )
00258     {
00259         $bal->jrn=null;
00260     }
00261     if ( $_GET['p_filter'] == 2 && isset ($_GET['r_cat']))
00262     {
00263         $bal->filter_cat($_GET['r_cat']);
00264     }
00265     $bal->from_poste=$_GET['from_poste'];
00266     $bal->to_poste=$_GET['to_poste'];
00267     if ( isset($_GET['unsold']))  $bal->unsold=true;
00268     $previous=(isset($_GET['previous_exc']))?1:0;
00269     
00270     $row=$bal->get_row($_GET['from_periode'],
00271                        $_GET['to_periode'],
00272             $previous);
00273     $previous= (isset ($row[0]['sum_cred_previous']))?1:0;
00274 
00275     $periode=new Periode($cn);
00276     $a=$periode->get_date_limit($_GET['from_periode']);
00277     $b=$periode->get_date_limit($_GET['to_periode']);
00278     echo "<h2 class=\"info\"> période du ".$a['p_start']." au ".$b['p_end']."</h2>";
00279         echo '<span style="display:block">';
00280         echo _('Filtre').HtmlInput::infobulle(24);
00281         echo HtmlInput::filter_table("t_balance", "0,1","1");
00282         echo '</span>';
00283     echo '<table id="t_balance" width="100%">';
00284     echo '<th>Poste Comptable</th>';
00285     echo '<th>Libell&eacute;</th>';
00286     if ( $previous == 1 ){
00287         echo '<th>D&eacute;bit N-1</th>';
00288         echo '<th>Cr&eacute;dit N-1</th>';
00289         echo '<th>Solde D&eacute;biteur N-1</th>';
00290         echo '<th>Solde Cr&eacute;diteur N-1</th>';
00291     }
00292     echo '<th>D&eacute;bit</th>';
00293     echo '<th>Cr&eacute;dit</th>';
00294     echo '<th>Solde D&eacute;biteur </th>';
00295     echo '<th>Solde Cr&eacute;diteur</th>';
00296     $i=0;
00297     if ( $previous == 1) {
00298         $a_sum=array('sum_cred','sum_deb','solde_deb','solde_cred','sum_cred_previous','sum_deb_previous','solde_deb_previous','solde_cred_previous');
00299     }
00300     else {
00301               $a_sum=array('sum_cred','sum_deb','solde_deb','solde_cred') ;
00302     }
00303     foreach($a_sum as $a)
00304       {
00305         $lvl1[$a]=0;
00306         $lvl2[$a]=0;
00307         $lvl3[$a]=0;
00308       }
00309     $lvl1_old='';
00310     $lvl2_old='';
00311     $lvl3_old='';
00312 
00313     bcscale(2);
00314     foreach ($row as $r)
00315     {
00316         $i++;
00317         if ( $i%2 == 0 )
00318             $tr="even";
00319         else
00320             $tr="odd";
00321         $view_history= sprintf('<A class="detail" style="text-decoration:underline" HREF="javascript:view_history_account(\'%s\',\'%s\')" >%s</A>',
00322                                $r['poste'], $gDossier, $r['poste']);
00323 
00324         /*
00325          * level x
00326          */
00327         foreach (array(3,2,1) as $ind)
00328           {
00329             if ( ! isset($_GET['lvl'.$ind]))continue;
00330             if (${'lvl'.$ind.'_old'} == '')       ${'lvl'.$ind.'_old'}=mb_substr($r['poste'],0,$ind);
00331             if ( ${'lvl'.$ind.'_old'} != mb_substr($r['poste'],0,$ind))
00332               {
00333 
00334                 echo '<tr >';
00335                 echo td(${'lvl'.$ind.'_old'},'style="font-weight:bold;"');
00336                 echo td(${'lvl'.$ind.'_old'}." "._("Total niveau")." ".$ind,'style="font-weight:bold;"');
00337                 if ($previous==1) {
00338                     echo td(nbm(${'lvl'.$ind}['sum_deb_previous']),'class="previous_year" style="font-weight:bold;"');
00339                     echo td(nbm(${'lvl'.$ind}['sum_cred_previous']),' class="previous_year" style="font-weight:bold;" ');
00340                     echo td(nbm(${'lvl'.$ind}['solde_deb_previous']),'class="previous_year" style="font-weight:bold;"');
00341                     echo td(nbm(${'lvl'.$ind}['solde_cred_previous']),'class="previous_year" style="font-weight:bold;"');
00342                 }
00343                 echo td(nbm(${'lvl'.$ind}['sum_deb']),'style="text-align:right;font-weight:bold;"  ');
00344                 echo td(nbm(${'lvl'.$ind}['sum_cred']),'style="text-align:right;font-weight:bold;"');
00345                 echo td(nbm(${'lvl'.$ind}['solde_deb']),'style="text-align:right;font-weight:bold;"');
00346                 echo td(nbm(${'lvl'.$ind}['solde_cred']),'style="text-align:right;font-weight:bold;"');
00347 
00348                 echo '</tr>';
00349                 ${'lvl'.$ind.'_old'}=mb_substr($r['poste'],0,$ind);
00350                 foreach($a_sum as $a)
00351                   {
00352                     ${'lvl'.$ind}[$a]=0;
00353                   }
00354               }
00355           }
00356           
00357           foreach($a_sum as $a)
00358             {
00359               $lvl1[$a]=bcadd($lvl1[$a],$r[$a]);
00360               $lvl2[$a]=bcadd($lvl2[$a],$r[$a]);
00361               $lvl3[$a]=bcadd($lvl3[$a],$r[$a]);
00362             }
00363         echo '<TR class="'.$tr.'">';
00364         echo td($view_history);
00365         echo td(h($r['label']));
00366         if ($previous == 1 ) {
00367             echo td(nbm($r['sum_deb_previous']),' class="previous_year"');
00368             echo td(nbm($r['sum_cred_previous']),' class="previous_year" ');
00369             echo td(nbm($r['solde_deb_previous']),' class="previous_year"');
00370             echo td(nbm($r['solde_cred_previous']),'class="previous_year" ');
00371         }
00372         echo td(nbm($r['sum_deb']),'style="text-align:right;"');
00373         echo td(nbm($r['sum_cred']),'style="text-align:right;"');
00374         echo td(nbm($r['solde_deb']),'style="text-align:right;"');
00375         echo td(nbm($r['solde_cred']),'style="text-align:right;"');
00376         echo '</TR>';
00377 
00378     }
00379     echo '</table>';
00380 
00381 }// end submit
00382 echo "</div>";
00383 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations