diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 62a92f4d5ac2b..92baae566694c 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -6,7 +6,7 @@ * Copyright (C) 2010 Juanjo Menent * Copyright (C) 2012 Christophe Battarel * Copyright (C) 2012 Cédric Salvador - * Copyright (C) 2012-2015 Raphaël Doursenaud + * Copyright (C) 2012-2016 Raphaël Doursenaud * Copyright (C) 2014 Cedric GROSS * Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com> * Copyright (C) 2015 Marcos García @@ -1947,3 +1947,79 @@ function pdf_getSizeForImage($realpath) return array('width'=>$width,'height'=>$height); } +/** + * Output printable object extrafields to PDF + * + * @param TCPDI $pdf PDF object + * @param CommonObject $object Business object + */ +function pdf_writeMainExtrafields(&$pdf, $object) +{ + require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; + global $db; + + // Is there any extrafields? + if ($object->fetch_optionals()) { + + $extrafields = new ExtraFields($db); + $labels = $extrafields->fetch_name_optionals_label($object->table_element); + $values = $object->array_options; + + $text = extractExtrafieldsText($extrafields, $labels, $values); + + if (!($text === null)) { + $pdf->writeHTMLCell(190, 3, $pdf->GetX(), $pdf->GetY(), $text, 0, 1); + } + } +} + +/** + * Output printable line extrafields to PDF line description + * + * @param TCPDI $pdf PDF object + * @param CommonObject $object Business object + * @param int $i Current line number + */ +function pdf_writeLineExtrafields(&$pdf, $object, $i) +{ + require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; + global $db; + + // Is there any line extrafields? + if($object->lines[$i]->fetch_optionals()) { + + $extrafields = new ExtraFields($db); + $labels = $extrafields->fetch_name_optionals_label($object->table_element_line); + $values = $object->lines[$i]->array_options; + + $text = extractExtrafieldsText($extrafields, $labels, $values); + + if(!($text === null)) { + $pdf->writeHTMLCell(190, 3, $pdf->GetX(), $pdf->GetY(), $text, 0, 1); + } + } +} + +/** + * Extract text from extrafields + * + * @param ExtraFields $extrafields Extrafields boject + * @param array $labels Labels list + * @param array $values Values list + * @return string + */ +function extractExtrafieldsText($extrafields, $labels, $values) +{ + global $langs; + $text = null; + foreach ($labels as $code => $label) { + $value = $values['options_' . $code]; + if (!empty($value) && $extrafields->attribute_printable[$code]) { + if (!($text === null)) { + $text .= '
'; + } + $text .= $label . $langs->trans("SeparatorColon") . ' '. $value; + } + } + return $text; +} diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index e967f6781ea2e..d21a102347231 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -5,7 +5,7 @@ * Copyright (C) 2010-2014 Juanjo Menent * Copyright (C) 2012 Christophe Battarel * Copyright (C) 2012 Cédric Salvador - * Copyright (C) 2012-2014 Raphaël Doursenaud + * Copyright (C) 2012-2016 Raphaël Doursenaud * Copyright (C) 2015 Marcos García * * This program is free software; you can redistribute it and/or modify @@ -387,6 +387,11 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid $height_note=0; } + // Main extrafields + $pdf->setY($tab_top); // FIXME: Ugly hack to fit current code. All the document should use relative positions instead. + pdf_writeMainExtrafields($pdf, $object); + $tab_top = $pdf->GetY() + 6; // FIXME: Ugly hack to fit current code. All the document should use relative positions instead. + $iniY = $tab_top + 7; $curY = $tab_top + 7; $nexY = $tab_top + 7; @@ -435,6 +440,10 @@ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hid $pdf->startTransaction(); pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc); + + // Line extrafields + pdf_writeLineExtrafields($pdf, $object, $i); + $pageposafter=$pdf->getPage(); if ($pageposafter > $pageposbefore) // There is a pagebreak { diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index eebec1e7f887b..bd4922dbd60c4 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -8,6 +8,7 @@ FONTFORPDF=helvetica FONTSIZEFORPDF=10 SeparatorDecimal=. SeparatorThousand=, +SepratorColon=: FormatDateShort=%m/%d/%Y FormatDateShortInput=%m/%d/%Y FormatDateShortJava=MM/dd/yyyy diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index 5d0a8b6048373..614a36e6daf9c 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -8,6 +8,7 @@ FONTFORPDF=helvetica FONTSIZEFORPDF=10 SeparatorDecimal=, SeparatorThousand=Space +SeparatorColon= : FormatDateShort=%d/%m/%Y FormatDateShortInput=%d/%m/%Y FormatDateShortJava=dd/MM/yyyy