noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
impress_gl_comptes.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 Author Dany De Bontridder danydb@aevalys.eu
00020 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
00021 require_once("class_ispan.php");
00022 require_once("class_icard.php");
00023 require_once("class_iselect.php");
00024 require_once("class_icheckbox.php");
00025 require_once('class_acc_operation.php');
00026 /*! \file
00027  * \brief Print account (html or pdf)
00028  *        file included from user_impress
00029  *
00030  * some variable are already defined $cn, $g_user ...
00031  *
00032  */
00033 //-----------------------------------------------------
00034 // Show the jrn and date
00035 //-----------------------------------------------------
00036 require_once('class_database.php');
00037 global $g_user;
00038 //-----------------------------------------------------
00039 // Form
00040 //-----------------------------------------------------
00041 echo '<div class="content">';
00042 
00043 echo '<FORM action="?" METHOD="GET">';
00044 echo HtmlInput::hidden('ac',$_REQUEST['ac']);
00045 echo HtmlInput::hidden('type','gl_comptes');
00046 echo dossier::hidden();
00047 echo '<TABLE><TR>';
00048 
00049 $cn=new Database(dossier::id());
00050 $periode=new Periode($cn);
00051 $a=$periode->get_limit($g_user->get_exercice());
00052 // $a is an array
00053 $first_day=$a[0]->first_day();
00054 $last_day=$a[1]->last_day();
00055 
00056 // filter on period
00057 $date_from=new IDate('from_periode');
00058 $date_to=new IDate('to_periode');
00059 $year=$g_user->get_exercice();
00060 $date_from->value=(isset($_REQUEST['from_periode'])&& isDate($_REQUEST['from_periode'])!=0)?$_REQUEST['from_periode']:$first_day;
00061 $date_to->value=(isset($_REQUEST['to_periode']) && isDate($_REQUEST['to_periode']) !=0  )?$_REQUEST['to_periode']:$last_day;
00062 echo td(_('Depuis').$date_from->input());
00063 echo td(_('Jusque ').$date_to->input());
00064 
00065 $letter=new ICheckbox('letter');
00066 $letter->selected=(isset($_REQUEST['letter']))?true:false;
00067 
00068 $from_poste=new IPoste('from_poste');
00069 $from_poste->value=HtmlInput::default_value('from_poste','',$_REQUEST);
00070 $from_poste->set_attribute('account','from_poste');
00071 
00072 $to_poste=new IPoste('to_poste');
00073 $to_poste->value=HtmlInput::default_value('to_poste','',$_REQUEST);
00074 $to_poste->set_attribute('account','to_poste');
00075 
00076 $solded=new ICheckbox('solded');
00077 $solded->selected=(isset($_REQUEST['solded']))?true:false;
00078 
00079 echo '<tr>';
00080 echo td(_('Depuis le poste')).td($from_poste->input());
00081 echo '</tr>';
00082 
00083 echo '<tr>';
00084 echo td(_("Jusqu'au poste")).td($to_poste->input());
00085 echo '</tr>';
00086 
00087 echo '<tr>';
00088 echo td(_('Uniquement les opérations non lettrées'));
00089 echo td($letter->input());
00090 echo '</tr>';
00091 
00092 echo '<tr>';
00093 echo td(_('Uniquement les comptes non soldés'));
00094 echo td($solded->input());
00095 echo '</tr>';
00096 
00097 
00098 //
00099 echo '</TABLE>';
00100 print HtmlInput::submit('bt_html',_('Visualisation'));
00101 
00102 echo '</FORM>';
00103 echo '<hr>';
00104 echo '</div>';
00105 
00106 //-----------------------------------------------------
00107 // If print is asked
00108 // First time in html
00109 // after in pdf or cvs
00110 //-----------------------------------------------------
00111 if ( isset( $_REQUEST['bt_html'] ) )
00112 {
00113   require_once("class_acc_account_ledger.php");
00114   echo '<div class="content">';
00115     echo Acc_Account_Ledger::HtmlTableHeader("gl_comptes");
00116     echo '</div>';
00117     $sql='select pcm_val from tmp_pcmn ';
00118     $cond_poste='';
00119 
00120     if ($from_poste->value != '')
00121       {
00122                 $cond_poste = '  where ';
00123                 $cond_poste .=' pcm_val >= upper (\''.Database::escape_string($from_poste->value).'\')';
00124       }
00125 
00126     if ( $to_poste->value != '')
00127       {
00128         if  ( $cond_poste == '')
00129           {
00130             $cond_poste =  ' where pcm_val <= upper (\''.Database::escape_string($to_poste->value).'\')';
00131           }
00132         else
00133           {
00134             $cond_poste.=' and pcm_val <= upper (\''.Database::escape_string($to_poste->value).'\')';
00135           }
00136       }
00137 
00138     $sql=$sql.$cond_poste.'  order by pcm_val::text';
00139 
00140     $a_poste=$cn->get_array($sql);
00141 
00142     if ( sizeof($a_poste) == 0 )
00143     {
00144         die("Nothing here. Strange.");
00145         exit;
00146     }
00147     if ( isDate($_REQUEST['from_periode'])==null || isDate($_REQUEST['to_periode'])==null)
00148     {
00149         echo alert('Date malformée, désolée');
00150         return;
00151     }
00152     echo '<div class="content">';
00153 
00154 
00155     echo '<table class="result">';
00156         $l=(isset($_REQUEST['letter']))?2:0;
00157         $s=(isset($_REQUEST['solded']))?1:0;
00158     
00159     
00160     foreach ($a_poste as $poste_id )
00161     {
00162         $Poste=new Acc_Account_Ledger ($cn, $poste_id['pcm_val']);
00163         $Poste->load();
00164 
00165 
00166         $Poste->get_row_date( $_GET['from_periode'], $_GET['to_periode'],$l,$s);
00167         if ( empty($Poste->row))
00168         {
00169             continue;
00170         }
00171         
00172 
00173         echo '<tr >
00174         <td colspan="8" style="width:auto">
00175         <h2 class="info">'. $poste_id['pcm_val'].' '.h($Poste->label).'</h2>
00176         </td>
00177         </tr>';
00178 
00179         echo '<tr>
00180         <td>Date</td>
00181         <td>R&eacute;f&eacute;rence</td>
00182         <td>Libell&eacute;</td>
00183         <td>Pi&egrave;ce</td>
00184         <td align="right">D&eacute;bit</td>
00185         <td align="right">Cr&eacute;dit</td>
00186         <td align="right">Solde</td>
00187         <td align="right">Let.</td>
00188         </tr>';
00189 
00190         $solde = 0.0;
00191         $solde_d = 0.0;
00192         $solde_c = 0.0;
00193         bcscale(2);
00194         $i=0;
00195         $current_exercice="";
00196 
00197         foreach ($Poste->row as $detail)
00198         {
00199             /*
00200              * separation per exercice
00201              */
00202             if ( $current_exercice == "") $current_exercice=$detail['p_exercice'];
00203             
00204             if ( $current_exercice != $detail['p_exercice']) {
00205                 echo '<tr class="highlight">
00206                <td>'.$current_exercice.'</td>
00207                <td>'.''.'</td>
00208                <td>'.'Total du compte '.$poste_id['pcm_val'].'</td>
00209                <td>'.''.'</td>
00210                <td align="right">'.($solde_d  > 0 ? nbm( $solde_d)  : '').'</td>
00211                <td align="right">'.($solde_c  > 0 ? nbm( $solde_c)  : '').'</td>
00212                <td align="right">'.nbm( abs($solde_c-$solde_d)).'</td>
00213                <td>';
00214                if ($solde_c > $solde_d ) echo _("Crédit");
00215                if ($solde_c < $solde_d )  echo _("Débit");
00216                if ($solde_c == $solde_d )  echo "=";
00217 
00218              echo '</td>'.
00219                '</tr>';
00220              /*
00221               * reset total and current_exercice
00222               */
00223                 $current_exercice=$detail['p_exercice'];
00224                 $solde = 0.0;
00225                 $solde_d = 0.0;
00226                 $solde_c = 0.0;
00227 
00228             }
00229             
00230             
00231             if ($detail['cred_montant'] > 0)
00232             {
00233               $solde=bcsub($solde, $detail['cred_montant']);
00234               $solde_c=bcadd($solde_c,$detail['cred_montant']);
00235             }
00236             if ($detail['deb_montant'] > 0)
00237             {
00238               $solde   = bcadd($solde,$detail['deb_montant']);
00239               $solde_d = bcadd($solde_d,$detail['deb_montant']);
00240             }
00241                         $side="&nbsp;".$Poste->get_amount_side($solde);
00242             $letter="";
00243                 $html_let="";
00244                 if ($detail['letter']!=-1) {
00245                         $letter=strtoupper(base_convert($detail['letter'],10,36));
00246                         $html_let = HtmlInput::show_reconcile("", $letter);
00247                 }
00248                 $i++;
00249                 if (($i % 2 ) == 0) $class="odd"; else $class="even";
00250             echo '<tr name="tr_'.$letter.'_" class="'.$class.'">
00251             <td>'.$detail['j_date_fmt'].'</td>
00252             <td>'.HtmlInput::detail_op($detail['jr_id'],$detail['jr_internal']).'</td>
00253             <td>'.$detail['description'].'</td>
00254             <td>'.$detail['jr_pj_number'].'</td>
00255             <td align="right">'.($detail['deb_montant']  > 0 ? nbm($detail['deb_montant'])  : '').'</td>
00256             <td align="right">'.($detail['cred_montant'] > 0 ? nbm($detail['cred_montant']) : '').'</td>
00257             <td align="right">'.nbm(abs($solde)).$side.'</td>
00258             <td  style="text-align:right;color:red">'.$html_let.'</td>
00259             </tr>';
00260         }
00261         echo '<tr class="highlight">
00262         <td>'.$current_exercice.'</td>
00263         <td>'.''.'</td>
00264         <td>'.'<b>'.'Total du compte '.$poste_id['pcm_val'].'</b>'.'</td>
00265         <td>'.''.'</td>
00266         <td align="right">'.'<b>'.($solde_d  > 0 ? nbm( $solde_d)  : '').'</b>'.'</td>
00267         <td align="right">'.'<b>'.($solde_c  > 0 ? nbm( $solde_c)  : '').'</b>'.'</td>
00268         <td align="right">'.'<b>'.nbm( abs($solde_c-$solde_d)).'</b>'.'</td>
00269         <td>';
00270         if ($solde_c > $solde_d ) echo "Crédit";
00271         if ($solde_c < $solde_d )  echo "Débit";
00272         if ($solde_c == $solde_d )  echo "=";
00273 
00274       echo '</td>'.
00275         '</tr>';
00276     }
00277     echo '</table>';
00278     echo Acc_Account_Ledger::HtmlTableHeader("gl_comptes");
00279     echo "</div>";
00280     exit;
00281 }
00282 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations