noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
export_poste_detail_pdf.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004  *   This file is part of NOALYSS.
00005  *
00006  *   NOALYSS is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   NOALYSS is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with NOALYSS; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 */
00020 
00021 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00022 /*! \file
00023  * \brief send the account list in PDF
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 ('header_print.php');
00031 require_once('class_dossier.php');
00032 require_once('class_user.php');
00033 require_once('class_pdf.php');
00034 
00035 $gDossier=dossier::id();
00036 
00037 /* Security */
00038 $cn=new Database($gDossier);
00039 extract($_GET);
00040 
00041 if ( isset ( $poste_fille) )
00042 { //choisit de voir tous les postes
00043     $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text like '$poste_id%' order by pcm_val");
00044 }
00045 else
00046     $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text = '$poste_id'");
00047 
00048 
00049 $ret="";
00050 
00051 $pdf=new PDF($cn);
00052 $pdf->setDossierInfo("  Periode : ".$_GET['from_periode']." - ".$_GET['to_periode']);
00053 $pdf->AliasNbPages();
00054 $pdf->AddPage();
00055 $pdf->SetAuthor('NOALYSS');
00056 $pdf->setTitle("Détail poste comptable",true);
00057 
00058 
00059 if ( count($a_poste) == 0 )
00060 {
00061     $pdf->Output('poste.pdf','D');
00062     exit;
00063 }
00064 $size=array(13,25,13,65,12,20,20,20);
00065 $align=array('L','C','C','L','R','R','R','R');
00066 
00067 foreach ($a_poste as $poste)
00068 {
00069     $Poste=new Acc_Account_Ledger($cn,$poste['pcm_val']);
00070     list($array,$tot_deb,$tot_cred)=$Poste->get_row_date($from_periode,$to_periode,$_GET['ople']);
00071     // don't print empty account
00072     if ( count($array) == 0 )
00073     {
00074         continue;
00075     }
00076     $Libelle=sprintf("(%s) %s ",$Poste->id,$Poste->get_name());
00077     $pdf->SetFont('DejaVuCond','',10);
00078     $pdf->Cell(0,8,$Libelle,1,0,'C');
00079     $pdf->Ln();
00080 
00081     $pdf->SetFont('DejaVuCond','',8);
00082     $l=0;
00083     $pdf->Cell($size[$l],6,'Date',0,0,'L');
00084     $l++;
00085     $pdf->Cell($size[$l],6,'Ref',0,0,'C');
00086     $l++;
00087     $pdf->Cell($size[$l],6,'Journal',0,0,'C');
00088     $l++;
00089     $pdf->LongLine($size[$l],6,'Libellé',0,'L');
00090     $l++;
00091     $pdf->Cell($size[$l],6,'Let',0,0,'R');
00092     $l++;
00093     $pdf->Cell($size[$l],6,'Debit',0,0,'R');
00094     $l++;
00095     $pdf->Cell($size[$l],6,'Credit',0,0,'R');
00096     $l++;
00097     $pdf->Cell($size[$l],6,'Prog',0,0,'R');
00098     $l++;
00099     $pdf->ln();
00100     $tot_deb=0;
00101     $tot_cred=0;
00102     $prog=0;
00103     $current_exercice="";
00104     bcscale(2);
00105     for ($e=0;$e<count($array);$e++)
00106     {
00107         $row=$array[$e];
00108          /*
00109              * separation per exercice
00110              */
00111             if ( $current_exercice == "") $current_exercice=$row['p_exercice'];
00112             
00113             if ( $current_exercice != $row['p_exercice']) {
00114                     $str_debit=sprintf("% 12.2f €",$tot_deb);
00115                     $str_credit=sprintf("% 12.2f €",$tot_cred);
00116                     $diff_solde=bcsub($tot_deb,$tot_cred);
00117                     if ( $diff_solde < 0 )
00118                     {
00119                         $solde=" créditeur ";
00120                         $diff_solde=bcmul($diff_solde,-1);
00121                     }
00122                     else
00123                     {
00124                          $solde=" débiteur ";
00125                     }
00126                     $str_diff_solde=sprintf("%12.2f €",$diff_solde);
00127 
00128                     $pdf->SetFont('DejaVu','B',8);
00129                     $pdf->Cell(15,6,_('totaux'),0,0,'L');
00130                     $pdf->Cell(15,6,$current_exercice,0,0,'L');
00131                     $pdf->Cell(40,6,$solde,0,'L');
00132                     $pdf->Cell(40,6,$str_debit,0,0,'R');
00133                     $pdf->Cell(40,6,$str_credit,0,0,'R');
00134                     $pdf->Cell(40,6,$str_diff_solde,0,0,'R');
00135                     $pdf->Ln();
00136                     /*
00137                     * reset total and current_exercice
00138                     */
00139                     $prog=0;
00140                     $current_exercice=$row['p_exercice'];
00141                     $tot_deb=0;$tot_cred=0;    
00142                     $pdf->SetFont('DejaVuCond','',8);
00143             }
00144         $l=0;
00145         $diff=bcsub($row['deb_montant'],$row['cred_montant']);
00146         $prog=bcadd($row['deb_montant'],$row['cred_montant']);
00147 
00148         $date=shrink_date($row['j_date_fmt']);
00149         $pdf->Cell($size[$l],6,$date,0,0,$align[$l]);
00150         $l++;
00151         if ( $row['jr_pj_number'] == '')
00152           $pdf->Cell($size[$l],6,$row['jr_internal'],0,0,$align[$l]);
00153         else
00154           $pdf->Cell($size[$l],6,$row['jr_pj_number'],0,0,$align[$l]);
00155         $l++;
00156         $pdf->Cell($size[$l],6,mb_substr($row['jrn_def_code'],0,14),0,0,$align[$l]);
00157         $l++;
00158         $pdf->LongLine($size[$l],6,  $row['description'],0,$align[$l]);
00159         $l++;
00160         $pdf->Cell($size[$l],6,(($row['letter']!=-1)?$row['letter']:''),0,0,$align[$l]);
00161         $l++;
00162         $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$row['deb_montant'])),0,0,$align[$l]);
00163         $l++;
00164         $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$row['cred_montant'])),0,0,$align[$l]);
00165         $l++;
00166         $pdf->Cell($size[$l],6,(sprintf('% 12.2f',abs($prog))),0,0,$align[$l]);
00167         $l++;
00168         $pdf->ln();
00169         $tot_deb=bcadd($tot_deb,$row['deb_montant']);
00170         $tot_cred=bcadd($tot_deb,$row['cred_montant']);
00171         /* -------------------------------------- */
00172         /* if details are asked we show them here */
00173         /* -------------------------------------- */
00174         if ( isset($_GET['oper_detail']))
00175         {
00176             $detail=new Acc_Operation($cn);
00177             $detail->jr_id=$row['jr_id'];
00178             $a_detail=$detail->get_jrnx_detail();
00179             for ($f=0;$f<count($a_detail);$f++)
00180             {
00181                 $l=0;
00182                 $pdf->Cell($size[$l],6,'',0,0,$align[$l]);
00183                 $l++;
00184                 $pdf->Cell($size[$l],6,$a_detail[$f]['j_qcode'],0,0,$align[$l]);
00185                 $l++;
00186                 $pdf->Cell($size[$l],6,$a_detail[$f]['j_poste'],0,0,$align[$l]);
00187                 $l++;
00188                 if ( $a_detail[$f]['j_qcode']=='')
00189                     $lib=$a_detail[$f]['pcm_lib'];
00190                 else
00191                 {
00192                     $f_id=$cn->get_value('select f_id from vw_poste_qcode where j_qcode=$1',array($a_detail[$f]['j_qcode'])) ;
00193                     $lib=$cn->get_value('select ad_value from fiche_detail where ad_id=$1 and f_id=$2',
00194                                         array(ATTR_DEF_NAME,$f_id));
00195                 }
00196                 $pdf->Cell($size[$l],6,$lib,0,0,$align[$l]);
00197                 $l++;
00198                 $pdf->Cell($size[$l],6,(($a_detail[$f]['letter']!=-1)?$a_detail[$f]['letter']:''),0,0,$align[$l]);
00199                 $l++;
00200 
00201                 $deb=($a_detail[$f]['debit']=='D')?$a_detail[$f]['j_montant']:'';
00202                 $cred=($a_detail[$f]['debit']=='C')?$a_detail[$f]['j_montant']:'';
00203 
00204                 $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$deb)),0,0,$align[$l]);
00205                 $l++;
00206                 $pdf->Cell($size[$l],6,(sprintf('% 12.2f',$cred)),0,0,$align[$l]);
00207                 $l++;
00208                 $pdf->ln();
00209             }
00210         }
00211     }
00212     $str_debit=sprintf("% 12.2f €",$tot_deb);
00213     $str_credit=sprintf("% 12.2f €",$tot_cred);
00214     $diff_solde=$tot_deb-$tot_cred;
00215     if ( $diff_solde < 0 )
00216     {
00217         $solde=" créditeur ";
00218         $diff_solde=bcmul($diff_solde,-1);
00219     }
00220     else
00221     {
00222         $solde=" débiteur ";
00223     }
00224     $str_diff_solde=sprintf("%12.2f €",$diff_solde);
00225 
00226     $pdf->SetFont('DejaVu','B',8);
00227 
00228     $pdf->Cell(160,5,'Débit',0,0,'R');
00229     $pdf->Cell(30,5,$str_debit,0,0,'R');
00230     $pdf->Ln();
00231     $pdf->Cell(160,5,'Crédit',0,0,'R');
00232     $pdf->Cell(30,5,$str_credit,0,0,'R');
00233     $pdf->Ln();
00234     $pdf->Cell(160,5,'Solde '.$solde,0,0,'R');
00235     $pdf->Cell(30,5,$str_diff_solde,0,0,'R');
00236     $pdf->Ln();
00237 
00238 }
00239 $fDate=date('dmy-Hi');
00240 $pdf->Output('poste-'.$fDate.'-'.$poste_id.'.pdf','D');
00241 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations