Is there a way to display "Description" of products on invoices for just some products?

Let’s say I have a product called “Work [h]” with description “Work made by employee, charged by hour”. When we add this product to invoice, the description is automatically added and seen on invoice, which it should in this case.

Now let’s say we have another product called “Extras at place” with description “Extra materials required for the work in question”, but this description is supposed to be internal only (only for us) and should not be added to the invoice.

Is there a setting on product level that makes the description for that particular product to NOT show up on invoices, but still be in the field “Description”?

(I know we can use Notes for internal notes, but notes does not show up on the Product Card like Description does, and that’s what we want here)

Maybe you can define an extrafield “internal_description” ( type boolean) on products and set “Display on PDF” to “0”

In this case, you can decide for each product whether the description is intended internally or externally.

Now the corresponding PDF generation scripts “pdf_sponge-modules.php” or similar must be extended by a corresponding query on the content of the extrafield and selection on the result.

// Example:
// if $extrafield = 1 then hide description
if ($extrafield) {
	$this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, 1);
} else {
	$this->printColDescContent($pdf, $curY, 'desc', $object, $i, $outputlangs, $hideref, $hidedesc);
}	

This is a good idea. However, extracting/using the extrafields from within php-code seems to be quite difficult. I have looked at /core/class/extrafields.class.php but I cannot figure out how to - in the pdfwriter class - extract the boolean value from the particular extrafield for the current line.

In sponge-module there is a line “if (!empty($object->lines[$i]->array_options))…”, but array_options is always empty and I cannot find the extrafields even if I do var_dump($object).

So, how do we fetch the extrafields?

I believe there are pre-defined functions to do this, but I don’t discovered that yet.
So I decided to wrote my own function inside the “pdf_sponge-modules.php” file.

// exchange "gen_custom" with the name of your extrafield
	public function getLocation($id)
	{
			$sql = "SELECT gen_custom FROM ".MAIN_DB_PREFIX."product_extrafields";
			$sql .= " WHERE fk_object = ".((int) $id);

			dol_syslog(get_class($this).'::getValueFrom', LOG_DEBUG);
			  $resql = $this->db->query($sql);
			  if ($resql) {
				  $row = $this->db->fetch_row($resql);
				  $result = $row[0];
			  }
		return $result;
	}

Call this function like this:

    $extrafield = $this->getLocation($object->lines[$i]->fk_product);

and use it like described in my last post.

1 Like
1 Like

This code works perfectly as intended. Thank you.

Thank you for pointing out the wiki.
I have indeed not looked/read enough into it.
Sometimes things have to be done quickly because the CTO is breathing down your neck… :nerd_face:

In this case I suggested to the TO to use an extra field (boolean) to control the display of text (not the extra field) that is regularly displayed in the PDF’s.
But in any case I will check the wiki more often now. :wink:

1 Like