| Conditions | 118 |
| Total Lines | 607 |
| Code Lines | 334 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 141 | function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) |
||
| 142 | { |
||
| 143 | global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes; |
||
| 144 | |||
| 145 | if (! is_object($outputlangs)) $outputlangs=$langs; |
||
| 146 | // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO |
||
| 147 | if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; |
||
| 148 | |||
| 149 | $outputlangs->load("main"); |
||
| 150 | $outputlangs->load("dict"); |
||
| 151 | $outputlangs->load("companies"); |
||
| 152 | $outputlangs->load("bills"); |
||
| 153 | $outputlangs->load("propal"); |
||
| 154 | $outputlangs->load("products"); |
||
| 155 | |||
| 156 | $nblignes = count($object->lines); |
||
| 157 | |||
| 158 | // Loop on each lines to detect if there is at least one image to show |
||
| 159 | $realpatharray=array(); |
||
| 160 | if (! empty($conf->global->MAIN_GENERATE_PROPOSALS_WITH_PICTURE)) |
||
| 161 | { |
||
| 162 | $objphoto = new Product($this->db); |
||
| 163 | |||
| 164 | for ($i = 0 ; $i < $nblignes ; $i++) |
||
| 165 | { |
||
| 166 | if (empty($object->lines[$i]->fk_product)) continue; |
||
| 167 | |||
| 168 | $objphoto->fetch($object->lines[$i]->fk_product); |
||
| 169 | |||
| 170 | if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) |
||
| 171 | { |
||
| 172 | $pdir[0] = get_exdir($objphoto->id,2) . $objphoto->id ."/photos/"; |
||
| 173 | $pdir[1] = dol_sanitizeFileName($objphoto->ref).'/'; |
||
| 174 | } |
||
| 175 | else |
||
| 176 | { |
||
| 177 | $pdir[0] = dol_sanitizeFileName($objphoto->ref).'/'; |
||
| 178 | $pdir[1] = get_exdir($objphoto->id,2) . $objphoto->id ."/photos/"; |
||
| 179 | } |
||
| 180 | |||
| 181 | $arephoto = false; |
||
| 182 | foreach ($pdir as $midir) |
||
| 183 | { |
||
| 184 | if (! $arephoto) |
||
| 185 | { |
||
| 186 | $dir = $conf->product->dir_output.'/'.$midir; |
||
| 187 | |||
| 188 | foreach ($objphoto->liste_photos($dir,1) as $key => $obj) |
||
| 189 | { |
||
| 190 | if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES)) // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo |
||
| 191 | { |
||
| 192 | if ($obj['photo_vignette']) |
||
| 193 | { |
||
| 194 | $filename= $obj['photo_vignette']; |
||
| 195 | } |
||
| 196 | else |
||
| 197 | { |
||
| 198 | $filename=$obj['photo']; |
||
| 199 | } |
||
| 200 | } |
||
| 201 | else |
||
| 202 | { |
||
| 203 | $filename=$obj['photo']; |
||
| 204 | } |
||
| 205 | |||
| 206 | $realpath = $dir.$filename; |
||
| 207 | $arephoto = true; |
||
| 208 | } |
||
| 209 | } |
||
| 210 | } |
||
| 211 | |||
| 212 | if ($realpath && $arephoto) $realpatharray[$i]=$realpath; |
||
| 213 | } |
||
| 214 | } |
||
| 215 | |||
| 216 | if (count($realpatharray) == 0) $this->posxpicture=$this->posxtva; |
||
| 217 | |||
| 218 | if ($conf->propal->dir_output) |
||
| 219 | { |
||
| 220 | $object->fetch_thirdparty(); |
||
| 221 | if(!empty($object->client) ){ |
||
| 222 | $object->thirdparty = $object->client; |
||
| 223 | } |
||
| 224 | // $deja_regle = 0; |
||
| 225 | |||
| 226 | // Definition of $dir and $file |
||
| 227 | if ($object->specimen) |
||
| 228 | { |
||
| 229 | $dir = $conf->propal->dir_output; |
||
| 230 | $file = $dir . "/SPECIMEN.pdf"; |
||
| 231 | } |
||
| 232 | else |
||
| 233 | { |
||
| 234 | $objectref = dol_sanitizeFileName($object->ref); |
||
| 235 | $dir = $conf->propal->dir_output . "/" . $objectref; |
||
| 236 | $file = $dir . "/" . $objectref . ".pdf"; |
||
| 237 | } |
||
| 238 | |||
| 239 | if (! file_exists($dir)) |
||
| 240 | { |
||
| 241 | if (dol_mkdir($dir) < 0) |
||
| 242 | { |
||
| 243 | $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
||
| 244 | return 0; |
||
| 245 | } |
||
| 246 | } |
||
| 247 | |||
| 248 | if (file_exists($dir)) |
||
| 249 | { |
||
| 250 | // Add pdfgeneration hook |
||
| 251 | if (! is_object($hookmanager)) |
||
| 252 | { |
||
| 253 | include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
||
| 254 | $hookmanager=new HookManager($this->db); |
||
| 255 | } |
||
| 256 | $hookmanager->initHooks(array('pdfgeneration')); |
||
| 257 | $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); |
||
| 258 | global $action; |
||
| 259 | $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
||
| 260 | |||
| 261 | // Create pdf instance |
||
| 262 | $pdf=pdf_getInstance($this->format); |
||
| 263 | $default_font_size = pdf_getPDFFontSize($outputlangs); // Must be after pdf_getInstance |
||
| 264 | $heightforinfotot = 50; // Height reserved to output the info and total part |
||
| 265 | $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5); // Height reserved to output the free text on last page |
||
| 266 | $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) |
||
| 267 | $pdf->SetAutoPageBreak(1,0); |
||
| 268 | |||
| 269 | if (class_exists('TCPDF')) |
||
| 270 | { |
||
| 271 | $pdf->setPrintHeader(false); |
||
| 272 | $pdf->setPrintFooter(false); |
||
| 273 | } |
||
| 274 | $pdf->SetFont(pdf_getPDFFont($outputlangs)); |
||
| 275 | // Set path to the background PDF File |
||
| 276 | if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) |
||
| 277 | { |
||
| 278 | $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); |
||
| 279 | $tplidx = $pdf->importPage(1); |
||
| 280 | } |
||
| 281 | |||
| 282 | $pdf->Open(); |
||
| 283 | $pagenb=0; |
||
| 284 | $pdf->SetDrawColor(128,128,128); |
||
| 285 | |||
| 286 | $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); |
||
| 287 | $pdf->SetSubject($outputlangs->transnoentities("CommercialProposal")); |
||
| 288 | $pdf->SetCreator("Dolibarr ".DOL_VERSION); |
||
| 289 | $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); |
||
| 290 | $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("CommercialProposal")); |
||
| 291 | if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); |
||
| 292 | |||
| 293 | $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right |
||
| 294 | |||
| 295 | // Positionne $this->atleastonediscount si on a au moins une remise |
||
| 296 | for ($i = 0 ; $i < $nblignes ; $i++) |
||
| 297 | { |
||
| 298 | if ($object->lines[$i]->remise_percent) |
||
| 299 | { |
||
| 300 | $this->atleastonediscount++; |
||
| 301 | } |
||
| 302 | } |
||
| 303 | if (empty($this->atleastonediscount)) |
||
| 304 | { |
||
| 305 | $this->posxpicture+=($this->postotalht - $this->posxdiscount); |
||
| 306 | $this->posxtva+=($this->postotalht - $this->posxdiscount); |
||
| 307 | $this->posxup+=($this->postotalht - $this->posxdiscount); |
||
| 308 | $this->posxqty+=($this->postotalht - $this->posxdiscount); |
||
| 309 | $this->posxdiscount+=($this->postotalht - $this->posxdiscount); |
||
| 310 | //$this->postotalht; |
||
| 311 | } |
||
| 312 | |||
| 313 | // New page |
||
| 314 | $pdf->AddPage(); |
||
| 315 | if (! empty($tplidx)) $pdf->useTemplate($tplidx); |
||
| 316 | $pagenb++; |
||
| 317 | $this->_pagehead($pdf, $object, 1, $outputlangs); |
||
| 318 | $pdf->SetFont('','', $default_font_size - 1); |
||
| 319 | $pdf->MultiCell(0, 3, ''); // Set interline to 3 |
||
| 320 | $pdf->SetTextColor(0,0,0); |
||
| 321 | |||
| 322 | $tab_top = 90; |
||
| 323 | $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10); |
||
| 324 | $tab_height = 130; |
||
| 325 | $tab_height_newpage = 150; |
||
| 326 | |||
| 327 | // Affiche notes |
||
| 328 | $notetoshow=empty($object->note_public)?'':$object->note_public; |
||
| 329 | if (! empty($conf->global->MAIN_ADD_SALE_REP_SIGNATURE_IN_NOTE)) |
||
| 330 | { |
||
| 331 | // Get first sale rep |
||
| 332 | if (is_object($object->thirdparty)) |
||
| 333 | { |
||
| 334 | $salereparray=$object->thirdparty->getSalesRepresentatives($user); |
||
| 335 | $salerepobj=new User($this->db); |
||
| 336 | $salerepobj->fetch($salereparray[0]['id']); |
||
| 337 | if (! empty($salerepobj->signature)) $notetoshow=dol_concatdesc($notetoshow, $salerepobj->signature); |
||
| 338 | } |
||
| 339 | } |
||
| 340 | if ($notetoshow) |
||
| 341 | { |
||
| 342 | $tab_top = 88; |
||
| 343 | |||
| 344 | $pdf->SetFont('','', $default_font_size - 1); |
||
| 345 | $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1); |
||
| 346 | $nexY = $pdf->GetY(); |
||
| 347 | $height_note=$nexY-$tab_top; |
||
| 348 | |||
| 349 | // Rect prend une longueur en 3eme param |
||
| 350 | $pdf->SetDrawColor(192,192,192); |
||
| 351 | $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1); |
||
| 352 | |||
| 353 | $tab_height = $tab_height - $height_note; |
||
| 354 | $tab_top = $nexY+6; |
||
| 355 | } |
||
| 356 | else |
||
| 357 | { |
||
| 358 | $height_note=0; |
||
| 359 | } |
||
| 360 | |||
| 361 | $iniY = $tab_top + 7; |
||
| 362 | $curY = $tab_top + 7; |
||
| 363 | $nexY = $tab_top + 7; |
||
| 364 | |||
| 365 | $inPackage = false; |
||
| 366 | $TPackageInfos = array(); |
||
| 367 | $TChilds = array(); |
||
| 368 | $package_qty = 0; |
||
| 369 | $TStack = array(); |
||
| 370 | |||
| 371 | // Loop on each lines |
||
| 372 | for ($i = 0 ; $i < $nblignes ; $i++) |
||
| 373 | { |
||
| 374 | $package_qty = $TStack[count($TStack) - 1]['package_qty']; |
||
| 375 | $inPackage = count($TStack) > 0; |
||
| 376 | |||
| 377 | // Ligne de titre |
||
| 378 | if ($object->lines[$i]->product_type == 9 && $object->lines[$i]->qty < 97 && $object->lines[$i]->fk_product > 0) { |
||
| 379 | $inPackage = true; |
||
| 380 | |||
| 381 | if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES) { |
||
| 382 | if (!empty($object->lines[$i]->fk_product)) { |
||
| 383 | $product = new Product($db); |
||
| 384 | $product->fetch($object->lines[$i]->fk_product); |
||
| 385 | |||
| 386 | $TChilds = $product->getChildsArbo($product->id); |
||
| 387 | |||
| 388 | $TStack[count($TStack)] = array( |
||
| 389 | 'childs' => $TChilds, |
||
| 390 | 'package' => array(), |
||
| 391 | 'package_qty' => 0 |
||
| 392 | ); |
||
| 393 | |||
| 394 | // Si on se trouvait déjà dans un package, on rajoute ce produit à la liste des produits |
||
| 395 | // du précédent package |
||
| 396 | if (count($TStack) > 1) { |
||
| 397 | $TStack[count($TStack) - 2]['package'][$object->lines[$i]->fk_product] += $object->lines[$i]->qty; |
||
| 398 | } |
||
| 399 | } |
||
| 400 | } |
||
| 401 | } |
||
| 402 | |||
| 403 | if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES) { |
||
| 404 | if ($inPackage && $object->lines[$i]->product_type != 9 && $object->lines[$i]->fk_product > 0) { |
||
| 405 | $TStack[count($TStack) - 1]['package'][$object->lines[$i]->fk_product] += $object->lines[$i]->qty; |
||
| 406 | } |
||
| 407 | } |
||
| 408 | |||
| 409 | // Ligne de sous-total |
||
| 410 | if ($inPackage && $object->lines[$i]->product_type == 9 && $object->lines[$i]->qty >= 97) { |
||
| 411 | if (count($TStack) <= 1) { |
||
| 412 | $inPackage = false; |
||
| 413 | } |
||
| 414 | |||
| 415 | if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES) { |
||
| 416 | // Comparaison pour déterminer la quantité de package |
||
| 417 | $TProducts = array_keys($TStack[count($TStack) - 1]['package']); |
||
| 418 | $TProductsChilds = array_keys($TStack[count($TStack) - 1]['childs']); |
||
| 419 | |||
| 420 | if ($TProductsChilds == $TProducts) { |
||
| 421 | // Il s'agit d'un package |
||
| 422 | // On récupére la quantité |
||
| 423 | $first_child_id = $TProducts[0]; |
||
| 424 | $document_qty = $TStack[count($TStack) - 1]['package'][$first_child_id]; |
||
| 425 | $base_qty = $TStack[count($TStack) - 1]['childs'][$first_child_id][1]; |
||
| 426 | |||
| 427 | $TStack[count($TStack) - 1]['package_qty'] = $document_qty / $base_qty; |
||
| 428 | $package_qty = $TStack[count($TStack) - 1]['package_qty']; |
||
| 429 | } |
||
| 430 | |||
| 431 | array_pop($TStack); |
||
| 432 | } |
||
| 433 | } |
||
| 434 | |||
| 435 | $curY = $nexY; |
||
| 436 | $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage |
||
| 437 | $pdf->SetTextColor(0,0,0); |
||
| 438 | |||
| 439 | // Define size of image if we need it |
||
| 440 | $imglinesize=array(); |
||
| 441 | if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]); |
||
| 442 | |||
| 443 | $pdf->setTopMargin($tab_top_newpage); |
||
| 444 | $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. |
||
| 445 | $pageposbefore=$pdf->getPage(); |
||
| 446 | |||
| 447 | $showpricebeforepagebreak=1; |
||
| 448 | $posYAfterImage=0; |
||
| 449 | $posYAfterDescription=0; |
||
| 450 | |||
| 451 | // We start with Photo of product line |
||
| 452 | if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot))) // If photo too high, we moved completely on new page |
||
| 453 | { |
||
| 454 | $pdf->AddPage('','',true); |
||
| 455 | if (! empty($tplidx)) $pdf->useTemplate($tplidx); |
||
| 456 | if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); |
||
| 457 | $pdf->setPage($pageposbefore+1); |
||
| 458 | |||
| 459 | $curY = $tab_top_newpage; |
||
| 460 | $showpricebeforepagebreak=0; |
||
| 461 | } |
||
| 462 | |||
| 463 | if (isset($imglinesize['width']) && isset($imglinesize['height'])) |
||
| 464 | { |
||
| 465 | $curX = $this->posxpicture-1; |
||
| 466 | $pdf->Image($realpatharray[$i], $curX + (($this->posxtva-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi |
||
| 467 | // $pdf->Image does not increase value return by getY, so we save it manually |
||
| 468 | $posYAfterImage=$curY+$imglinesize['height']; |
||
| 469 | } |
||
| 470 | |||
| 471 | // Description of product line |
||
| 472 | $curX = $this->posxdesc-1; |
||
| 473 | |||
| 474 | $pdf->startTransaction(); |
||
| 475 | pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc); |
||
| 476 | |||
| 477 | $pageposafter=$pdf->getPage(); |
||
| 478 | if ($pageposafter > $pageposbefore) // There is a pagebreak |
||
| 479 | { |
||
| 480 | $pdf->rollbackTransaction(true); |
||
| 481 | $pageposafter=$pageposbefore; |
||
| 482 | //print $pageposafter.'-'.$pageposbefore;exit; |
||
| 483 | $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. |
||
| 484 | pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc); |
||
| 485 | |||
| 486 | $pageposafter=$pdf->getPage(); |
||
| 487 | $posyafter=$pdf->GetY(); |
||
| 488 | //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit; |
||
| 489 | if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text |
||
| 490 | { |
||
| 491 | if ($i == ($nblignes-1)) // No more lines, and no space left to show total, so we create a new page |
||
| 492 | { |
||
| 493 | $pdf->AddPage('','',true); |
||
| 494 | if (! empty($tplidx)) $pdf->useTemplate($tplidx); |
||
| 495 | if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); |
||
| 496 | $pdf->setPage($pageposafter+1); |
||
| 497 | } |
||
| 498 | } |
||
| 499 | else |
||
| 500 | { |
||
| 501 | // We found a page break |
||
| 502 | $showpricebeforepagebreak=0; |
||
| 503 | } |
||
| 504 | } |
||
| 505 | else // No pagebreak |
||
| 506 | { |
||
| 507 | $pdf->commitTransaction(); |
||
| 508 | } |
||
| 509 | $posYAfterDescription=$pdf->GetY(); |
||
| 510 | |||
| 511 | $nexY = $pdf->GetY(); |
||
| 512 | $pageposafter=$pdf->getPage(); |
||
| 513 | |||
| 514 | $pdf->setPage($pageposbefore); |
||
| 515 | $pdf->setTopMargin($this->marge_haute); |
||
| 516 | $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. |
||
| 517 | |||
| 518 | // We suppose that a too long description or photo were moved completely on next page |
||
| 519 | if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) { |
||
| 520 | $pdf->setPage($pageposafter); $curY = $tab_top_newpage; |
||
| 521 | } |
||
| 522 | |||
| 523 | $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut |
||
| 524 | |||
| 525 | // VAT Rate |
||
| 526 | if (empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) |
||
| 527 | { |
||
| 528 | // Si on ne doit masquer que les sous-produits |
||
| 529 | if ($hidedetails && !$inPackage && $conf->global->SUBTOTAL_ONLY_HIDE_SUBPRODUCTS_PRICES) { |
||
| 530 | $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, 0); |
||
| 531 | } else { |
||
| 532 | $vat_rate = pdf_getlinevatrate($object, $i, $outputlangs, $hidedetails); |
||
| 533 | } |
||
| 534 | |||
| 535 | $pdf->SetXY($this->posxtva, $curY); |
||
| 536 | $pdf->MultiCell($this->posxup-$this->posxtva-0.8, 3, $vat_rate, 0, 'R'); |
||
| 537 | } |
||
| 538 | |||
| 539 | // Unit price before discount |
||
| 540 | if ($hidedetails && !$inPackage && $conf->global->SUBTOTAL_ONLY_HIDE_SUBPRODUCTS_PRICES) { |
||
| 541 | $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, 0); |
||
| 542 | } else { |
||
| 543 | $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails); |
||
| 544 | } |
||
| 545 | |||
| 546 | $pdf->SetXY($this->posxup, $curY); |
||
| 547 | $pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0); |
||
| 548 | |||
| 549 | // Booléen pour déterminer s'il s'agit d'une ligne de titre ou non |
||
| 550 | $isTitle = false; |
||
| 551 | |||
| 552 | // Quantity |
||
| 553 | // Affichage de la quantité sur les lignes de total si la conf l'indique |
||
| 554 | |||
| 555 | // Récupération de la quantité à afficher |
||
| 556 | if ($conf->global->SUBTOTAL_IF_HIDE_PRICES_SHOW_QTY) { |
||
| 557 | if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES && $package_qty > 0) { |
||
| 558 | $qty = $package_qty; |
||
| 559 | } else { |
||
| 560 | $qty = pdf_getlineqty($object, $i, $outputlangs, 0); |
||
| 561 | } |
||
| 562 | } else { |
||
| 563 | if ($conf->global->SUBTOTAL_SHOW_QTY_ON_TITLES && $package_qty > 0) { |
||
| 564 | $qty = $package_qty; |
||
| 565 | } else { |
||
| 566 | $qty = pdf_getlineqty($object, $i, $outputlangs, $hidedetails); |
||
| 567 | } |
||
| 568 | } |
||
| 569 | |||
| 570 | $pdf->SetXY($this->posxqty, $curY); |
||
| 571 | $pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 3, $qty, 0, 'R'); // Enough for 6 chars |
||
| 572 | |||
| 573 | // Discount on line |
||
| 574 | if ($object->lines[$i]->remise_percent) |
||
| 575 | { |
||
| 576 | $pdf->SetXY($this->posxdiscount-2, $curY); |
||
| 577 | $remise_percent = pdf_getlineremisepercent($object, $i, $outputlangs, $hidedetails); |
||
| 578 | $pdf->MultiCell($this->postotalht-$this->posxdiscount+2, 3, $remise_percent, 0, 'R'); |
||
| 579 | } |
||
| 580 | |||
| 581 | // Total HT line |
||
| 582 | if ($hidedetails && !$inPackage && $conf->global->SUBTOTAL_ONLY_HIDE_SUBPRODUCTS_PRICES) { |
||
| 583 | $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, 0); |
||
| 584 | } else { |
||
| 585 | $total_excl_tax = pdf_getlinetotalexcltax($object, $i, $outputlangs, $hidedetails); |
||
| 586 | } |
||
| 587 | |||
| 588 | $pdf->SetXY($this->postotalht, $curY); |
||
| 589 | $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0); |
||
| 590 | |||
| 591 | // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva |
||
| 592 | $tvaligne=$object->lines[$i]->total_tva; |
||
| 593 | $localtax1ligne=$object->lines[$i]->total_localtax1; |
||
| 594 | $localtax2ligne=$object->lines[$i]->total_localtax2; |
||
| 595 | $localtax1_rate=$object->lines[$i]->localtax1_tx; |
||
| 596 | $localtax2_rate=$object->lines[$i]->localtax2_tx; |
||
| 597 | $localtax1_type=$object->lines[$i]->localtax1_type; |
||
| 598 | $localtax2_type=$object->lines[$i]->localtax2_type; |
||
| 599 | |||
| 600 | if ($object->remise_percent) $tvaligne-=($tvaligne*$object->remise_percent)/100; |
||
| 601 | if ($object->remise_percent) $localtax1ligne-=($localtax1ligne*$object->remise_percent)/100; |
||
| 602 | if ($object->remise_percent) $localtax2ligne-=($localtax2ligne*$object->remise_percent)/100; |
||
| 603 | |||
| 604 | $vatrate=(string) $object->lines[$i]->tva_tx; |
||
| 605 | |||
| 606 | // Retrieve type from database for backward compatibility with old records |
||
| 607 | if ((! isset($localtax1_type) || $localtax1_type=='' || ! isset($localtax2_type) || $localtax2_type=='') // if tax type not defined |
||
| 608 | && (! empty($localtax1_rate) || ! empty($localtax2_rate))) // and there is local tax |
||
| 609 | { |
||
| 610 | $localtaxtmp_array=getLocalTaxesFromRate($vatrate,0,$object->thirdparty,$mysoc); |
||
| 611 | $localtax1_type = $localtaxtmp_array[0]; |
||
| 612 | $localtax2_type = $localtaxtmp_array[2]; |
||
| 613 | } |
||
| 614 | |||
| 615 | // retrieve global local tax |
||
| 616 | if ($localtax1_type && $localtax1ligne != 0) |
||
| 617 | $this->localtax1[$localtax1_type][$localtax1_rate]+=$localtax1ligne; |
||
| 618 | if ($localtax2_type && $localtax2ligne != 0) |
||
| 619 | $this->localtax2[$localtax2_type][$localtax2_rate]+=$localtax2ligne; |
||
| 620 | |||
| 621 | if (($object->lines[$i]->info_bits & 0x01) == 0x01) $vatrate.='*'; |
||
| 622 | if (! isset($this->tva[$vatrate])) $this->tva[$vatrate]=0; |
||
| 623 | |||
| 624 | if (!empty($object->lines[$i]->TTotal_tva)) |
||
| 625 | { |
||
| 626 | foreach ($object->lines[$i]->TTotal_tva as $vatrate => $tvaligne) |
||
| 627 | { |
||
| 628 | $this->tva[$vatrate] += $tvaligne; |
||
| 629 | } |
||
| 630 | } |
||
| 631 | else { |
||
| 632 | // standard |
||
| 633 | if(!empty($tvaligne)) $this->tva[$vatrate] += $tvaligne; |
||
| 634 | } |
||
| 635 | |||
| 636 | if ($posYAfterImage > $posYAfterDescription) $nexY=$posYAfterImage; |
||
| 637 | |||
| 638 | // Add line |
||
| 639 | if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1)) |
||
| 640 | { |
||
| 641 | $pdf->setPage($pageposafter); |
||
| 642 | $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(210,210,210))); |
||
| 643 | //$pdf->SetDrawColor(190,190,200); |
||
| 644 | $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1); |
||
| 645 | $pdf->SetLineStyle(array('dash'=>0)); |
||
| 646 | } |
||
| 647 | |||
| 648 | $nexY+=2; // Passe espace entre les lignes |
||
| 649 | |||
| 650 | // Detect if some page were added automatically and output _tableau for past pages |
||
| 651 | while ($pagenb < $pageposafter) |
||
| 652 | { |
||
| 653 | $pdf->setPage($pagenb); |
||
| 654 | if ($pagenb == 1) |
||
| 655 | { |
||
| 656 | $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); |
||
| 657 | } |
||
| 658 | else |
||
| 659 | { |
||
| 660 | $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); |
||
| 661 | } |
||
| 662 | $this->_pagefoot($pdf,$object,$outputlangs,1); |
||
| 663 | $pagenb++; |
||
| 664 | $pdf->setPage($pagenb); |
||
| 665 | $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. |
||
| 666 | if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); |
||
| 667 | } |
||
| 668 | if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak) |
||
| 669 | { |
||
| 670 | if ($pagenb == 1) |
||
| 671 | { |
||
| 672 | $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); |
||
| 673 | } |
||
| 674 | else |
||
| 675 | { |
||
| 676 | $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); |
||
| 677 | } |
||
| 678 | $this->_pagefoot($pdf,$object,$outputlangs,1); |
||
| 679 | // New page |
||
| 680 | $pdf->AddPage(); |
||
| 681 | if (! empty($tplidx)) $pdf->useTemplate($tplidx); |
||
| 682 | $pagenb++; |
||
| 683 | if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); |
||
| 684 | } |
||
| 685 | } |
||
| 686 | |||
| 687 | // Show square |
||
| 688 | if ($pagenb == 1) |
||
| 689 | { |
||
| 690 | $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); |
||
| 691 | $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; |
||
| 692 | } |
||
| 693 | else |
||
| 694 | { |
||
| 695 | $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); |
||
| 696 | $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; |
||
| 697 | } |
||
| 698 | |||
| 699 | // Affiche zone infos |
||
| 700 | $posy=$this->_tableau_info($pdf, $object, $bottomlasttab, $outputlangs); |
||
| 701 | |||
| 702 | if (!$conf->global->SUBTOTAL_HIDE_DOCUMENT_TOTAL) { |
||
| 703 | // Affiche zone totaux |
||
| 704 | $posy=$this->_tableau_tot($pdf, $object, 0, $bottomlasttab, $outputlangs); |
||
| 705 | } |
||
| 706 | |||
| 707 | // Affiche zone versements |
||
| 708 | /* |
||
| 709 | if ($deja_regle || $amount_credit_notes_included || $amount_deposits_included) |
||
| 710 | { |
||
| 711 | $posy=$this->_tableau_versements($pdf, $object, $posy, $outputlangs); |
||
| 712 | } |
||
| 713 | */ |
||
| 714 | |||
| 715 | // Pied de page |
||
| 716 | $this->_pagefoot($pdf,$object,$outputlangs); |
||
| 717 | if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages(); |
||
| 718 | |||
| 719 | $pdf->Close(); |
||
| 720 | |||
| 721 | $pdf->Output($file,'F'); |
||
| 722 | |||
| 723 | //Add pdfgeneration hook |
||
| 724 | $hookmanager->initHooks(array('pdfgeneration')); |
||
| 725 | $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); |
||
| 726 | global $action; |
||
| 727 | $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
||
| 728 | |||
| 729 | if (! empty($conf->global->MAIN_UMASK)) |
||
| 730 | @chmod($file, octdec($conf->global->MAIN_UMASK)); |
||
| 731 | |||
| 732 | return 1; // Pas d'erreur |
||
| 733 | } |
||
| 734 | else |
||
| 735 | { |
||
| 736 | $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); |
||
| 737 | return 0; |
||
| 738 | } |
||
| 739 | } |
||
| 740 | else |
||
| 741 | { |
||
| 742 | $this->error=$langs->trans("ErrorConstantNotDefined","PROP_OUTPUTDIR"); |
||
| 743 | return 0; |
||
| 744 | } |
||
| 745 | |||
| 746 | $this->error=$langs->trans("ErrorUnknown"); |
||
| 747 | return 0; // Erreur par defaut |
||
| 748 | } |
||
| 1536 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.