Print Product Barcodes

Just installed and setup the on-prem (Windows) version and I’m loving it so far.

Most of the other POS systems I’ve used have had an ability to print a barcode label either during stock take, or, at least on the product page, there’s usually a button to print the item label/barcode.

I don’t seem to see that here. The only thing I do see is the Tools > Print Barcodes option.

Are there any other ways to print (and also customize what’s on them) product labels? Tried searching google and the forums… didn’t pull up much.

Thanks

Please check Setup > modules/applications > Barcode and click on settings wheel.

thanks
yesbee

thanks yesbee… i do have that installed…
what I’m asking for is… on most other products, there’s a way, from the item/product screen to print the barcodes and also potentially configure them, to add things like pricing info, description info, etc.

I don’t seem to see that here. The only thing I seem to get is the ability on that screen to AFTER I put the part in, search the Tools > Barcodes section in order to print individual labels.

HI. did you find a answer on this, I was hoping there is a solution,

Hi,
we have added this functionality, but it requires some changes in the source files.

We use Dolibarr in the cloud and the QR code is printed on a label printer connected to a print-server in our office.
Therefore, our modification is special, but it may give some hints on how to solve the QR code printing problem.

In \htdocs\product\card.php we have added a new action “printbarcode” and a button that triggers this action.
This action in turn finally triggers a URL with the print parameters.

…new action “printbarcode”:

	// Print QR-Code value
	if ($action == 'printbarcode') {
			$action = '';
			if (!$notrigger) {
			// Call trigger
				$result = $object->call_trigger('PRODUCT_PRINT_QR', $user);
				if ($result < 0) {
					$error++;
				}
			}	
			// End call triggers
			header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
			exit;
	}

…new button “Print QR-Code”:

		// barcode set and !empty and type=QR-Code
		if (isset($object->barcode) && ($object->barcode <> '') && $object->barcode_type == '8') {
			print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=printbarcode&id='.rawurlencode($object->id).'&token='.newToken().'">'.$langs->trans("Print QR-Code").'</a>';
		}

For this we copied the \htdocs\core\triggers\interface_99_modZapier_ZapierTriggers.class.php and adapted it for my needs.
As you can see, we have also added other actions for printing serial numbers from the MRP module.

		switch ($action) {
			case 'PRODUCT_PRINT_QR':
				$object->user = $user->accountancy_code;	// User Short
				$cleaned = cleanObjectDatas(dol_clone($object));
				$json = json_encode($cleaned);
				$type = 0;
				// call the QRCodePostWebhook() function
				QRCodePostWebhook($type, $obj['url'], $json);
				$logtriggeraction = true;
				break;
            // get lot/serial
			case 'PRODUCT_LOT_PRINT_QR':
			case 'MRP_LOT_PRINT_QR':
				$sql = 'SELECT pl.rowid, p.ref as `pref`, mp.fk_mo, mo.ref, pl.tms
					FROM '.MAIN_DB_PREFIX.'product_lot pl
					LEFT JOIN '.MAIN_DB_PREFIX.'mrp_production mp ON mp.batch = pl.batch 
					LEFT JOIN '.MAIN_DB_PREFIX.'mrp_mo mo ON mo.rowid = mp.fk_mo 
					LEFT JOIN '.MAIN_DB_PREFIX.'product p ON p.rowid = pl.fk_product 
					WHERE pl.batch = "'.$object->barcode.'"';
				$resqlC = $this->db->query($sql);
				$result = $this->db->fetch_array($resqlC);

				$object->user = $user->accountancy_code;	// User Short
				$cleaned = cleanObjectDatas(dol_clone($object));
				$cleaned->id = $result['rowid'];
				$cleaned->name = $result['ref']." (".$result['tms'].")";
				$cleaned->ref = $result['pref'];

				$json = json_encode($cleaned);
				$type = 2;
				// call the QRCodePostWebhook() function
				QRCodePostWebhook($type, $obj['url'], $json);
				$logtriggeraction = true;
				break;

            // some more cases followed but not shown here... 
        }

function QRCodePostWebhook($typ, $url, $json)
{
	$qr = json_decode($json);	// extrahiere parameter
	$curl = curl_init();
	switch($typ) {
		case 0:
            $fields = http_build_query(array(
            "typ"  => "card",
            "pos1" => $qr->barcode,
            "pos2" => $qr->description,
            "pos3" => urldecode($qr->label),
            "pos4" => $qr->user,
			"ret"  => $qr->id
            ));
            $url = "https://xxx.xxx.xxx.xxx/printQRCode_Doli.php?".$fields; 
			break;
		case 2:
             $fields = http_build_query(array(
             "typ"  => "charge",
             "pos1" => $qr->barcode,
             "pos2" => $qr->ref,
             "pos3" => urldecode($qr->label),
             "pos4" => $qr->name,
			 "ret"  => $qr->id
             ));
             $url = "http://xxx.xxx.xxx.xxx/printQRCode_Doli.php?".$fields;
			break;
	}

      curl_setopt($curl, CURLOPT_URL, $url);

	$request = "GET";
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_TIMEOUT, 5); //timeout in seconds
    $headers = array(
	   "accept: application/json",
	   "Content-Type: application/json",
	);
	curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request);
	curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
	//for debug only!
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

        $result = curl_exec($curl);

        if($result) {
            setEventMessages('Label mit QR-Code wurde gedruckt...', null, 'mesgs');
        } else {
            setEventMessages('Druck des QR-Code-Labels ist fehlgeschlagen...', null, 'errors');
        }    
	// Decode the result for debug
	$resultData = json_decode($result, true);
	curl_close($curl);
}

...

In the web interface it looks like this:

From the MRP-Module:

From the LOT-Module:

The printed label looks like this: (not the same numbers as in the examples :wink:)

Hope this helps…

Ok thanks, will look at that

Hello Bro

I successfully make the modifications for the \product\card.php
I see the button ’ PRINT QR-CODE ’ , at the right bottom of my producto page

When I try to print, nothing happen, the url i see on the button was:
https://www.webiste.com/my_folder/product/card.php?action=printbarcode&id=35&token=1af4caeee8f87d2a4950594038f3b1f3cc

I get the file ( interface_99_modZapier_ZapierTriggers.class.php ) here :interface_99_modZapier_ZapierTriggers.class.php

I modify it andput my personal URL

$url = “://xxx.xxx.xxx.xxx/printQRCode_Doli.php?”.$fields;

but nothing
Where can i find the file printQRCode_Doli.php ?

Hi Bernd,
would you be able to share eigther the modified files or a little bit more in dept description.
What you did is exactly what I need for my system. But wasn’t able to make it work so far.
Thanks a million.

Hi,
I can share more details but at the moment I have no access to the server.
Please give me some days….

1 Like

The printQRCode_Doli.php looks like the following:
You can see that we use the library “phpqrcode”
The generation and printing out the QR-Code is finally done in “QRCode.php”.


<?php
// file: printQRCode_Doli.php

// some includes
include('phpqrcode/qrlib.php'); 
include('QRCode.php');

 if(isset($_GET['pos1'])) {
 	$pos1 = $_GET['pos1'];
	if(empty($pos1)) {
	  $pos1=' ';
	}
 }else{
	$pos1='';
 }	

 if(isset($_GET['pos2'])) {
 	$pos2 = $_GET['pos2'];
	if(empty($pos2)) {
	  $pos2=' ';
	}
 }else{
	$pos2='';
 }	

 if(isset($_GET['pos3'])) {
 	$pos3 = $_GET['pos3'];
	if(empty($pos3)) {
	  $pos3=' ';
	}
 }else{
	$pos3='';
 }

 if(isset($_GET['pos4'])) {
 	$pos4 = $_GET['pos4'];
	if(empty($pos4)) {
	  $pos4=' ';
	}
 }else{
	$pos4=' ';
 }	

 if(isset($_GET['typ'])) {
 	$type = $_GET['typ'];
	if(empty($type)) {
	  $type=' ';
	}
 }else{
	$type='';
 }	

 $ret = $_GET['ret'];

file_put_contents('/tmp/qrcode.log', $pos1."|".$pos2."|".$pos3."|".$pos4."|".$type."|".$ret."\n", FILE_APPEND);

printQRCodeDolibarr($pos1,$pos2,$pos3,$pos4,$type,$ret);
	
exit;

?>

The file QRCode.php looks like:
(you can modify the $codeContents to link to other pages in Dolibarr, but we decided that these links are usefull. In case of other links you have to modify/reference the proper ID.)
BTW: You can see the resulting printed labels on my earlier post. If you use another label-printer you have to adapt to your needs.

