[ Index ] |
|
Code source de vtiger CRM 5.0.2 |
1 <?php 2 require ('include/fpdf/fpdf.php'); 3 // Xavier Nicolay 2004 4 // Version 1.01 5 class PDF extends FPDF 6 { 7 // private variables 8 var $columns; 9 var $format; 10 var $angle=0; 11 12 // private functions 13 function RoundedRect($x, $y, $w, $h, $r, $style = '') 14 { 15 $k = $this->k; 16 $hp = $this->h; 17 if($style=='F') 18 $op='f'; 19 elseif($style=='FD' or $style=='DF') 20 $op='B'; 21 else 22 $op='S'; 23 $MyArc = 4/3 * (sqrt(2) - 1); 24 $this->_out(sprintf('%.2f %.2f m',($x+$r)*$k,($hp-$y)*$k )); 25 $xc = $x+$w-$r ; 26 $yc = $y+$r; 27 $this->_out(sprintf('%.2f %.2f l', $xc*$k,($hp-$y)*$k )); 28 29 $this->_Arc($xc + $r*$MyArc, $yc - $r, $xc + $r, $yc - $r*$MyArc, $xc + $r, $yc); 30 $xc = $x+$w-$r ; 31 $yc = $y+$h-$r; 32 $this->_out(sprintf('%.2f %.2f l',($x+$w)*$k,($hp-$yc)*$k)); 33 $this->_Arc($xc + $r, $yc + $r*$MyArc, $xc + $r*$MyArc, $yc + $r, $xc, $yc + $r); 34 $xc = $x+$r ; 35 $yc = $y+$h-$r; 36 $this->_out(sprintf('%.2f %.2f l',$xc*$k,($hp-($y+$h))*$k)); 37 $this->_Arc($xc - $r*$MyArc, $yc + $r, $xc - $r, $yc + $r*$MyArc, $xc - $r, $yc); 38 $xc = $x+$r ; 39 $yc = $y+$r; 40 $this->_out(sprintf('%.2f %.2f l',($x)*$k,($hp-$yc)*$k )); 41 $this->_Arc($xc - $r, $yc - $r*$MyArc, $xc - $r*$MyArc, $yc - $r, $xc, $yc - $r); 42 $this->_out($op); 43 } 44 45 function _Arc($x1, $y1, $x2, $y2, $x3, $y3) 46 { 47 $h = $this->h; 48 $this->_out(sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c ', $x1*$this->k, ($h-$y1)*$this->k, 49 $x2*$this->k, ($h-$y2)*$this->k, $x3*$this->k, ($h-$y3)*$this->k)); 50 } 51 52 function Rotate($angle,$x=-1,$y=-1) 53 { 54 if($x==-1) 55 $x=$this->x; 56 if($y==-1) 57 $y=$this->y; 58 if($this->angle!=0) 59 $this->_out('Q'); 60 $this->angle=$angle; 61 if($angle!=0) 62 { 63 $angle*=M_PI/180; 64 $c=cos($angle); 65 $s=sin($angle); 66 $cx=$x*$this->k; 67 $cy=($this->h-$y)*$this->k; 68 $this->_out(sprintf('q %.5f %.5f %.5f %.5f %.2f %.2f cm 1 0 0 1 %.2f %.2f cm',$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy)); 69 } 70 } 71 72 function _endpage() 73 { 74 if($this->angle!=0) 75 { 76 $this->angle=0; 77 $this->_out('Q'); 78 } 79 parent::_endpage(); 80 } 81 82 // public functions 83 function sizeOfText( $text, $largeur ) 84 { 85 $index = 0; 86 $nb_lines = 0; 87 $loop = TRUE; 88 while ( $loop ) 89 { 90 $pos = strpos($text, "\n"); 91 if (!$pos) 92 { 93 $loop = FALSE; 94 $line = $text; 95 } 96 else 97 { 98 $line = substr( $text, $index, $pos); 99 $text = substr( $text, $pos+1 ); 100 } 101 $length = floor( $this->GetStringWidth( $line ) ); 102 $res = 1 + floor( $length / $largeur) ; 103 $nb_lines += $res; 104 } 105 return $nb_lines; 106 } 107 108 // addImage 109 // Default will place vtiger in the top left corner 110 function addImage( $logo_name, $location=array('10','10','0','0') ) { 111 if($logo_name)//error checking just in case, by OpenCRM 112 { 113 $x1 = $location[0]; 114 $y1 = $location[1]; 115 $stretchx = $location[2]; 116 $stretchy = $location[3]; 117 $this->Image('test/logo/'.$logo_name,$x1,$y1,$stretchx,$stretchy); 118 } 119 } 120 121 // Company 122 function addCompany( $nom, $address, $location='' ) 123 { 124 $x1 = $location[0]; 125 $y1 = $location[1]; 126 //Positionnement en bas 127 $this->SetXY( $x1, $y1 ); 128 $this->SetFont('Arial','B',12); 129 $length = $this->GetStringWidth( $nom ); 130 $this->Cell( $length, 2, $nom); 131 $this->SetXY( $x1, $y1 + 4 ); 132 $this->SetFont('Arial','',10); 133 $length = $this->GetStringWidth( $address ); 134 //Coordonnées de la société 135 $lines = $this->sizeOfText( $address, $length) ; 136 $this->MultiCell($length, 4, $address); 137 } 138 139 // bubble blocks 140 function title ($label, $total, $position) 141 { 142 $r1 = $position[0]; 143 $r2 = $r1 + 19 + $position[2] ; 144 $y1 = $position[1]; 145 $y2 = $y1; 146 $mid = $y1 + ($y2 / 2); 147 $width=10; 148 $this->SetFillColor(192); 149 $this->RoundedRect($r1-16, $y1-1, 52, $y2+1, 2.5, 'DF'); 150 $this->SetXY( $r1 + 4, $y1+1 ); 151 $this->SetFont( "Helvetica", "B", 15); 152 $this->Cell($width,5, $label." ".$total, 0, 0, "C"); 153 } 154 155 // text block, non-wrapped 156 function addTextBlock( $title,$text,$positions ) 157 { 158 $r1 = $positions[0]; 159 $y1 = $positions[1]; 160 $this->SetXY( $r1, $y1); 161 $this->SetFont( "Helvetica", "B", 10); 162 $this->Cell( $positions[2], 4,$title); 163 $this->SetXY( $r1, $y1+4); 164 $this->SetFont( "Helvetica", "", 10); 165 $this->MultiCell( $positions[2], 4, $text); 166 } 167 168 function tableWrapper($position) 169 { 170 $r1 = $position[0]; 171 $r2 = $r1 + 19 + $position[2] ; 172 $y1 = $position[1]; 173 if($position[3]) 174 $y2 = $position[3]; 175 else 176 $y2 = 17; 177 178 $mid = $y1 + (13 / 2); 179 $width=10; 180 $this->RoundedRect($r1, $y1, ($r2 - $r1), $y2, 4.5, 'D'); 181 $this->Line( $r1, $mid, $r2, $mid); 182 $this->SetXY( $r1 + ($r2-$r1)/2 - 3, $y1+3 ); 183 $this->SetXY( $r1 + ($r2-$r1)/2 - 5, $y1 + 9 ); 184 } 185 186 function addBubble($page,$title,$position) 187 { 188 $r1 = $position[0]; 189 $r2 = $r1 + 19 + $position[2] ; 190 $y1 = $position[1]; 191 if($position[3]) 192 $y2 = 17*$position[3]; 193 else 194 $y2 = 17; 195 196 $mid = $y1 + (19 / 2); 197 $width=10; 198 $this->RoundedRect($r1, $y1, ($r2 - $r1), $y2, 4.5, 'D'); 199 $this->Line( $r1, $mid, $r2, $mid); 200 $this->SetXY( $r1 + ($r2-$r1)/2 - 3, $y1+3 ); 201 $this->SetFont( "Helvetica", "B", 10); 202 $this->Cell($width,5, $title, 0, 0, "C"); 203 $this->SetXY( $r1 + ($r2-$r1)/2 - 5, $y1 + 9 ); 204 $this->SetFont( "Helvetica", "", 10); 205 $this->MultiCell($width,5,$page, 0,0, "C"); 206 } 207 208 // bubble blocks 209 function addBubbleBlock ($page, $title, $position) 210 { 211 $r1 = $position[0]; 212 $r2 = $r1 + 19 + $position[2] ; 213 $y1 = $position[1]; 214 $y2 = 17; 215 216 $mid = $y1 + ($y2 / 2); 217 $width=10; 218 $this->RoundedRect($r1, $y1, ($r2 - $r1), $y2, 4.5, 'D'); 219 $this->Line( $r1, $mid, $r2, $mid); 220 $this->SetXY( $r1 + ($r2-$r1)/2 - 5, $y1+3 ); 221 $this->SetFont( "Helvetica", "B", 10); 222 $this->Cell($width,5, $title, 0, 0, "C"); 223 $this->SetXY( $r1 + ($r2-$r1)/2 - 5, $y1 + 9 ); 224 $this->SetFont( "Helvetica", "", 10); 225 $this->Cell($width,5,$page, 0,0, "C"); 226 } 227 228 // record blocks 229 function addRecBlock( $data, $title, $postion ) 230 { 231 $lengthtitle = strlen($title); 232 $lengthdata = strlen($data); 233 $length=$lengthtitle; 234 $r1 = $postion[0]; 235 $r2 = $r1 + 40 + $length; 236 $y1 = $postion[1]; 237 $y2 = $y1+10; 238 $mid = $y1 + (($y2-$y1) / 2); 239 240 $this->RoundedRect($r1, $y1, ($r2 - $r1), ($y2-$y1), 2.5, 'D'); 241 $this->Line( $r1, $mid, $r2, $mid); 242 $this->SetXY( $r1 + ($r2-$r1)/2 -5 , $y1+1 ); 243 $this->SetFont( "Helvetica", "B", 10); 244 $this->Cell(10,4, $title, 0, 0, "C"); 245 $this->SetXY( $r1 + ($r2-$r1)/2 -5 , $y1 + 5 ); 246 $this->SetFont( "Helvetica", "", 10); 247 $this->Cell(10,4,$data, 0, 0, "C"); 248 } 249 250 // description blocks 251 function addDescBlock( $data, $title, $position ) 252 { 253 $lengthtitle = strlen($title); 254 $lengthdata= $position[3]; 255 256 $length=$position[2]; 257 $r1 = $position[0]; 258 $r2 = $r1 + 40 + $length; 259 $y1 = $position[1]; 260 $y2 = $y1+10; 261 $mid = $y1 + (($y2-$y1) / 2); 262 263 $this->RoundedRect($r1,$y1, ($length + 40), ($lengthdata/140*30), 2.5, 'D'); 264 $this->Line( $r1, $mid, $r2, $mid); 265 266 $this->SetXY( $position[0]+2 , $y1 + 1 ); 267 $this->SetFont( "Helvetica", "B", 10); 268 $this->Cell(10,4, $title); 269 270 $this->SetXY( $position[0]+2 , $y1 + 6 ); 271 $this->SetFont( "Helvetica", "", 10); 272 $this->MultiCell(($length+36),4,$data); 273 } 274 275 function drawLine($positions) 276 { 277 $x=$positions[0]; 278 $y=$positions[1]; 279 $width=$positions[2]; 280 $this->Line( $x, $y, $x+$width, $y); 281 } 282 283 // add columns to table 284 function addCols( $tab ,$positions ,$bottom, $taxtype = 'group') 285 { 286 global $columns; 287 288 $r1 = 10; 289 $r2 = $this->w - ($r1 * 2) ; 290 $y1 = 80; 291 $x1 = $positions[1]; 292 $y2 = $bottom; 293 $this->SetXY( $r1, $y1 ); 294 $this->SetFont( "Helvetica", "", 10); 295 296 $colX = $r1; 297 $columns = $tab; 298 while ( list( $lib, $pos ) = each ($tab) ) 299 { 300 $this->SetXY( $colX, $y1+3 ); 301 $this->Cell( $pos, 1, $lib, 0, 0, "C"); 302 $colX += $pos; 303 switch($lib) { 304 case 'Total': 305 break; 306 case 'Qty': 307 case 'Price': 308 if($taxtype == "individual") 309 $this->Line( $colX, $y1, $colX, (($y1+$y2)-37)); 310 else 311 $this->Line( $colX, $y1, $colX, (($y1+$y2)-43)); 312 break; 313 default: 314 if($taxtype == "individual" && $lib == 'Discount') 315 $this->Line( $colX, $y1, $colX, (($y1+$y2)-37)); 316 else 317 $this->Line( $colX, $y1, $colX, ($y1+$y2)); 318 break; 319 } 320 } 321 } 322 323 function addLineFormat( $tab ) 324 { 325 global $format, $columns; 326 327 while ( list( $lib, $pos ) = each ($columns) ) 328 { 329 if ( isset( $tab["$lib"] ) ) 330 $format[ $lib ] = $tab["$lib"]; 331 } 332 } 333 334 function addProductLine( $line, $tab, $totals='' ) 335 { 336 global $columns, $format; 337 338 $ordonnee = 10; 339 $maxSize = $line; 340 341 reset( $columns ); 342 while ( list( $lib, $pos ) = each ($columns) ) 343 { 344 $longCell = $pos -2; 345 $text = $tab[ $lib ]; 346 $length = $this->GetStringWidth( $text ); 347 $formText = $format[ $lib ]; 348 $this->SetXY( $ordonnee, $line); 349 $this->MultiCell( $longCell, 3 , $text, 3, $formText); 350 if ( $maxSize < ($this->GetY() ) ) 351 $maxSize = $this->GetY() ; 352 $ordonnee += $pos; 353 } 354 return ( $maxSize - $line ); 355 } 356 357 function addTotalsRec($names, $totals, $positions) 358 { 359 $this->SetFont( "Arial", "B", 8); 360 $r1 = $positions[0]; 361 $r2 = $r1 + 90; 362 $y1 = $positions[1]; 363 $y2 = $y1+10; 364 $this->RoundedRect($r1, $y1, ($r2 - $r1), ($y2-$y1), 2.5, 'D'); 365 $this->Line( $r1, $y1+4, $r2, $y1+4); 366 $this->Line( $r1+27, $y1, $r1+27, $y2); // avant Subtotal 367 $this->Line( $r1+43, $y1, $r1+43, $y2); // avant Tax 368 $this->Line( $r1+66, $y1, $r1+66, $y2); // avant Adjustment 369 370 $this->SetXY( $r1+2, $y1); 371 $this->Cell(10,4, $names[0]); 372 $this->SetX( $r1+29,$y1 ); 373 $this->Cell(10,4, $names[1]); 374 $this->SetX( $r1+45 ); 375 $this->Cell(10,4, $names[2]); 376 $this->SetX( $r1+66 ); 377 $this->Cell(10,4, $names[3]); 378 379 380 $this->SetXY( $r1+2, $y1+5 ); 381 $this->Cell( 10,4, $totals[0] ); 382 $this->SetXY( $r1+29, $y1+5 ); 383 $this->Cell( 10,4, $totals[1] ); 384 $this->SetXY( $r1+44, $y1+5 ); 385 $this->Cell( 10,4, $totals[2] ); 386 $this->SetXY( $r1+66, $y1+5 ); 387 $this->Cell( 10,4, $totals[3] ); 388 389 $this->SetFont( "Arial", "B", 6); 390 $this->SetXY( $r1+90, $y2 - 8 ); 391 $this->SetFont( "Helvetica", "", 10); 392 } 393 394 // add a watermark (temporary estimate, DUPLICATA...) 395 // call this method first 396 function watermark( $text, $positions, $rotate = array('45','50','180') ) 397 { 398 $this->SetFont('Arial','B',50); 399 $this->SetTextColor(230,230,230); 400 $this->Rotate($rotate[0],$rotate[1],$rotate[2]); 401 $this->Text($positions[0],$positions[1],$text); 402 $this->Rotate(0); 403 $this->SetTextColor(0,0,0); 404 } 405 406 } 407 function StripLastZero($string) 408 { 409 $count=strlen($string); 410 $ret=substr($string,0,($count-1)); 411 return $ret; 412 } 413 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 10:22:19 2007 | par Balluche grâce à PHPXref 0.7 |