Getting locations on the ordernote

Hello,

I could really use some help, i need to be able to add a customfield from products into de PDF of orders
no matter what i do i am not able to figure it out PHP is not my thing :wink:

this is what i have done,
tried the Wiki page by adding the needed fields for a customfield of product

  • only thing i am able to get is product description but not a custom field.

Please help me in this,

id the database code for location for example [‘options_I9948’]

i know it alot to ask but when you look at the default template i need actually a column
before vat (BTW)
image
with that location of the part in it.

if someone would be able to help ?
if needed i am willing to pay for such thing?

Regards

PS: i use the eratosthene template, and it doesnt include the custom fields

Hello,

Without the description of what you have done, we can’t help you.

Everything is explained here : Add Extrafields on PDF Models - Dolibarr ERP CRM Wiki

eratosthene template has the extrafiled function in it.

i am unable to add more images so ill try to explain,

did follow the wiki, but it’s not showing anything, eratostene doens’t work for some reason for customfields on products in the sales order, also check a other forum page here but it wasn’t the awnser to solve it.

i added as followed as mentioned in the instruction

require_once DOL_DOCUMENT_ROOT.‘/core/class/extrafields.class.php’;

$extrafieldsline = new ExtraFields($this->db);
$extralabelsline=$extrafieldsline->fetch_name_optionals_label($object->table_element_line);

$object->lines[$i]->fetch_optionals($object->lines[$i]->rowid,$extralabelsline);

$pdf->MultiCell(0, 3, $outputlangs->convToOutputCharset($object->lines[$i]->array_options[‘options_I9948’]), 0, ‘L’, 0);

but as mentioned i have no clue what to do,also tried to do the include product extrafield but it’s also not showing any thing

On V17.0.2 it’s imho not so difficult

I did similar on the mrp/pdf_vinci.module.php

You need 3 steps:
1.) add new ColumnField “location”
2.) add column “location” in output
3.) add new function getLocation(
)
4.) add translation for “LOCATION”

1:
add in htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php
in function defineColumnField(
)
at the desired position the following code:

		$rank = $rank + 10;
		$this->cols['location'] = array(
			'rank' => $rank,
			'status' => true,
			'width' => 16, // in mm
			'title' => array(
				'textkey' => 'LOCATION'
			),
			'border-left' => true, // add left line separator
		);

You have to play with the width of the other columns and adapt for your wishes

2:
add in function write_file(
) right before " if ($this->getColumnStatus(‘vat’)) "

		// Extrafield
		// Enough for 6 chars
		if ($this->getColumnStatus('location')) {
		    $location = $this->getLocation($object->lines[$i]->fk_product);
		    $this->printStdColumnContent($pdf, $curY, 'location', $location);
		    $nexY = max($pdf->GetY(), $nexY);
		}

3:
wrote the new function getLocation(
)
in htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php

	public function getLocation($id)
	{
            $field = 'name_of_your_column_in_extrafields';
            $table ='name_of_your_table_with_extrafields';

			$sql = "SELECT ".$field." FROM ".MAIN_DB_PREFIX.$table;
			$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];
			  } // maybe we need a else case here 
		return $result;
	}

Regards

1 Like

Thanks for the help, much appreciated.

step 1 and 2 no issue’s column is showing in the PDF
but Step 3 is there a specific location to put this?, when i don’t put it in the webpage will error ofcourse.
but when i put this (on the buttom or public function __construct($db)) it doesnt show me the value of the locations.

am i filling it wrong?
$field =‘l9948’;
$table =‘llx_product_extrafields’;

Hope you could help once more

GOT IT!!, i used the database prefix llx_. i didn’t need to. it’s working you sir are a very good person :slight_smile:

many many thanks!

One more question regarding the same funtion, i thought the DPF for receiving goods was the same idea
squille.modules.php, but it’s not.

Any idea were to put these lines in this php file, than i will stop asking :slight_smile:

The same idea, but different code for creation of the pdf.
Step1 + 2 are different