<?
function printQRCodeDolibarr($pos1,$pos2,$pos3,$pos4,$type,$ret)
{
header('Content-Type: text/html; charset=utf-8');
    $tempDir = "temp/"; 

	switch ($type) {
		case 'card':
			# We still have an intermediate step to correctly resolve "old" QR-Codes in our old read-only DB. 
			# This is done using "sys=doli", which the old QR-Codes don't have.
			# same on case 'charge'
			# $codeContents = "http://<our_url>/type.php?id=".urlencode($ret)."&sys=doli";

			# gibt ID als Zielwert 
			$codeContents = "http://<your_dolibarr_url>/product/stock/productlot_card.php?id=".urlencode($ret);
			break;
		case 'charge':
			# $codeContents = "http://<our_url>/part.php?id=".urlencode($ret)."&sys=doli";
			# gibt ID als Zielwert 
			$codeContents = "http://<your_dolibarr_url>/product/card.php?id=".urlencode($ret);
			break;
	}

#echo $codeContents;
#echo "<br>";

    // we need to generate filename somehow,  
    // with md5 or with database ID used to obtains $codeContents... 
    $QRfileName = 'qrcode_'.md5($codeContents).'.png'; 
	$fileName = 'qrcodeT_'.md5($codeContents).'.png'; 
     
    $pngAbsoluteFilePath = $tempDir.$fileName; 
	$QRAbsoluteFilePath = $tempDir.$QRfileName; 
	
    $urlRelativeFilePathQR = 'temp/'.$QRfileName; 
	$urlRelativeFilePath = 'temp/'.$fileName; 
     
    // generating 
    QRcode::png($codeContents, $QRAbsoluteFilePath); 
    
    echo 'Server PNG File: '.$pngAbsoluteFilePath; 
    echo '<hr />'; 
     
    // displaying 
    echo '<img src="'.$urlRelativeFilePathQR.'" />'; 
	
	$im = imagecreatefrompng($QRAbsoluteFilePath);
	//imagesavealpha($im, true); // important to keep the png's transparency 
	if(!$im) {
		die("im is null");
	}
	$black = imagecolorallocate($im, 0, 0, 0);
	list($width, $height) = getimagesize($QRAbsoluteFilePath);
	
	$QL700width = 756;
	
	$largeQRpercentage = 0.5;
	$smallQRpercentage = 0.25;
	$heightLargerPercentage = 1.1;
	$newheight = $heightLargerPercentage*$height*$QL700width/$width*$largeQRpercentage ; // the height of the image
	
	$font = 6; // font size
	$leftTextPos = 10; // left position text
	
	$newImage = imagecreate($QL700width,$newheight);
	$QLImage = imagecreatetruecolor($QL700width,$newheight);
	imagecopyresampled($newImage,$im,0,10,0,0,$QL700width,$newheight/$heightLargerPercentage,$width/$largeQRpercentage,$height);
	imagecopyresampled($newImage,$im,$largeQRpercentage*$QL700width,20,0,0,$QL700width,$newheight/$heightLargerPercentage,$width/$smallQRpercentage,$height*$largeQRpercentage/$smallQRpercentage);
	imagecopyresampled($newImage,$im,($largeQRpercentage + $smallQRpercentage)*$QL700width,20,0,0,$QL700width,$newheight/$heightLargerPercentage,$width/$smallQRpercentage,$height*$largeQRpercentage/$smallQRpercentage);
	
	#-------------------------------------------------------------
    $label = $pos1;
    $labelfont = 4;
	$labelfont_large = 4;
	// pixel-width of label
	$txtsz = imagefontwidth($labelfont) * strlen($label);
	$txtsz_large = imagefontwidth($labelfont_large) * strlen($label);
	// pixel-height of label
	$txtht = imagefontheight($labelfont);
	$txtht_large = imagefontheight($labelfont_large);
	$labelimage = imagecreate($txtsz,$txtht);
	$labelimage_large = imagecreate($txtsz_large,$txtht_large);
	
	$white = imagecolorallocate($labelimage, 0xFF, 0xFF, 0xFF);
	$black = imagecolorallocate($labelimage, 0x00, 0x00, 0x00);
	$white = imagecolorallocate($labelimage_large, 0xFF, 0xFF, 0xFF);
	$black = imagecolorallocate($labelimage_large, 0x00, 0x00, 0x00);
	
	imagestring($labelimage, $labelfont_large, 0, 0, $label , $black);
	imagecopyresampled($newImage,$labelimage,40,0,0,0,3*$txtsz_large, 3*$txtht_large,$txtsz_large, $txtht_large);
	imagestring($labelimage, $labelfont, 0, 0, $label , $black);
	$labelimage1 = imagerotate($labelimage, -90, $white);
	imagecopyresampled($newImage,$labelimage1,$largeQRpercentage*$QL700width-10,40,0,0,2*$txtht, 0.8*$smallQRpercentage*$QL700width,$txtht, $txtsz);
	imagecopyresampled($newImage,$labelimage1,($largeQRpercentage + $smallQRpercentage)*$QL700width-10,40,0,0,2*$txtht, 0.8*$smallQRpercentage*$QL700width,$txtht, $txtsz);
	
	#-------------------------------------------------------------
    $label = "ID: ".$pos2;
	$txtsz = imagefontwidth($labelfont) * strlen($label);
	$txtht = imagefontheight($labelfont);
	$labelinfo = imagecreate($txtsz,$txtht);
	$white = imagecolorallocate($labelinfo, 0xFF, 0xFF, 0xFF);
	$black = imagecolorallocate($labelinfo, 0x00, 0x00, 0x00);
	imagestring($labelinfo, $labelfont, 0, 0, $label, $black);
	imagecopyresampled($newImage,$labelinfo,$largeQRpercentage*$QL700width-10,$smallQRpercentage*$QL700width+5,0,0,3*$txtsz, 3*$txtht,$txtsz, $txtht);
	
	#-------------------------------------------------------------
    $label = $pos3;
    $labelfont = 7;
	$labelfont_large = 6;
	$txtsz = imagefontwidth($labelfont) * strlen($label);
	$txtht = imagefontheight($labelfont);
	$labelinfo = imagecreate($txtsz,$txtht);
	$white = imagecolorallocate($labelinfo, 0xFF, 0xFF, 0xFF);
	$black = imagecolorallocate($labelinfo, 0x00, 0x00, 0x00);
	// imagestring($labelinfo, $labelfont, 0, 0, $label, $black);
    // changed to TrueType-Font for correct display of german umlauts
	$font = '/usr/share/fonts/truetype/droid/DroidSans.ttf';
	imagettftext($labelinfo, $labelfont, 0, 0, 10, $black, $font, $label);
	// imagestring($labelinfo, $labelfont, 0, 0, $label, $black);
	imagecopyresampled($newImage,$labelinfo,$largeQRpercentage*$QL700width-10,$smallQRpercentage*$QL700width+50,0,0,2*$txtsz, 3*$txtht,$txtsz, $txtht);

	#-------------------------------------------------------------
    $label = $pos4;
   	$labelfont = 2;
	$labelfont_large = 2;
	$txtsz = imagefontwidth($labelfont) * strlen($label);
	$txtht = imagefontheight($labelfont);
	$labelinfo = imagecreate($txtsz,$txtht);
	$white = imagecolorallocate($labelinfo, 0xFF, 0xFF, 0xFF);
	$black = imagecolorallocate($labelinfo, 0x00, 0x00, 0x00);
	imagestring($labelinfo, $labelfont, 0, 0, $label, $black);
	imagecopyresampled($newImage,$labelinfo,$largeQRpercentage*$QL700width-10,$smallQRpercentage*$QL700width+90,0,0,2*$txtsz, 3*$txtht,$txtsz, $txtht);

	imagepng($newImage, $pngAbsoluteFilePath, 0);
	imagedestroy($im);
	imagedestroy($labelimage1);
	imagedestroy($labelinfo);
	imagedestroy($labelimage);
	echo '<img src="'.$urlRelativeFilePath.'" />'; 
	
	// printing to QL-700
	shell_exec("lp -d QL-700 -o orientation-requested=6 ".$pngAbsoluteFilePath);
}
	
