Hey guys,

I'm writing a small script that will print pick lists for our online orders using the printer functions provided with the stock extension. The problem is I can't get it to span across multiple pages. I've tried checking the Y position and using end_page and start_page accordingly but for some reason it's locking up. Here's my code, I'm only commenting the bit that's not working so if you need some clarification on something just ask.

$order = $_GET['id'];

function printPick($orderNum){
$connection = mssql_connect("127.0.0.1", "foo", "bar");
if (!$connection){
echo "failed to connect to database";
exit;
}else{
mssql_select_db("fooBar");
}

$handle = printer_open("P1"); 
printer_start_doc($handle, "Order $orderNum"); 
printer_start_page($handle);
$headerFont = printer_create_font("Arial", 144, 96, 400, false, false, false, 0);
printer_select_font($handle, $headerFont);
printer_draw_text($handle, "Movies 4 Sale Pick List | Order: $orderNum", 10, 10);
printer_delete_font($headerFont);
$itemFont = printer_create_font("Arial",72,48,400,false,false,false,0);
printer_select_font($handle, $itemFont);

$resultDisp = mssql_query("select * from customerOrders where id = '$orderNum'");
$totalPeices = mssql_num_rows($resultDisp);
$y = 210;
$pUser = 0;
while ($rowDisp = mssql_fetch_array($resultDisp)){
	$cId = $rowDisp['customerId'];
	$title = substr($rowDisp['title'], 0, 24);
	$upc = $rowDisp['upc'];
	$quantity = $rowDisp['quantity'];
	if ($pUser == 0){
		$resultCust = mssql_query("select * from users where id = '$cId'");
			while ($rowCust = mssql_fetch_array($resultCust)){
				$cName = $rowCust['contactName'];
				$cPhone = $rowCust['contactPhone'];
				$cCompany = $rowCust['companyName'];
				$addr1 = $rowCust['address1'];
				$addr2 = $rowCust['address2'];
				$city = $rowCust['city'];
				$state = $rowCust['state'];
				$zip = $rowCust['zip'];
			}
		printer_draw_text($handle, "", 10, $y);
		$y = $y + 100;
		printer_draw_text($handle, "Customer Information:", 10, $y);
		printer_draw_text($handle, "Total Pieces Ordered: $totalPeices", 2410, $y);
		$y = $y + 100;
		printer_draw_text($handle, "Company Name: $cCompany", 10, $y);
		printer_draw_text($handle, "Total Pieces Shipped: ____", 2410, $y);
		$y = $y + 100;
		printer_draw_text($handle, "Contact Name: $cName", 10, $y);
		$y = $y + 100;
		printer_draw_text($handle, "Phone Number: $cPhone", 10, $y);
		$y = $y + 100;
		printer_draw_text($handle, "Address: $addr1 $addr2", 10, $y);
		$y = $y + 100;
		printer_draw_text($handle, "$city, $state $zip", 10, $y);
		$y = $y + 100;
		printer_draw_text($handle, "", 10, $y);
		$y = $y + 100;
		printer_draw_text($handle, "Title", 10, $y);
		printer_draw_text($handle, "UPC", 1310, $y);
		printer_draw_text($handle, "Quantity", 3110, $y);
		printer_draw_text($handle, "Picked", 3610, $y);
		$y = $y + 100;
		$pen = printer_create_pen(PRINTER_PEN_SOLID, 2, "000000"); 
		printer_select_pen($handle, $pen); 
		printer_draw_line($handle, 1, $y, 4000, $y + 1); 
		printer_delete_pen($pen); 
		$y = $y + 100;
		$pUser = 1;
	}

	//data
	printer_draw_text($handle, "$title", 10, $y);
	printer_draw_text($handle, "$upc", 1310, $y);
	printer_draw_text($handle, "$quantity", 3110, $y);
	printer_draw_text($handle, "_____", 3610, $y);
	$y = $y + 100;
	$pen = printer_create_pen(PRINTER_PEN_SOLID, 2, "000000"); 
	printer_select_pen($handle, $pen); 
	printer_draw_line($handle, 1, $y, 4000, $y + 1); 
	printer_delete_pen($pen); 
	if ($y == 6210){
		printer_end_page($handle);
		printer_start_page($handle);
		$y = 110;

// that SHOULD tell it to start a new page, correct? I still only get one page of text each time I print. I know there's enough data to fill atleast 3 pages.
}
$y = $y + 100;
}

printer_delete_font($itemFont); 

printer_end_page($handle); 
printer_end_doc($handle); 
printer_close($handle); 

}
if ($order != ""){
printPick($order);
}else{
echo "Sorry, you must supply an order number to print a pick list!";
}
?>

What am I doing wrong here? I've searched through tons of google's to find an example of someone doing this but all I can find are endless amounts of manual entries on the same functions. Little help?

-Chris

    Write a Reply...