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 require_once('class_pdf.php');
00034 bcscale(2);
00035
00036 $gDossier=dossier::id();
00037
00038
00039 $cn=new Database($gDossier);
00040 $g_user->Check();
00041 $g_user->check_dossier($gDossier);
00042
00043 $sql="select pcm_val from tmp_pcmn ";
00044
00045 extract($_GET);
00046 $cond_poste="";
00047 if ($from_poste != '')
00048 {
00049 $cond_poste = ' where ';
00050 $cond_poste .=' pcm_val >= upper (\''.Database::escape_string($from_poste).'\')';
00051 }
00052
00053 if ( $to_poste != '')
00054 {
00055 if ( $cond_poste == '')
00056 {
00057 $cond_poste = ' where pcm_val <= upper (\''.Database::escape_string($to_poste).'\')';
00058 }
00059 else
00060 {
00061 $cond_poste.=' and pcm_val <= upper (\''.Database::escape_string($to_poste).'\')';
00062 }
00063 }
00064
00065 $sql=$sql.$cond_poste.' order by pcm_val::text';
00066 $a_poste=$cn->get_array($sql);
00067
00068 $pdf = new PDF($cn);
00069 $pdf->setDossierInfo(" Periode : ".$from_periode." - ".$to_periode);
00070 $pdf->AliasNbPages();
00071 $pdf->AddPage();
00072 $pdf->setTitle("Grand Livre",true);
00073 $pdf->SetAuthor('NOALYSS');
00074
00075 if ( count($a_poste) == 0 )
00076 {
00077 $pdf->Output();
00078 return;
00079 }
00080
00081 // Header
00082 $header = array( "Date", "Référence", "Libellé", "Pièce","Let", "Débit", "Crédit", "Solde" );
00083 // Left or Right aligned
00084 $lor = array( "L" , "L" , "L" , "L" , "R", "R" , "R" , "R" );
00085 // Column widths (in mm)
00086 $width = array( 13 , 20 , 60 , 15 , 12 , 20 , 20 , 20 );
00087 $l=(isset($_REQUEST['letter']))?2:0;
00088 $s=(isset($_REQUEST['solded']))?1:0;
00089
00090 foreach ($a_poste as $poste)
00091 {
00092
00093 $Poste=new Acc_Account_Ledger($cn,$poste['pcm_val']);
00094
00095
00096 $array1=$Poste->get_row_date($from_periode,$to_periode,$l,$s);
00097 // don't print empty account
00098 if ( count($array1) == 0 )
00099 {
00100 continue;
00101 }
00102 $array=$array1[0];
00103 $tot_deb=$array1[1];
00104 $tot_cred=$array1[2];
00105
00106 $pdf->SetFont('DejaVuCond','',10);
00107 $Libelle=sprintf("%s - %s ",$Poste->id,$Poste->get_name());
00108 $pdf->Cell(0, 7, $Libelle, 1, 1, 'C');
00109
00110 $pdf->SetFont('DejaVuCond','',6);
00111 for($i=0;$i<count($header);$i++)
00112 $pdf->Cell($width[$i], 4, $header[$i], 0, 0, $lor[$i]);
00113 $pdf->Ln();
00114
00115 $pdf->SetFont('DejaVuCond','',7);
00116
00117
00118 $solde = 0.0;
00119 $solde_d = 0.0;
00120 $solde_c = 0.0;
00121 $current_exercice="";
00122 foreach ($Poste->row as $detail)
00123 {
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 if ( $current_exercice == "") $current_exercice=$detail['p_exercice'];
00141
00142 if ( $current_exercice != $detail['p_exercice']) {
00143
00144 $pdf->SetFont('DejaVuCond','B',8);
00145 $i=0;
00146 $pdf->Cell($width[$i], 6, $current_exercice, 0, 0, $lor[$i]);
00147 $i++;
00148 $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
00149 $i++;
00150 $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
00151 $i++;
00152 $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
00153 $i++;
00154 $pdf->Cell($width[$i], 6, 'Total du compte '.$Poste->id, 0, 0, 'R');
00155 $i++;
00156 $pdf->Cell($width[$i], 6, ($solde_d > 0 ? nbm($solde_d) : ''), 0, 0, $lor[$i]);
00157 $i++;
00158 $pdf->Cell($width[$i], 6, ($solde_c > 0 ? nbm( $solde_c) : ''), 0, 0, $lor[$i]);
00159 $i++;
00160 $pdf->Cell($width[$i], 6, nbm(abs($solde_c-$solde_d)), 0, 0, $lor[$i]);
00161 $i++;
00162 $pdf->Cell(5, 6, ($solde_c > $solde_d ? 'C' : 'D'), 0, 0, 'L');
00163
00164
00165
00166 $current_exercice=$detail['p_exercice'];
00167 $solde = 0.0;
00168 $solde_d = 0.0;
00169 $solde_c = 0.0;
00170 $pdf->Ln();
00171 $pdf->SetFont('DejaVuCond','',7);
00172
00173 }
00174
00175 if ($detail['cred_montant'] > 0)
00176 {
00177 $solde = bcsub ($solde,$detail['cred_montant']);
00178 $solde_c = bcadd($solde_c,$detail['cred_montant']);
00179 }
00180 if ($detail['deb_montant'] > 0)
00181 {
00182 $solde = bcadd($solde,$detail['deb_montant']);
00183 $solde_d = bcadd($solde_d,$detail['deb_montant']);
00184 }
00185
00186 $i = 0;
00187 $side=" ".$Poste->get_amount_side($solde);
00188 $pdf->LongLine($width[$i], 6, shrink_date($detail['j_date_fmt']), 0, $lor[$i]);
00189 $i++;
00190 $pdf->LongLine($width[$i], 6, $detail['jr_internal'], 0, $lor[$i] );
00191 $i++;
00192
00193 $triple_point = (mb_strlen($detail['description']) > 40 ) ? '...':'';
00194 $pdf->LongLine($width[$i], 6, mb_substr($detail['description'],0,40).$triple_point, 0,$lor[$i]);
00195 $i++;
00196 $pdf->Cell($width[$i], 6, $detail['jr_pj_number'], 0, 0, $lor[$i]);
00197 $i++;
00198 $pdf->Cell($width[$i], 6, ($detail['letter']!=-1)?$detail['letter']:'', 0, 0, $lor[$i]);
00199 $i++;
00200 $pdf->Cell($width[$i], 6, ($detail['deb_montant'] > 0 ? nbm( $detail['deb_montant']) : ''), 0, 0, $lor[$i]);
00201 $i++;
00202 $pdf->Cell($width[$i], 6, ($detail['cred_montant'] > 0 ? nbm( $detail['cred_montant']) : ''), 0, 0, $lor[$i]);
00203 $i++;
00204 $pdf->Cell($width[$i], 6, nbm(abs( $solde)).$side, 0, 0, $lor[$i]);
00205 $i++;
00206 $pdf->Ln();
00207
00208 }
00209
00210
00211 $pdf->SetFont('DejaVuCond','B',8);
00212
00213 $i = 0;
00214 $pdf->Cell($width[$i], 6, $current_exercice, 0, 0, $lor[$i]);
00215 $i++;
00216 $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
00217 $i++;
00218 $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
00219 $i++;
00220 $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
00221 $i++;
00222 $pdf->Cell($width[$i], 6, 'Total du compte '.$Poste->id, 0, 0, 'R');
00223 $i++;
00224 $pdf->Cell($width[$i], 6, ($solde_d > 0 ? nbm($solde_d) : ''), 0, 0, $lor[$i]);
00225 $i++;
00226 $pdf->Cell($width[$i], 6, ($solde_c > 0 ? nbm( $solde_c) : ''), 0, 0, $lor[$i]);
00227 $i++;
00228 $pdf->Cell($width[$i], 6, nbm(abs($solde_c-$solde_d)), 0, 0, $lor[$i]);
00229 $i++;
00230 $pdf->Cell(5, 6, ($solde_c > $solde_d ? 'C' : 'D'), 0, 0, 'L');
00231
00232 $pdf->Ln();
00233 $pdf->Ln();
00234
00235 }
00236
00237 $pdf->Output("gl_comptes.pdf", 'D');
00238 exit;
00239 ?>