Skip to content

Commit

Permalink
New Dolibarr#4410 Prepare for printable extrafields
Browse files Browse the repository at this point in the history
Added printable extrafields support to customer invoices crabe model
  • Loading branch information
rdoursenaud committed Jan 16, 2016
1 parent f297206 commit a253674
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 2 deletions.
78 changes: 77 additions & 1 deletion htdocs/core/lib/pdf.lib.php
Expand Up @@ -6,7 +6,7 @@
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2012-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2012-2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
* Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
Expand Down Expand Up @@ -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 .= '<br>';
}
$text .= $label . $langs->trans("SeparatorColon") . ' '. $value;
}
}
return $text;
}
11 changes: 10 additions & 1 deletion htdocs/core/modules/facture/doc/pdf_crabe.modules.php
Expand Up @@ -5,7 +5,7 @@
* Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2012-2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down
1 change: 1 addition & 0 deletions htdocs/langs/en_US/main.lang
Expand Up @@ -8,6 +8,7 @@ FONTFORPDF=helvetica
FONTSIZEFORPDF=10
SeparatorDecimal=.
SeparatorThousand=,
SepratorColon=:
FormatDateShort=%m/%d/%Y
FormatDateShortInput=%m/%d/%Y
FormatDateShortJava=MM/dd/yyyy
Expand Down
1 change: 1 addition & 0 deletions htdocs/langs/fr_FR/main.lang
Expand Up @@ -8,6 +8,7 @@ FONTFORPDF=helvetica
FONTSIZEFORPDF=10
SeparatorDecimal=,
SeparatorThousand=Space
SeparatorColon= :
FormatDateShort=%d/%m/%Y
FormatDateShortInput=%d/%m/%Y
FormatDateShortJava=dd/MM/yyyy
Expand Down

0 comments on commit a253674

Please sign in to comment.