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
00026 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
00027
00028 require_once('class_user.php');
00029 require_once('class_database.php');
00030 require_once('class_pdf.php');
00031 require_once('class_lettering.php');
00032 require_once('class_dossier.php');
00033 require_once('ac_common.php');
00034
00035
00036 $gDossier=dossier::id();
00037 $cn=new Database($gDossier);
00038 $g_user->Check();
00039 $g_user->check_dossier($gDossier);
00040
00041 $pdf=new PDF($cn);
00042 $pdf->setDossierInfo(" Periode : ".$_GET['start']." - ".$_GET['end']);
00043 $pdf->AliasNbPages();
00044 $pdf->AddPage();
00045 $name=$cn->get_value('select fd_label from fiche_def where fd_id=$1',array($_GET['cat']));
00046 $pdf->SetFont('DejaVu','BI',14);
00047 $pdf->Cell(0,8,$name,0,1,'C');
00048 $pdf->SetTitle($name,1);
00049 $pdf->SetAuthor('NOALYSS');
00050
00051 if ( $_GET['histo'] == 4 )
00052 {
00053 $fd=new Fiche_Def($cn,$_REQUEST['cat']);
00054 if ( $fd->hasAttribute(ATTR_DEF_ACCOUNT) == false )
00055 {
00056 $pdf->Cell(0,10, "Cette catégorie n'ayant pas de poste comptable n'a pas de balance");
00057
00058 $fDate=date('dmy-Hi');
00059 $pdf->Output("category-$fDate.pdf", 'D');
00060 exit;
00061 }
00062 $aCard=$cn->get_array("select f_id,ad_value from fiche join fiche_Detail using (f_id) where ad_id=1 and fd_id=$1 order by 2 ",array($_REQUEST['cat']));
00063
00064 if ( empty($aCard))
00065 {
00066 $pdf->Cell(0,10, "Aucune fiche trouvée");
00067 $fDate=date('dmy-Hi');
00068 $pdf->Output("category-$fDate.pdf", 'D');
00069 exit;
00070 }
00071 $pdf->SetFont('DejaVuCond','',7);
00072 $pdf->Cell(30,7,'Quick Code',0,0,'L',0);
00073 $pdf->Cell(80,7,'Libellé',0,0,'L',0);
00074 $pdf->Cell(20,7,'Débit',0,0,'R',0);
00075 $pdf->Cell(20,7,'Crédit',0,0,'R',0);
00076 $pdf->Cell(20,7,'Solde',0,0,'R',0);
00077 $pdf->Cell(20,7,'D/C',0,0,'C',0);
00078 $pdf->Ln();
00079 $idx=0;
00080 for ($i=0;$i < count($aCard);$i++)
00081 {
00082 if ( isDate($_REQUEST['start']) == null || isDate ($_REQUEST['end']) == null ) exit;
00083 $filter= " (j_date >= to_date('".$_REQUEST['start']."','DD.MM.YYYY') ".
00084 " and j_date <= to_date('".$_REQUEST['end']."','DD.MM.YYYY')) ";
00085 $oCard=new Fiche($cn,$aCard[$i]['f_id']);
00086 $solde=$oCard->get_solde_detail($filter);
00087 if ( $solde['debit'] == 0 && $solde['credit']==0) continue;
00088
00089 if ( $idx % 2 == 0 )
00090 {
00091 $pdf->SetFillColor(220,221,255);
00092 $fill=1;
00093 }
00094 else
00095 {
00096 $pdf->SetFillColor(0,0,0);
00097 $fill=0;
00098 }
00099 $idx++;
00100
00101 $pdf->Cell(30,7,$oCard->strAttribut(ATTR_DEF_QUICKCODE),0,0,'L',$fill);
00102 $pdf->Cell(80,7,$oCard->strAttribut(ATTR_DEF_NAME),0,0,'L',$fill);
00103 $pdf->Cell(20,7,sprintf('%.02f',$solde['debit']),0,0,'R',$fill);
00104 $pdf->Cell(20,7,sprintf('%.02f',$solde['credit']),0,0,'R',$fill);
00105 $pdf->Cell(20,7,sprintf('%.02f',abs($solde['solde'])),0,0,'R',$fill);
00106 $pdf->Cell(20,7,(($solde['solde']<0)?'CRED':'DEB'),0,0,'C',$fill);
00107 $pdf->Ln();
00108 }
00109 }
00110 else
00111 {
00112 $array=Fiche::get_fiche_def($cn,$_GET['cat'],'name_asc');
00113
00114
00115
00116 if ($array == null )
00117 {
00118 exit();
00119 }
00120 $tab=array(13,25,55,20,20,12,20);
00121 $align=array('L','L','L','R','R','R','R');
00122
00123 foreach($array as $row_fiche)
00124 {
00125 $row=new Fiche($cn,$row_fiche['f_id']);
00126 $letter=new Lettering_Card($cn);
00127 $letter->set_parameter('quick_code',$row->strAttribut(ATTR_DEF_QUICKCODE));
00128 $letter->set_parameter('start',$_GET['start']);
00129 $letter->set_parameter('end',$_GET['end']);
00130
00131 if ( $_GET['histo'] == 0 )
00132 {
00133 $letter->get_all();
00134 }
00135
00136
00137 if ( $_GET['histo'] == 1 )
00138 {
00139 $letter->get_letter();
00140 }
00141
00142 if ( $_GET['histo'] == 2 )
00143 {
00144 $letter->get_unletter();
00145 }
00146
00147 if (count($letter->content) == 0 ) continue;
00148 $pdf->SetFont('DejaVuCond','',10);
00149 $fiche=new Fiche($cn,$row_fiche['f_id']);
00150 $pdf->Cell(0,7,$fiche->strAttribut(ATTR_DEF_NAME),1,1,'C');
00151
00152 $pdf->SetFont('DejaVuCond','',7);
00153
00154 $pdf->Cell($tab[0],7,'Date');
00155 $pdf->Cell($tab[1],7,'ref');
00156 $pdf->Cell($tab[1],7,'Int.');
00157 $pdf->Cell($tab[2],7,'Comm');
00158 $pdf->Cell(40,7,'Montant',0,0,'C');
00159 $pdf->Cell($tab[5],7,'Let.',0,0,'R');
00160 $pdf->Cell($tab[6],7,'Som. Let.',0,0,'R');
00161 $pdf->ln();
00162
00163 $amount_deb=0;
00164 $amount_cred=0;
00165 for ($i=0;$i<count($letter->content);$i++)
00166 {
00167 if ( $i % 2 == 0 )
00168 {
00169 $pdf->SetFillColor(220,221,255);
00170 $fill=1;
00171 }
00172 else
00173 {
00174 $pdf->SetFillColor(0,0,0);
00175 $fill=0;
00176 }
00177 $pdf->SetFont('DejaVuCond','',7);
00178 $row=$letter->content[$i];
00179 $str_date=shrink_date($row['j_date_fmt']);
00180
00181 $pdf->Cell($tab[0],4,$str_date,0,0,$align[0],$fill);
00182 $pdf->Cell($tab[1],4,$row['jr_pj_number'],0,0,$align[1],$fill);
00183 $pdf->Cell($tab[1],4,$row['jr_internal'],0,0,$align[1],$fill);
00184 $pdf->Cell($tab[2],4,$row['jr_comment'],0,0,$align[2],$fill);
00185 if ( $row['j_debit'] == 't')
00186 {
00187 $pdf->Cell($tab[3],4,sprintf('%10.2f',$row['j_montant']),0,0,$align[4],$fill);
00188 $amount_deb+=$row['j_montant'];
00189 $pdf->Cell($tab[4],4,"",0,0,'C',$fill);
00190 }
00191 else
00192 {
00193 $pdf->Cell($tab[3],4,"",0,0,'C',$fill);
00194 $pdf->Cell($tab[4],4,sprintf('%10.2f',$row['j_montant']),0,0,$align[4],$fill);
00195 $amount_cred+=$row['j_montant'];
00196 }
00197 if ($row['letter'] != -1 )
00198 {
00199 $pdf->Cell($tab[5],4,strtoupper(base_convert($row['letter'],10,36)),0,0,$align[5],$fill);
00200
00201 $sql="select sum(j_montant) from jrnx where j_debit=$1 and j_id in ".
00202 " (select j_id from jnt_letter join letter_deb using (jl_id) where jl_id=$2 union ".
00203 " select j_id from jnt_letter join letter_cred using (jl_id) where jl_id=$3)";
00204 $sum=$cn->get_value($sql,array($row['j_debit'],$row['letter'],$row['letter']));
00205 $pdf->Cell($tab[6],4,sprintf('%.2f',$sum),'0','0','R',$fill);
00206 }
00207 else
00208 $pdf->Cell($tab[5],4,"",0,0,'R',$fill);
00209 $pdf->Ln();
00210 }
00211 $pdf->SetFillColor(0,0,0);
00212 $pdf->SetFont('DejaVuCond','B',8);
00213 $debit =sprintf('Debit : % 12.2f',$amount_deb);
00214 $credit=sprintf('Credit : % 12.2f',$amount_cred);
00215 if ( $amount_deb>$amount_cred) $s='solde débiteur';
00216 else $s='solde crediteur';
00217 $solde =sprintf('%s : % 12.2f',$s,(abs(round($amount_cred-$amount_deb,2))));
00218
00219 $pdf->Cell(0,6,$debit,0,0,'R');
00220 $pdf->ln(4);
00221 $pdf->Cell(0,6,$credit,0,0,'R');
00222 $pdf->ln(4);
00223 $pdf->Cell(0,6,$solde,0,0,'R');
00224 $pdf->ln(4);
00225
00226 $pdf->Ln();
00227 }
00228 }
00229
00230 $fDate=date('dmy-Hi');
00231 $pdf->Output("category-$fDate.pdf", 'D');
00232 exit;