PHP example
The PHP example is based on a PHP file Custom Label Generator.php, which is used to create a simple web application able to handle Pierbridge Label Requests and generate custom labels accordingly. This file can be modified to match the requirements of each project. The custom label generator uses following files:
- CustomLabelGenerator.php
- CustomLabelParameters.php
- LogFile.php
The CustomLabelGenerator.php consists of the main logic of the custom label generator. Without any modifications the label generator will receive a request from the system, which includes the data from Pierbridge Label Request, append these to the appropriate thermal code and send back the custom label content. The label type is chosen based on the Format parameter, which is received with the label request.
Access request properties
TopThe Pierbridge Label Request data will be stored in a number of CustomLabelParameters which provide an easy access to each individual field through a property. If necessary, access to these parameters can be obtained by:
require 'CustomLabelParameters.php'; $filter = $fieldOne;
Adding custom parameters
TopIf additional data is required it can be looked up from any data source. In the examples, these are the Shipping Order Header and Shipping Order Line Items tables. The connection details can be modified to match the server details:
$uid = ""; $pwd = ""; $database = "My Database"; $serverName = "(local)"; /* windows auth */ //$connectionString = array("Database" => $database); * sql server auth */ $connectionString = array("UID" => $uid, "PWD" => $pwd, "Database" => $database);$connection = sqlsrv_connect($serverName, $connectionString);
The example below shows how a value passed in through the Pierbridge Label Request in Field1 is used as a condition to look up a Record Key One value from Shipping Line Items table. ShipmentID and PackageID parameters are also available for CustomLabel types through Pierbridge Ship Request.
Required conditions or multiple return values should be added similarly to the sample below:
$query = "SELECT [Shipping Order Line Items].[Record Key Six] FROM [Shipping Order Line Items] JOIN [Shipping Order Header] ON [Shipping Order Line Items].[Shipping Order Header ID] = [Shipping Order Header].[ID]WHERE [Shipping Order Header].ID = ?"; $getReference = sqlsrv_query($connection, $query, array($filter)); $columnValue = sqlsrv_get_field($getReference, 0);
Creating thermal labels
TopBased on the requested label format the required thermal label type is selected:
if ($format == EPL) { $label .= "N"; ... } elseif ($format == ZPL) { $label .= "¬f165"; ... } elseif ($format == DPLl) { $label .= "~SD20"; ... } else { $log -> writeLog("Label format is not supported by label generator"); }
Both Request and custom parameters are added to all labels using parameter properties:
$label .= "A85,240,0,4,1,1,N," . $receiverName; $label .= "A85,270,0,4,1,1,N," . $receiverCompany; $label .= "A85,300,0,4,1,1,N," . $receiverAddress1; $label .= "A10,430,0,4,1,1,N," . "ADDITIONAL INFO"; $label .= "A85,430,0,4,1,1,N," . $columnValue;
Multiple labels
TopIf a single custom label generator is used to produce multiple labels these can be identified by using the available CustomLabelName parameter and configured in the Administration App Data > Reference Data > Custom Labels.
Multiple labels with a same CustomLabelName can also be added to a single thermal label by creating anumber of labels one after another:
//label 1 $label .= "N"; $label .= "OD10"; $label .= "q812"; $label .= "Q1218,24"; $label .= "D15"; $label .= "ZB"; $label .= "A10,30,0,1,1,1,N," . "FROM"; $label .= "A85,30,0,1,1,1,N," . $senderName; $label .= "P1"; $label .= "N"; //label 2 $label .= "N"; $label .= "OD10"; $label .= "q812"; $label .= "Q1218,24"; $label .= "D15"; $label .= "ZB"; $label .= "A10,30,0,1,1,1,N," . "FROM"; $label .= "A85,30,0,1,1,1,N," . $senderName; $label .= "P1"; $label .= "N";
Error logging
TopThe label generator uses a log file for error logging in case any error occurs. The error messages are written in a log file. The error log path is configured in the LogFile.php file and should be modified to match the installation.
if ($file = @fopen("C:/Temp/Custom Label Generator/PHPLog.txt", "a+")) {}
Error messages are customizable and can be changed:
$log -> writeLog("No Data returned with: filter: " . $filter . " ." . $e -> getMessage());
- Custom Label Generator toolkit introduces the toolkit and the role of Custom Label Generators in Transtream. It also covers basic use of the toolkit.