1:
add definition of column position in __construct(
) like
$this->posx<NAME> = $this->page_largeur - $this->marge_droite - <VALUE>;

		// Define position of columns
		$this->posxdesc = $this->marge_gauche + 1;
		$this->posxweightvol = $this->page_largeur - $this->marge_droite - 78;
		$this->posxqtyordered = $this->page_largeur - $this->marge_droite - 56;
		$this->posxqtytoship = $this->page_largeur - $this->marge_droite - 28;
		$this->posxpuht = $this->page_largeur - $this->marge_droite;

		if (!empty($conf->global->MAIN_PDF_RECEPTION_DISPLAY_AMOUNT_HT)) {
			$this->posxweightvol = $this->page_largeur - $this->marge_droite - 118;
			$this->posxqtyordered = $this->page_largeur - $this->marge_droite - 96;
			$this->posxqtytoship = $this->page_largeur - $this->marge_droite - 68;
			$this->posxpuht = $this->page_largeur - $this->marge_droite - 40;
			$this->posxtotalht = $this->page_largeur - $this->marge_droite - 20;
		}

Adapt the other integer values according to your wishes

2:
add in write_file(
) a similar block at desired position (is shown here before "Qty received)

	// <NAME>
	$pdf->SetXY($this->posx<NAME>, $curY);
       // <get value from ....  $myValue = get<FUNCTION>($object-lines[$i]-><ID>);
       // wrote get<FUNCTION> according to your requirements  
       // ID depends on what you want to retrieve
	$pdf->MultiCell(($this->posx<FOLLOWING_COLUMN> - $this->posx<NAME>), 3, $myValue, '', 'C');

	// Qty received
	$pdf->SetXY($this->posxqtytoship, $curY);
	$pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 3, $object->lines[$i]->qty, '', 'C');
        ....

I did this (displaying at the right position) with trial and error

3:
as written in my former posting (adapt to your requirements)

BTW: When I tried all this it was helpful for me to insert temporary var_dump() or print “” at appropriate places to get the object variables or look inside the relevant class file

did the following but i have the idea it’s incorrect as it’s not working :wink:

{removed the weight as we don’t use that function} adn replaced with posxlocation

// Define position of columns
	$this->posxdesc = $this->marge_gauche + 1;
            **$this->posxlocation = $this->page_largeur - $this->marge_droite - 118;**
	$this->posxqtyordered = $this->page_largeur - $this->marge_droite - 56;
	$this->posxqtytoship = $this->page_largeur - $this->marge_droite - 28;
	$this->posxpuht = $this->page_largeur - $this->marge_droite;

	if (!empty($conf->global->MAIN_PDF_RECEPTION_DISPLAY_AMOUNT_HT)) {
                    **$this->posxlocation = $this->page_largeur - $this->marge_droite - 118;**
		$this->posxqtyordered = $this->page_largeur - $this->marge_droite - 96;
		$this->posxqtytoship = $this->page_largeur - $this->marge_droite - 68;
		$this->posxpuht = $this->page_largeur - $this->marge_droite - 40;
		$this->posxtotalht = $this->page_largeur - $this->marge_droite - 20;
	}

Added again,

public function getLocation($id)
{
$field =‘l9948’;
$table =‘product_extrafields’;

		$sql = "SELECT ".$field." FROM ".MAIN_DB_PREFIX.$table;
		$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];
		  } // maybe we need a else case here 
	return $result;
}

// Posxlocation
$pdf->SetXY($this->posxlocation, $curY);
$myValue = getLocation($object-lines[$i]->$field);
$pdf->MultiCell(($this->posxqtyordered - $this->posxlocation), 3, $myValue, ‘’, ‘C’);

// Qty received
$pdf->SetXY($this->posxqtytoship, $curY);
$pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 3, $object->lines[$i]->qty, ‘’, ‘C’);

Could you help ?

The query for the location is wrong:
$object-lines[$i]->$field is unknown here and the syntax is also wrong.
There is a “>” missing.

Use $object->lines[$i]->fk_product, this is the rowid from table “llx_product”
In my general example <ID> has to be replaced with the proper object-field and this depends on what you want to retrieve from the tables.

$myValue = getLocation($object-lines[$i]->$field);

should be again

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

It’s a good idea to display the sql query to find possible errors like this:

print "<br>SQL-QUERY: ".$sql;

Add this line in your function getLocation(
)
Then you can execute the displayed sql query directly in phpmyadmin or a similar program and check the result if it is what you expected.

Thank you for the help but unfortiantly it’s still not showing.
also the columns are not shown on the PDF.
followed the instruction what you wrote, but it’s not showing up.

Sorry i don’t know anything about PDF files.
If you have another idea, i would love thearo it as alot of PDF’s in doli are written in this way.