Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
00026 include_once('class_acc_account_ledger.php');
00027 include_once('ac_common.php');
00028 require_once('class_database.php');
00029 include_once('class_impress.php');
00030 require_once('class_own.php');
00031 require_once('class_dossier.php');
00032 require_once('class_user.php');
00033
00034 header('Content-type: application/csv');
00035 header('Content-Disposition: attachment;filename="gl_comptes.csv"',FALSE);
00036 header('Pragma: public');
00037
00038
00039 $gDossier=dossier::id();
00040
00041
00042 $cn=new Database($gDossier);
00043
00044
00045 extract($_GET);
00046
00047 if ( isset($poste_id) && strlen(trim($poste_id)) != 0 && isNumber($poste_id) )
00048 {
00049 if ( isset ($poste_fille) )
00050 {
00051 $parent=$poste_id;
00052 $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text like '$parent%' order by pcm_val::text");
00053 }
00054 elseif ( $cn->count_sql('select * from tmp_pcmn where pcm_val='.sql_string($poste_id)) != 0 )
00055 {
00056 $a_poste=array('pcm_val' => $poste_id);
00057 }
00058 }
00059 else
00060 {
00061 $cond_poste='';
00062 $sql="select pcm_val from tmp_pcmn ";
00063 if ($from_poste != '')
00064 {
00065 $cond_poste = ' where ';
00066 $cond_poste .=' pcm_val >= upper (\''.Database::escape_string($from_poste).'\')';
00067 }
00068
00069 if ( $to_poste != '')
00070 {
00071 if ( $cond_poste == '')
00072 {
00073 $cond_poste = " where pcm_val <= upper (''".Database::escape_string($to_poste)."'')";
00074 }
00075 else
00076 {
00077 $cond_poste.=" and pcm_val <= upper (''".Database::escape_string($to_poste)."'')";
00078 }
00079 }
00080
00081 $sql=$sql.$cond_poste.' order by pcm_val::text';
00082
00083 $a_poste=$cn->get_array($sql);
00084
00085 }
00086
00087 if ( count($a_poste) == 0 )
00088 {
00089 echo 'Rien à rapporter.';
00090 printf("\n");
00091 exit;
00092 }
00093
00094 // Header
00095 $header = array( "Date", "Référence", "Libellé", "Pièce","Lettrage", "Débit", "Crédit", "Solde" );
00096
00097 $l=(isset($_GET['letter']))?2:0;
00098 $s=(isset($_REQUEST['solded']))?1:0;
00099
00100 foreach ($a_poste as $poste)
00101 {
00102
00103
00104 $Poste=new Acc_Account_Ledger($cn,$poste['pcm_val']);
00105
00106 $array1=$Poste->get_row_date($from_periode,$to_periode,$l,$s);
00107 // don't print empty account
00108 if ( count($array1) == 0 )
00109 {
00110 continue;
00111 }
00112 $array=$array1[0];
00113 $tot_deb=$array1[1];
00114 $tot_cred=$array1[2];
00115
00116
00117 if ( count($array) == 0 )
00118 {
00119 continue;
00120 }
00121
00122 echo sprintf("%s - %s ",$Poste->id,$Poste->get_name());
00123 printf("\n");
00124
00125 for($i=0;$i<count($header);$i++)
00126 echo $header[$i].";";
00127 printf("\n");
00128
00129 $solde = 0.0;
00130 $solde_d = 0.0;
00131 $solde_c = 0.0;
00132
00133 foreach ($Poste->row as $detail)
00134 {
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 if ($detail['cred_montant'] > 0)
00150 {
00151 $solde -= $detail['cred_montant'];
00152 $solde_c += $detail['cred_montant'];
00153 }
00154 if ($detail['deb_montant'] > 0)
00155 {
00156 $solde += $detail['deb_montant'];
00157 $solde_d += $detail['deb_montant'];
00158 }
00159
00160 echo $detail['j_date_fmt'].";";
00161 echo $detail['jr_internal'].";";
00162 echo $detail['description'].";";
00163 echo $detail['jr_pj_number'].";";
00164 if ($detail['letter'] == -1) { echo ';'; } else { echo $detail['letter'].";";}
00165 echo ($detail['deb_montant'] > 0 ? nb($detail['deb_montant']) : '').";";
00166 echo ($detail['cred_montant'] > 0 ? nb($detail['cred_montant']) : '').";";
00167 echo nb(abs($solde)).";";
00168 echo $Poste->get_amount_side($solde);
00169 printf("\n");
00170
00171 }
00172
00173
00174 echo ";";
00175 echo ";";
00176 echo ";";
00177 echo ";";
00178 echo 'Total du compte '.$Poste->id.";";
00179 echo ($solde_d > 0 ? nb($solde_d) : '').";";
00180 echo ($solde_c > 0 ? nb( $solde_c) : '').";";
00181 echo nb(abs($solde_c-$solde_d)).";";
00182 echo ($solde_c > $solde_d ? 'C' : 'D').";";
00183 printf("\n");
00184 printf("\n");
00185 }
00186
00187 exit;
00188
00189 ?>