163  public function write_file($object, $outputlangs, $srctemplatepath = 
'', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
 
  166    global $user, $langs, $conf, $mysoc, $db, $hookmanager, $nblines;
 
  168    dol_syslog(
"write_file outputlangs->defaultlang=".(is_object($outputlangs) ? $outputlangs->defaultlang : 
'null'));
 
  170    if (!is_object($outputlangs)) {
 
  171      $outputlangs = $langs;
 
  175      $outputlangs->charset_output = 
'ISO-8859-1';
 
  179    $outputlangs->loadLangs(array(
"main", 
"bills", 
"products", 
"dict", 
"companies"));
 
  182    if (
getDolGlobalString(
'MYOBJECT_DRAFT_WATERMARK') && $object->statut == $object::STATUS_DRAFT) {
 
  186    global $outputlangsbis;
 
  187    $outputlangsbis = 
null;
 
  189      $outputlangsbis = 
new Translate(
'', $conf);
 
  191      $outputlangsbis->loadLangs(array(
"main", 
"bills", 
"products", 
"dict", 
"companies"));
 
  194    $nblines = (is_array($object->lines) ? count($object->lines) : 0);
 
  202    $realpatharray = array();
 
  203    $this->atleastonephoto = 
false;
 
  260      $object->fetch_thirdparty();
 
  263      if ($object->specimen) {
 
  265        $file = $dir.
"/SPECIMEN.pdf";
 
  269        $file = $dir.
"/".$objectref.
".pdf";
 
  271      if (!file_exists($dir)) {
 
  273          $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
 
  278      if (file_exists($dir)) {
 
  280        if (!is_object($hookmanager)) {
 
  281          include_once DOL_DOCUMENT_ROOT.
'/core/class/hookmanager.class.php';
 
  284        $hookmanager->initHooks(array(
'pdfgeneration'));
 
  285        $parameters = array(
'file'=>$file, 
'object'=>$object, 
'outputlangs'=>$outputlangs);
 
  287        $reshook = $hookmanager->executeHooks(
'beforePDFCreation', $parameters, $object, $action); 
 
  290        $nblines = (is_array($object->lines) ? count($object->lines) : 0);
 
  295        $pdf->SetAutoPageBreak(1, 0);
 
  297        $heightforinfotot = 50; 
 
  299        $heightforfooter = $this->marge_basse + (
getDolGlobalInt(
'MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS') ? 12 : 22); 
 
  301        if (class_exists(
'TCPDF')) {
 
  302          $pdf->setPrintHeader(
false);
 
  303          $pdf->setPrintFooter(
false);
 
  309          $logodir = $conf->mycompany->dir_output;
 
  310          if (!empty($conf->mycompany->multidir_output[$object->entity])) {
 
  311            $logodir = $conf->mycompany->multidir_output[$object->entity];
 
  313          $pagecount = $pdf->setSourceFile($logodir.
'/'.
getDolGlobalString(
'MAIN_ADD_PDF_BACKGROUND'));
 
  314          $tplidx = $pdf->importPage(1);
 
  319        $pdf->SetDrawColor(128, 128, 128);
 
  321        $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref));
 
  322        $pdf->SetSubject($outputlangs->transnoentities(
"PdfTitle"));
 
  323        $pdf->SetCreator(
"Dolibarr ".DOL_VERSION);
 
  324        $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs)));
 
  325        $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref).
" ".$outputlangs->transnoentities(
"PdfTitle").
" ".$outputlangs->convToOutputCharset($object->thirdparty->name));
 
  327          $pdf->SetCompression(
false);
 
  331        $cert = empty($user->conf->CERTIFICATE_CRT) ? 
'' : $user->conf->CERTIFICATE_CRT;
 
  339            'Name' => $this->emetteur->name,
 
  340            'Location' => 
getCountry($this->emetteur->country_code, 0),
 
  341            'Reason' => 
'MYOBJECT',
 
  342            'ContactInfo' => $this->emetteur->email
 
  344          $pdf->setSignature($cert, $cert, $this->emetteur->name, 
'', 2, $info);
 
  347        $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); 
 
  352        if (!empty($tplidx)) {
 
  353          $pdf->useTemplate($tplidx);
 
  357        $top_shift = $this->
_pagehead($pdf, $object, 1, $outputlangs, $outputlangsbis);
 
  358        $pdf->SetFont(
'', 
'', $default_font_size - 1);
 
  359        $pdf->MultiCell(0, 3, 
''); 
 
  360        $pdf->SetTextColor(0, 0, 0);
 
  362        $tab_top = 90 + $top_shift;
 
  363        $tab_top_newpage = (!
getDolGlobalInt(
'MAIN_PDF_DONOTREPEAT_HEAD') ? 42 + $top_shift : 10);
 
  365        $tab_height = $this->page_hauteur - $tab_top - $heightforfooter - $heightforfreetext;
 
  367        $tab_height_newpage = 150;
 
  369          $tab_height_newpage -= $top_shift;
 
  372        $nexY = $tab_top - 1;
 
  375        $notetoshow = empty($object->note_public) ? 
'' : $object->note_public;
 
  377        $extranote = $this->getExtrafieldsInHtml($object, $outputlangs);
 
  378        if (!empty($extranote)) {
 
  382        $pagenb = $pdf->getPage();
 
  386          $tab_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite;
 
  387          $pageposbeforenote = $pagenb;
 
  394          $pdf->startTransaction();
 
  396          $pdf->SetFont(
'', 
'', $default_font_size - 1);
 
  397          $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, 
dol_htmlentitiesbr($notetoshow), 0, 1);
 
  399          $pageposafternote = $pdf->getPage();
 
  400          $posyafter = $pdf->GetY();
 
  402          if ($pageposafternote > $pageposbeforenote) {
 
  403            $pdf->rollbackTransaction(
true);
 
  406            while ($pagenb < $pageposafternote) {
 
  409              if (!empty($tplidx)) {
 
  410                $pdf->useTemplate($tplidx);
 
  413                $this->
_pagehead($pdf, $object, 0, $outputlangs);
 
  416              $pdf->setTopMargin($tab_top_newpage);
 
  418              $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
 
  422            $pdf->setPage($pageposbeforenote);
 
  423            $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
 
  424            $pdf->SetFont(
'', 
'', $default_font_size - 1);
 
  425            $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, 
dol_htmlentitiesbr($notetoshow), 0, 1);
 
  426            $pageposafternote = $pdf->getPage();
 
  428            $posyafter = $pdf->GetY();
 
  430            if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {  
 
  431              $pdf->AddPage(
'', 
'', 
true);
 
  434              $pdf->setPage($pageposafternote);
 
  435              $pdf->setTopMargin($tab_top_newpage);
 
  437              $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext);
 
  443            $i = $pageposbeforenote;
 
  444            while ($i < $pageposafternote) {
 
  448              $pdf->SetDrawColor(128, 128, 128);
 
  450              if ($i > $pageposbeforenote) {
 
  451                $height_note = $this->page_hauteur - ($tab_top_newpage + $heightforfooter);
 
  452                $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
 
  454                $height_note = $this->page_hauteur - ($tab_top + $heightforfooter);
 
  455                $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
 
  459              $pdf->setPageOrientation(
'', 1, 0); 
 
  460              $this->
_pagefoot($pdf, $object, $outputlangs, 1);
 
  466            $pdf->setPage($pageposafternote);
 
  467            if (!empty($tplidx)) {
 
  468              $pdf->useTemplate($tplidx);
 
  471              $this->
_pagehead($pdf, $object, 0, $outputlangs);
 
  473            $height_note = $posyafter - $tab_top_newpage;
 
  474            $pdf->Rect($this->marge_gauche, $tab_top_newpage - 1, $tab_width, $height_note + 1);
 
  477            $pdf->commitTransaction();
 
  478            $posyafter = $pdf->GetY();
 
  479            $height_note = $posyafter - $tab_top;
 
  480            $pdf->Rect($this->marge_gauche, $tab_top - 1, $tab_width, $height_note + 1);
 
  483            if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + 20))) {
 
  485              $pdf->AddPage(
'', 
'', 
true);
 
  488              $pdf->setPage($pageposafternote);
 
  489              if (!empty($tplidx)) {
 
  490                $pdf->useTemplate($tplidx);
 
  493                $this->
_pagehead($pdf, $object, 0, $outputlangs);
 
  496              $posyafter = $tab_top_newpage;
 
  500          $tab_height = $tab_height - $height_note;
 
  501          $tab_top = $posyafter + 6;
 
  510        $pdf->startTransaction();
 
  511        $this->
pdfTabTitles($pdf, $tab_top, $tab_height, $outputlangs, $hidetop);
 
  512        $pdf->rollbackTransaction(
true);
 
  514        $nexY = $tab_top + $this->tabTitleHeight;
 
  517        $pageposbeforeprintlines = $pdf->getPage();
 
  518        $pagenb = $pageposbeforeprintlines;
 
  519        for ($i = 0; $i < $nblines; $i++) {
 
  521          $pdf->SetFont(
'', 
'', $default_font_size - 1); 
 
  522          $pdf->SetTextColor(0, 0, 0);
 
  525          $imglinesize = array();
 
  526          if (!empty($realpatharray[$i])) {
 
  530          $pdf->setTopMargin($tab_top_newpage);
 
  531          $pdf->setPageOrientation(
'', 1, $heightforfooter + $heightforfreetext + $heightforinfotot); 
 
  532          $pageposbefore = $pdf->getPage();
 
  534          $showpricebeforepagebreak = 1;
 
  536          $posYAfterDescription = 0;
 
  540            if (isset($imglinesize[
'width']) && isset($imglinesize[
'height']) && ($curY + $imglinesize[
'height']) > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) {  
 
  541              $pdf->AddPage(
'', 
'', 
true);
 
  542              if (!empty($tplidx)) {
 
  543                $pdf->useTemplate($tplidx);
 
  545              $pdf->setPage($pageposbefore + 1);
 
  547              $curY = $tab_top_newpage;
 
  551                $showpricebeforepagebreak = 1;
 
  553                $showpricebeforepagebreak = 0;
 
  557            if (!empty($this->cols[
'photo']) && isset($imglinesize[
'width']) && isset($imglinesize[
'height'])) {
 
  558              $pdf->Image($realpatharray[$i], $this->
getColumnContentXStart(
'photo'), $curY + 1, $imglinesize[
'width'], $imglinesize[
'height'], 
'', 
'', 
'', 2, 300); 
 
  560              $posYAfterImage = $curY + $imglinesize[
'height'];
 
  566            $pdf->startTransaction();
 
  568            $this->
printColDescContent($pdf, $curY, 
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
 
  569            $pageposafter = $pdf->getPage();
 
  571            if ($pageposafter > $pageposbefore) { 
 
  572              $pdf->rollbackTransaction(
true);
 
  573              $pageposafter = $pageposbefore;
 
  574              $pdf->setPageOrientation(
'', 1, $heightforfooter); 
 
  576              $this->
printColDescContent($pdf, $curY, 
'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
 
  578              $pageposafter = $pdf->getPage();
 
  579              $posyafter = $pdf->GetY();
 
  581              if ($posyafter > ($this->page_hauteur - ($heightforfooter + $heightforfreetext + $heightforinfotot))) { 
 
  582                if ($i == ($nblines - 1)) { 
 
  583                  $pdf->AddPage(
'', 
'', 
true);
 
  584                  if (!empty($tplidx)) {
 
  585                    $pdf->useTemplate($tplidx);
 
  587                  $pdf->setPage($pageposafter + 1);
 
  593                  $showpricebeforepagebreak = 1;
 
  595                  $showpricebeforepagebreak = 0;
 
  599              $pdf->commitTransaction();
 
  601            $posYAfterDescription = $pdf->GetY();
 
  604          $nexY = max($pdf->GetY(), $posYAfterImage);
 
  607          $pageposafter = $pdf->getPage();
 
  608          $pdf->setPage($pageposbefore);
 
  609          $pdf->setTopMargin($this->marge_haute);
 
  610          $pdf->setPageOrientation(
'', 1, 0); 
 
  613          if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) {
 
  614            $pdf->setPage($pageposafter);
 
  615            $curY = $tab_top_newpage;
 
  618          $pdf->SetFont(
'', 
'', $default_font_size - 1); 
 
  625            $nexY = max($pdf->GetY(), $nexY);
 
  629          if (!empty($object->lines[$i]->array_options)) {
 
  630            foreach ($object->lines[$i]->array_options as $extrafieldColKey => $extrafieldValue) {
 
  632                $extrafieldValue = $this->
getExtrafieldContent($object->lines[$i], $extrafieldColKey, $outputlangs);
 
  634                $nexY = max($pdf->GetY(), $nexY);
 
  646            'outputlangs' => $outputlangs,
 
  647            'hidedetails' => $hidedetails
 
  649          $reshook = $hookmanager->executeHooks(
'printPDFline', $parameters, $this); 
 
  654          $prev_progress = $object->lines[$i]->get_prev_progress($object->id);
 
  655          if ($prev_progress > 0 && !empty($object->lines[$i]->situation_percent)) { 
 
  656            if (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
 
  657              $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
 
  659              $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent;
 
  662            if (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) {
 
  663              $tvaligne = $sign * $object->lines[$i]->multicurrency_total_tva;
 
  665              $tvaligne = $sign * $object->lines[$i]->total_tva;
 
  669          $localtax1ligne = $object->lines[$i]->total_localtax1;
 
  670          $localtax2ligne = $object->lines[$i]->total_localtax2;
 
  671          $localtax1_rate = $object->lines[$i]->localtax1_tx;
 
  672          $localtax2_rate = $object->lines[$i]->localtax2_tx;
 
  673          $localtax1_type = $object->lines[$i]->localtax1_type;
 
  674          $localtax2_type = $object->lines[$i]->localtax2_type;
 
  676          $vatrate = (string) $object->lines[$i]->tva_tx;
 
  679          if ((!isset($localtax1_type) || $localtax1_type == 
'' || !isset($localtax2_type) || $localtax2_type == 
'') 
 
  680            && (!empty($localtax1_rate) || !empty($localtax2_rate))) { 
 
  682            $localtax1_type = isset($localtaxtmp_array[0]) ? $localtaxtmp_array[0] : 
'';
 
  683            $localtax2_type = isset($localtaxtmp_array[2]) ? $localtaxtmp_array[2] : 
'';
 
  687          if ($localtax1_type && $localtax1ligne != 0) {
 
  688            if (empty($this->localtax1[$localtax1_type][$localtax1_rate])) {
 
  689              $this->localtax1[$localtax1_type][$localtax1_rate] = $localtax1ligne;
 
  691              $this->localtax1[$localtax1_type][$localtax1_rate] += $localtax1ligne;
 
  694          if ($localtax2_type && $localtax2ligne != 0) {
 
  695            if (empty($this->localtax2[$localtax2_type][$localtax2_rate])) {
 
  696              $this->localtax2[$localtax2_type][$localtax2_rate] = $localtax2ligne;
 
  698              $this->localtax2[$localtax2_type][$localtax2_rate] += $localtax2ligne;
 
  702          if (($object->lines[$i]->info_bits & 0x01) == 0x01) {
 
  707          if (!isset($this->tva[$vatrate])) {
 
  708            $this->tva[$vatrate] = 0;
 
  710          $this->tva[$vatrate] += $tvaligne;
 
  711          $vatcode = $object->lines[$i]->vat_src_code;
 
  712          if (empty($this->tva_array[$vatrate.($vatcode ? 
' ('.$vatcode.
')' : 
'')][
'amount'])) {
 
  713            $this->tva_array[$vatrate.($vatcode ? 
' ('.$vatcode.
')' : 
'')][
'amount'] = 0;
 
  715          $this->tva_array[$vatrate.($vatcode ? 
' ('.$vatcode.
')' : 
'')] = array(
'vatrate'=>$vatrate, 
'vatcode'=>$vatcode, 
'amount'=> $this->tva_array[$vatrate.($vatcode ? 
' ('.$vatcode.
')' : 
'')][
'amount'] + $tvaligne);
 
  717          $nexY = max($nexY, $posYAfterImage);
 
  720          if (
getDolGlobalInt(
'MAIN_PDF_DASH_BETWEEN_LINES') && $i < ($nblines - 1)) {
 
  721            $pdf->setPage($pageposafter);
 
  722            $pdf->SetLineStyle(array(
'dash'=>
'1,1', 
'color'=>array(80, 80, 80)));
 
  724            $pdf->line($this->marge_gauche, $nexY, $this->page_largeur - $this->marge_droite, $nexY);
 
  725            $pdf->SetLineStyle(array(
'dash'=>0));
 
  729          while ($pagenb < $pageposafter) {
 
  730            $pdf->setPage($pagenb);
 
  731            if ($pagenb == $pageposbeforeprintlines) {
 
  732              $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
 
  734              $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
 
  736            $this->
_pagefoot($pdf, $object, $outputlangs, 1);
 
  738            $pdf->setPage($pagenb);
 
  739            $pdf->setPageOrientation(
'', 1, 0); 
 
  741              $this->
_pagehead($pdf, $object, 0, $outputlangs);
 
  743            if (!empty($tplidx)) {
 
  744              $pdf->useTemplate($tplidx);
 
  748          if (isset($object->lines[$i + 1]->pagebreak) && $object->lines[$i + 1]->pagebreak) {
 
  749            if ($pagenb == $pageposafter) {
 
  750              $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, $hidetop, 1, $object->multicurrency_code, $outputlangsbis);
 
  752              $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1, $object->multicurrency_code, $outputlangsbis);
 
  754            $this->
_pagefoot($pdf, $object, $outputlangs, 1);
 
  757            if (!empty($tplidx)) {
 
  758              $pdf->useTemplate($tplidx);
 
  762              $this->
_pagehead($pdf, $object, 0, $outputlangs);
 
  768        if ($pagenb == $pageposbeforeprintlines) {
 
  769          $this->
_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, $hidetop, 0, $object->multicurrency_code, $outputlangsbis);
 
  771          $this->
_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0, $object->multicurrency_code, $outputlangsbis);
 
  773        $bottomlasttab = $this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1;
 
  790        $this->
_pagefoot($pdf, $object, $outputlangs);
 
  791        if (method_exists($pdf, 
'AliasNbPages')) {
 
  792          $pdf->AliasNbPages();
 
  797        $pdf->Output($file, 
'F');
 
  800        $hookmanager->initHooks(array(
'pdfgeneration'));
 
  801        $parameters = array(
'file'=>$file, 
'object'=>$object, 
'outputlangs'=>$outputlangs);
 
  803        $reshook = $hookmanager->executeHooks(
'afterPDFCreation', $parameters, $this, $action); 
 
  805          $this->error = $hookmanager->error;
 
  806          $this->errors = $hookmanager->errors;
 
  811        $this->result = array(
'fullpath'=>$file);
 
  815        $this->error = $langs->transnoentities(
"ErrorCanNotCreateDir", $dir);
 
  819      $this->error = $langs->transnoentities(
"ErrorConstantNotDefined", 
"FAC_OUTPUTDIR");
 
 
  910  protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = 
null)
 
  913    global $conf, $langs;
 
  916    if ($outputlangs->trans(
"DIRECTION") == 
'rtl') {
 
  921    $outputlangs->loadLangs(array(
"main", 
"bills", 
"propal", 
"companies"));
 
  928    if (
getDolGlobalString(
'MYMODULE_DRAFT_WATERMARK') && $object->statut == $object::STATUS_DRAFT) {
 
  932    $pdf->SetTextColor(0, 0, 60);
 
  933    $pdf->SetFont(
'', 
'B', $default_font_size + 3);
 
  937    $posy = $this->marge_haute;
 
  938    $posx = $this->page_largeur - $this->marge_droite - $w;
 
  940    $pdf->SetXY($this->marge_gauche, $posy);
 
  944      if ($this->emetteur->logo) {
 
  945        $logodir = $conf->mycompany->dir_output;
 
  950          $logo = $logodir.
'/logos/thumbs/'.$this->emetteur->logo_small;
 
  952          $logo = $logodir.
'/logos/'.$this->emetteur->logo;
 
  954        if (is_readable($logo)) {
 
  956          $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); 
 
  958          $pdf->SetTextColor(200, 0, 0);
 
  959          $pdf->SetFont(
'', 
'B', $default_font_size - 2);
 
  960          $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorLogoFileNotFound", $logo), 0, 
'L');
 
  961          $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"ErrorGoToGlobalSetup"), 0, 
'L');
 
  964        $text = $this->emetteur->name;
 
  965        $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 
'L');
 
  969    $pdf->SetFont(
'', 
'B', $default_font_size + 3);
 
  970    $pdf->SetXY($posx, $posy);
 
  971    $pdf->SetTextColor(0, 0, 60);
 
  972    $title = $outputlangs->transnoentities(
"PdfTitle");
 
  973    if (
getDolGlobalInt(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
 
  975      $title .= $outputlangsbis->transnoentities(
"PdfTitle");
 
  977    $pdf->MultiCell($w, 3, $title, 
'', 
'R');
 
  979    $pdf->SetFont(
'', 
'B', $default_font_size);
 
  982    $pdf->SetXY($posx, $posy);
 
  983    $pdf->SetTextColor(0, 0, 60);
 
  984    $textref = $outputlangs->transnoentities(
"Ref").
" : ".$outputlangs->convToOutputCharset($object->ref);
 
  985    if ($object->statut == $object::STATUS_DRAFT) {
 
  986      $pdf->SetTextColor(128, 0, 0);
 
  987      $textref .= 
' - '.$outputlangs->transnoentities(
"NotValidated");
 
  989    $pdf->MultiCell($w, 4, $textref, 
'', 
'R');
 
  992    $pdf->SetFont(
'', 
'', $default_font_size - 2);
 
  994    if ($object->ref_client) {
 
  996      $pdf->SetXY($posx, $posy);
 
  997      $pdf->SetTextColor(0, 0, 60);
 
  998      $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefCustomer").
" : ".
dol_trunc($outputlangs->convToOutputCharset($object->ref_client), 65), 
'', 
'R');
 
 1002      $object->fetch_projet();
 
 1003      if (!empty($object->project->ref)) {
 
 1005        $pdf->SetXY($posx, $posy);
 
 1006        $pdf->SetTextColor(0, 0, 60);
 
 1007        $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"Project").
" : ".(empty($object->project->title) ? 
'' : $object->project->title), 
'', 
'R');
 
 1012      $object->fetch_projet();
 
 1013      if (!empty($object->project->ref)) {
 
 1014        $outputlangs->load(
"projects");
 
 1016        $pdf->SetXY($posx, $posy);
 
 1017        $pdf->SetTextColor(0, 0, 60);
 
 1018        $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"RefProject").
" : ".(empty($object->project->ref) ? 
'' : $object->project->ref), 
'', 
'R');
 
 1023    $pdf->SetXY($posx, $posy);
 
 1024    $pdf->SetTextColor(0, 0, 60);
 
 1026    $title = $outputlangs->transnoentities(
"Date");
 
 1027    if (
getDolGlobalInt(
'PDF_USE_ALSO_LANGUAGE_CODE') && is_object($outputlangsbis)) {
 
 1028      $title .= 
' - '.$outputlangsbis->transnoentities(
"Date");
 
 1030    $pdf->MultiCell($w, 3, $title.
" : ".
dol_print_date($object->date, 
"day", 
false, $outputlangs, 
true), 
'', 
'R');
 
 1032    if (!
getDolGlobalString(
'MAIN_PDF_HIDE_CUSTOMER_CODE') && !empty($object->thirdparty->code_client)) {
 
 1034      $pdf->SetXY($posx, $posy);
 
 1035      $pdf->SetTextColor(0, 0, 60);
 
 1036      $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"CustomerCode").
" : ".$outputlangs->transnoentities($object->thirdparty->code_client), 
'', 
'R');
 
 1041      $arrayidcontact = $object->getIdContact(
'internal', 
'SALESREPFOLL');
 
 1042      if (count($arrayidcontact) > 0) {
 
 1043        $usertmp = 
new User($this->db);
 
 1044        $usertmp->fetch($arrayidcontact[0]);
 
 1046        $pdf->SetXY($posx, $posy);
 
 1047        $pdf->SetTextColor(0, 0, 60);
 
 1048        $pdf->MultiCell($w, 3, $outputlangs->transnoentities(
"SalesRepresentative").
" : ".$usertmp->getFullName($langs), 
'', 
'R');
 
 1056    $current_y = $pdf->getY();
 
 1057    $posy = 
pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 
'R', $default_font_size);
 
 1058    if ($current_y < $pdf->getY()) {
 
 1059      $top_shift = $pdf->getY() - $current_y;
 
 1064      $carac_emetteur = 
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, 
'', 0, 
'source', $object);
 
 1068      $posy += $top_shift;
 
 1069      $posx = $this->marge_gauche;
 
 1071        $posx = $this->page_largeur - $this->marge_droite - 80;
 
 1075      $widthrecbox = 
getDolGlobalInt(
'MAIN_PDF_USE_ISO_LOCATION') ? 92 : 82;
 
 1080        $pdf->SetTextColor(0, 0, 0);
 
 1081        $pdf->SetFont(
'', 
'', $default_font_size - 2);
 
 1082        $pdf->SetXY($posx, $posy - 5);
 
 1083        $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"BillFrom").
":", 0, $ltrdirection);
 
 1084        $pdf->SetXY($posx, $posy);
 
 1085        $pdf->SetFillColor(230, 230, 230);
 
 1086        $pdf->MultiCell($widthrecbox, $hautcadre, 
"", 0, 
'R', 1);
 
 1087        $pdf->SetTextColor(0, 0, 60);
 
 1092        $pdf->SetXY($posx + 2, $posy + 3);
 
 1093        $pdf->SetFont(
'', 
'B', $default_font_size);
 
 1094        $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, $ltrdirection);
 
 1095        $posy = $pdf->getY();
 
 1099      $pdf->SetXY($posx + 2, $posy);
 
 1100      $pdf->SetFont(
'', 
'', $default_font_size - 1);
 
 1101      $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, $ltrdirection);
 
 1104      $usecontact = 
false;
 
 1105      $arrayidcontact = $object->getIdContact(
'external', 
'BILLING');
 
 1106      if (count($arrayidcontact) > 0) {
 
 1108        $result = $object->fetch_contact($arrayidcontact[0]);
 
 1112      if ($usecontact && $object->contact->socid != $object->thirdparty->id && 
getDolGlobalInt(
'MAIN_USE_COMPANY_NAME_OF_CONTACT')) {
 
 1113        $thirdparty = $object->contact;
 
 1115        $thirdparty = $object->thirdparty;
 
 1118      if (is_object($thirdparty)) {
 
 1123      $carac_client = 
pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty, ($usecontact ? $object->contact : 
''), $usecontact, $mode, $object);
 
 1126      $widthrecbox = 
getDolGlobalInt(
'MAIN_PDF_USE_ISO_LOCATION') ? 92 : 100;
 
 1127      if ($this->page_largeur < 210) {
 
 1131      $posy += $top_shift;
 
 1132      $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
 
 1134        $posx = $this->marge_gauche;
 
 1139        $pdf->SetTextColor(0, 0, 0);
 
 1140        $pdf->SetFont(
'', 
'', $default_font_size - 2);
 
 1141        $pdf->SetXY($posx + 2, $posy - 5);
 
 1142        $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities(
"To").
":", 0, $ltrdirection);
 
 1143        $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
 
 1147      $pdf->SetXY($posx + 2, $posy + 3);
 
 1148      $pdf->SetFont(
'', 
'B', $default_font_size);
 
 1149      $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection);
 
 1151      $posy = $pdf->getY();
 
 1154      $pdf->SetFont(
'', 
'', $default_font_size - 1);
 
 1155      $pdf->SetXY($posx + 2, $posy);
 
 1156      $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, $ltrdirection);
 
 1159    $pdf->SetTextColor(0, 0, 0);