<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>barcode testing</title>
</head>
<body>
<!-- <img src="./php-barcode-master/barcode.php?text=asdasdasda asdasd 0"> -->
<?php
	// include 'php-barcode-master/barcode.php';
	include('php-barcode-generator-master/src/BarcodeGenerator.php');
	include('php-barcode-generator-master/src/BarcodeGeneratorPNG.php');
	include('php-barcode-generator-master/src/BarcodeGeneratorSVG.php');
	include('php-barcode-generator-master/src/BarcodeGeneratorJPG.php');
	include('php-barcode-generator-master/src/BarcodeGeneratorHTML.php');
	include 'connect61.php';
	$sql="SELECT
			a.[ct_no]
			,a.[ps_id]
			,a.[ps_name]
			,b.[TI_NAME]		
			,b.[PS_FNAME]
			,b.[PS_LNAME]
			,b.[PS_PHONE]
			,b.[PS_MOBILE]
			,b.[CD_DATA]
			,a.[ct_date]
			,a.[br_id]
			,a.[sbr_id]
			,a.[price]
			,a.[payamnt]
			,a.[due_amnt]
			,a.[due_count]
			,a.[product_id]
			,a.[product_name]
			,a.[serial_no]
			,a.[status]
			,a.[cnsvrefno]
			,a.[cnsvrefcode]
		FROM [EHONGDB].[dbo].[hps_ctmain] a
			left outer join(
				SELECT
					[PS_ID]
					,[TI_NAME]
					,[PS_FNAME]
					,[PS_LNAME]
					,[PS_PHONE]
					,[PS_MOBILE]
					,[CD_DATA]
					,[img_path]
				FROM [EHONGDB].[dbo].[PERSON]) b on (a.ps_id=b.PS_ID)
		where cnsvrefno is not null and cnsvrefcode != 'NULL' and cnsvrefcode is not null and status like 'N' ";
	$stmt = $dbh->prepare($sql,array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
	$stmt->execute();
	// $i=0;
	// while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
	// 	$detail=["สินค้า"=>$row['product_name'],"รหัสอ้างอิง"=>$row['cnsvrefcode'],"เลขที่สัญญา"=>$row['ct_no'],"ค่างวด"=>$row['due_amnt'],"รหัสลูกค้า"=>$row['ps_id'],"ชื่อ"=>$row['TI_NAME'].$row['PS_FNAME']."  ".$row['PS_LNAME']];
	// 	$filepath="barcode/".$row['cnsvrefcode'].".jpg";
	// 	$text=$row['cnsvrefno'].char(13).$row['cnsvrefcode'].char(13).char(13).'0';
	// 	$size=120;
	// 	$sizefactor=2;
	// 	barcode( $filepath, $text, $size, $orientation, $code_type, $print, $sizefactor ,$detail);
	// 	$i++;
	// 	echo "$i ---  $text<br>";
	// 	//print_r($detail);
	// }
	$i=1;
	while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
		$textarr=array($row['cnsvrefno'],$row['cnsvrefcode'],"0");
		$detail=["สินค้า"=>$row['product_name'],"รหัสอ้างอิง"=>$row['cnsvrefcode'],"เลขที่สัญญา"=>$row['ct_no'],"ค่างวด"=>$row['due_amnt'],"รหัสลูกค้า"=>$row['ps_id'],"ชื่อ"=>$row['TI_NAME'].$row['PS_FNAME']."  ".$row['PS_LNAME'],"code"=>$row['cnsvrefno'].' '.$row['cnsvrefcode'].' '.'0'];
		$filepath="barcode/".$row['cnsvrefcode'].".jpg";
		// $filepath="test/".$row['cnsvrefcode'].".jpg";
		$generator = new Picqer\Barcode\BarcodeGeneratorJPG();
		echo $i." ".$generator->getBarcode($textarr[0].chr(13).$textarr[1].chr(13).' '.chr(13).$textarr[2], $generator::TYPE_CODE_128,2,100,array(0, 0, 0),$filepath,$detail)."<br>";
		unset($generator);
		unset($row);
		unset($textarr);
		unset($detail);
		$i++;
	}
?>
</body>
</html>