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
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)
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
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
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â)) "
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;
}
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â;
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
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;
}
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.
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.