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 $name=$cn->get_value('select fd_label from fiche_def where fd_id=$1',array($_GET['cat']));
00041
00042 $pdf=new PDF($cn);
00043 $pdf->setDossierInfo(" Periode : ".$_GET['start']." - ".$_GET['end']);
00044 $pdf->AliasNbPages();
00045 $pdf->AddPage();
00046
00047 $pdf->SetTitle($name,1);
00048 $pdf->SetAuthor('NOALYSS');
00049
00050 $allcard=(isset($_GET['allcard']))?1:0;
00051
00052
00053
00054 if ( $_GET['histo'] == 4 || $_GET['histo']==5)
00055 {
00056 $fd=new Fiche_Def($cn,$_REQUEST['cat']);
00057 if ($allcard==1 && $fd->hasAttribute(ATTR_DEF_ACCOUNT) == false )
00058 {
00059 $pdf->Cell(0,10, "Cette catégorie n'ayant pas de poste comptable n'a pas de balance");
00060
00061 $fDate=date('dmy-Hi');
00062 $pdf->Output("category-$fDate.pdf", 'D');
00063 exit;
00064 }
00065
00066 if ($allcard==1)
00067 {
00068 $afiche=$cn->get_array("select fd_id from vw_fiche_def where ad_id=".ATTR_DEF_ACCOUNT." order by fd_label asc");
00069 }
00070 else
00071 {
00072 $afiche[0]=array('fd_id'=>$_REQUEST['cat']);
00073 }
00074
00075 if ( $allcard==0 && empty($afiche))
00076 {
00077 $pdf->Cell(0,10, "Aucune fiche trouvée");
00078 $fDate=date('dmy-Hi');
00079 $pdf->Output("category-$fDate.pdf", 'D');
00080 exit;
00081 }
00082 for ($e = 0; $e < count($afiche); $e++)
00083 {
00084 $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($afiche[$e]['fd_id']));
00085 $name=$cn->get_value('select fd_label from fiche_def where fd_id=$1',array($afiche[$e]['fd_id']));
00086 $pdf->SetFont('DejaVu','BI',14);
00087 $pdf->Cell(0,8,$name,0,1,'C');
00088
00089 $pdf->SetFont('DejaVuCond','',7);
00090 $pdf->LongLine(30,7,'Quick Code',0,'L',0);
00091 $pdf->LongLine(80,7,'Libellé',0,'L',0);
00092 $pdf->Cell(20,7,'Débit',0,0,'R',0);
00093 $pdf->Cell(20,7,'Crédit',0,0,'R',0);
00094 $pdf->Cell(20,7,'Solde',0,0,'R',0);
00095 $pdf->Cell(20,7,'D/C',0,0,'C',0);
00096 $pdf->Ln();
00097
00098 if (empty($aCard)) continue;
00099
00100
00101 $idx=0;$sum_deb=0;$sum_cred=0;bcscale(4);
00102 for ($i=0;$i < count($aCard);$i++)
00103 {
00104 if ( isDate($_REQUEST['start']) == null || isDate ($_REQUEST['end']) == null ) exit;
00105 $filter= " (j_date >= to_date('".$_REQUEST['start']."','DD.MM.YYYY') ".
00106 " and j_date <= to_date('".$_REQUEST['end']."','DD.MM.YYYY')) ";
00107 $oCard=new Fiche($cn,$aCard[$i]['f_id']);
00108 $solde=$oCard->get_solde_detail($filter);
00109 if ( $solde['debit'] == 0 && $solde['credit']==0) continue;
00110
00111 if ($_GET['histo'] == 5 && $solde['debit'] == $solde['credit']) continue;
00112
00113 if ( $idx % 2 == 0 )
00114 {
00115 $pdf->SetFillColor(220,221,255);
00116 $fill=1;
00117 }
00118 else
00119 {
00120 $pdf->SetFillColor(0,0,0);
00121 $fill=0;
00122 }
00123 $idx++;
00124 $side='';
00125 if(bcsub($solde['credit'],$solde['debit']) < 0) $side='Deb.';
00126 if(bcsub($solde['credit'],$solde['debit']) > 0) $side='Cred.';
00127
00128 $sum_cred=bcadd($sum_cred,$solde['credit']);
00129 $sum_deb=bcadd($sum_deb,$solde['debit']);
00130 $sum_solde=bcsub($sum_deb,$sum_cred);
00131
00132 $pdf->Cell(30,7,$oCard->strAttribut(ATTR_DEF_QUICKCODE),0,0,'L',$fill);
00133 $pdf->LongLine(80,7,$oCard->strAttribut(ATTR_DEF_NAME)." (".$oCard->strAttribut(ATTR_DEF_ACCOUNT).")",0,'L',$fill);
00134 $pdf->Cell(20,7,nbm($solde['debit']),0,0,'R',$fill);
00135 $pdf->Cell(20,7,nbm($solde['credit']),0,0,'R',$fill);
00136 $pdf->Cell(20,7,nbm(abs($solde['solde'])),0,0,'R',$fill);
00137 $pdf->Cell(20,7,$side,0,0,'C',$fill);
00138 $pdf->Ln();
00139 }
00140 if ( $idx % 2 == 0 )
00141 {
00142 $pdf->SetFillColor(220,221,255);
00143 $fill=1;
00144 }
00145 else
00146 {
00147 $pdf->SetFillColor(0,0,0);
00148 $fill=0;
00149 }
00150 $idx++;
00151
00152 $pdf->Cell(30,7,"",0,0,'L',$fill);
00153 $pdf->Cell(80,7,_("Totaux"),0,0,'L',$fill);
00154 $pdf->Cell(20,7,nbm($sum_deb),0,0,'R',$fill);
00155 $pdf->Cell(20,7,nbm($sum_cred),0,0,'R',$fill);
00156 $pdf->Cell(20,7,nbm(abs($sum_solde)),0,0,'R',$fill);
00157 $side=" = ";
00158 if ( $sum_solde > 0 )
00159 {
00160 $side='Deb.';
00161 }
00162 else if ( $sum_solde < 0)
00163 {
00164 $side='Cred.';
00165 }
00166
00167 $pdf->Cell(20,7,$side,0,0,'C',$fill);
00168 $pdf->Ln();
00169 }
00170 }
00171 else
00172 {
00173
00174
00175 if ($allcard == 1)
00176 {
00177 $afiche = $cn->get_array("select fd_id from vw_fiche_def where ad_id=" . ATTR_DEF_ACCOUNT . " order by fd_label asc");
00178 }
00179 else
00180 {
00181 $afiche[0] = array('fd_id' => $_REQUEST['cat']);
00182 }
00183 $fic=new Fiche($cn);
00184 for ($e = 0; $e < count($afiche); $e++)
00185 {
00186 $array = Fiche::get_fiche_def($cn,$afiche[$e]['fd_id'] , 'name_asc');
00187
00188
00189
00190 if ($array == null)
00191 {
00192 continue;
00193 }
00194 $tab = array(12, 20, 20,68, 20, 20, 10, 20);
00195 $align = array('L', 'C', 'L', 'L', 'R','R', 'R', 'R');
00196
00197 foreach ($array as $row_fiche)
00198 {
00199 $fic = new Fiche($cn, $row_fiche['f_id']);
00200 $letter = new Lettering_Card($cn);
00201 $letter->set_parameter('quick_code', $fic->strAttribut(ATTR_DEF_QUICKCODE));
00202 $letter->set_parameter('start', $_GET['start']);
00203 $letter->set_parameter('end', $_GET['end']);
00204
00205 if ($_GET['histo'] == 0)
00206 {
00207 $letter->get_all();
00208 }
00209
00210
00211 if ($_GET['histo'] == 1)
00212 {
00213 $letter->get_letter();
00214 }
00215
00216 if ($_GET['histo'] == 2)
00217 {
00218 $letter->get_unletter();
00219 }
00220 if ($_GET['histo'] == 6)
00221 {
00222 $letter->get_letter_diff();
00223 }
00224
00225 if (count($letter->content) == 0)
00226 continue;
00227 $pdf->SetFont('DejaVuCond', '', 10);
00228 $fiche = new Fiche($cn, $row_fiche['f_id']);
00229 $pdf->Cell(0, 7, $fiche->strAttribut(ATTR_DEF_NAME)." [".$fiche->strAttribut(ATTR_DEF_QUICKCODE).":".$fiche->strAttribut(ATTR_DEF_ACCOUNT)."]", 1, 'C');
00230
00231 $pdf->SetFont('DejaVuCond', '', 7);
00232 $pdf->Ln();
00233 $pdf->Cell($tab[0], 7, 'Date');
00234 $pdf->Cell($tab[1], 7, 'ref');
00235 $pdf->Cell($tab[2], 7, 'Internal');
00236 $pdf->Cell($tab[3], 7, 'Comm');
00237 $pdf->Cell($tab[4], 7, 'Montant', 0, 0, 'C');
00238 $pdf->Cell($tab[5], 7, 'Prog.', 0, 0, 'R');
00239 $pdf->Cell($tab[6], 7, 'Let.', 0, 0, 'R');
00240 $pdf->Cell($tab[7], 7, 'Diff. Let.', 0, 0, 'R');
00241 $pdf->ln();
00242
00243 $amount_deb = 0;
00244 $amount_cred = 0;
00245 $prog=0;
00246 for ($i = 0; $i < count($letter->content); $i++)
00247 {
00248 if ($i % 2 == 0)
00249 {
00250 $pdf->SetFillColor(220, 221, 255);
00251 $fill = 1;
00252 }
00253 else
00254 {
00255 $pdf->SetFillColor(0, 0, 0);
00256 $fill = 0;
00257 }
00258 $pdf->SetFont('DejaVuCond', '', 7);
00259 $row = $letter->content[$i];
00260 $str_date = shrink_date($row['j_date_fmt']);
00261
00262 $pdf->LongLine($tab[0], 4, $str_date, 0, $align[0], $fill);
00263 $pdf->Cell($tab[1], 4, $row['jr_pj_number'], 0, 0, $align[1], $fill);
00264 $pdf->LongLine($tab[2], 4, $row['jr_internal'], 0, $align[1], $fill);
00265 $pdf->LongLine($tab[3], 4, $row['jr_comment'], 0, $align[2], $fill);
00266 if ($row['j_debit'] == 't')
00267 {
00268 $prog=bcadd($prog,$row['j_montant']);
00269 $pdf->Cell($tab[4], 4, sprintf('%s D', nbm($row['j_montant'])), 0, 0, $align[4], $fill);
00270 $amount_deb+=$row['j_montant'];
00271 $str_prog=sprintf("%s %s",nbm(abs($prog)),$fic->get_amount_side($prog));
00272 $pdf->Cell($tab[5], 4, $str_prog, 0, 0, $align[5], $fill);
00273 }
00274 else
00275 {
00276 $prog=bcsub($prog,$row['j_montant']);
00277 $pdf->Cell($tab[4], 4, sprintf('%s C', nbm($row['j_montant'])), 0, 0, $align[4], $fill);
00278 $amount_cred+=$row['j_montant'];
00279 $str_prog=sprintf("%s %s",nbm(abs($prog)),$fic->get_amount_side($prog));
00280 $pdf->Cell($tab[5], 4, $str_prog, 0, 0, $align[5], $fill);
00281 }
00282 if ($row['letter'] != -1)
00283 {
00284 $pdf->Cell($tab[6], 4, strtoupper(base_convert($row['letter'],10,36)), 0, 0, $align[6], $fill);
00285
00286
00287 $pdf->Cell($tab[7], 4, sprintf('%s', nbm($row['letter_diff'])), '0', '0', $align[7], $fill);
00288 }
00289 else
00290 $pdf->Cell($tab[6], 4, "", 0, 0, 'R', $fill);
00291 $pdf->Ln();
00292 }
00293 $pdf->SetFillColor(0, 0, 0);
00294 $pdf->SetFont('DejaVuCond', 'B', 8);
00295 $debit = sprintf('Debit : %s', nbm($amount_deb));
00296 $credit = sprintf('Credit : %s', nbm($amount_cred));
00297 if ($amount_deb > $amount_cred)
00298 $s = 'solde débiteur';
00299 else
00300 $s = 'solde crediteur';
00301 $solde = sprintf('%s : %s', $s, nbm(abs(round($amount_cred - $amount_deb, 2))));
00302
00303 $pdf->Cell(0, 6, $debit, 0, 0, 'R');
00304 $pdf->ln(4);
00305 $pdf->Cell(0, 6, $credit, 0, 0, 'R');
00306 $pdf->ln(4);
00307 $pdf->Cell(0, 6, $solde, 0, 0, 'R');
00308 $pdf->ln(4);
00309
00310 $pdf->Ln();
00311 }
00312 }
00313 }
00314
00315 $fDate=date('dmy-Hi');
00316 $pdf->Output("category-$fDate.pdf", 'D');
00317 exit;