?>	

So many thanks,

I’m going to test your work asap !!
I’ll tell you today what’s happen for me

So, So, So many thanks
I appreciate it

Hello DG-Rilling

I make all the necessary, but always some interogations from my part
Sorry

I resume:

File: htdocs/…/product/card.php

and

File: htdocs/…/core/triggers/interface_99_modZapier_ZapierTriggers.class.php

and
I change the name of my website of course

Then, I created the files here:
htdocs/…/product/printQRCode_Doli.php
htdocs/…/product/QRCode.php

I change the name of my website of course

It’s happen nothing

1°) Could you tell me where did you put your printQRCode_Doli.php and QRCode.php ?
2°) Where can i have this qrlib.php ?
image

Sorry for the disturb…

The description is based on our configuration with <Dolibarr (Cloud) <–INTERNET–> WebServer with LabelPrinter (Local)>

Therefore are both files
“printQRCode_Doli.php” and “QRCode.php” located on the local-pc where the labelprinter is connected. Printing is finally done with the "shell_exec(“lp -d QL-700 …”)

If you are running Dolibarr on a local machine with labelprinter directly connected then you don’t need the “printQRcode_Doli.php”
because in the function QRcodePostWebHook(…) you have all the variables for the label.
And Dolibarr has the functionality to produce the QR-Code, look at htdocs\includes\tecnickcom\tcpdfhtdocs/include
There you will find the library and also some examples.

1 Like

thank you Bro.

I appreciate it

have a nice day