<?php defined('BASEPATH') OR exit('No direct script access allowed');
$this->currency_symbol = get_company('symbol');
$salModCodes = get_company('salModCodes');
$salModCodes = explode(',',$salModCodes);
		


/*
// Hardcoded for testing

$barcode["cols"] = 3;
$barcode["rows"] = 10;

$barcode["lines"][1]["font"] = "N";

*/

$showBorder = false;
$border = "1mm solid #000;";
$padding = 0; // mm

if (empty($barcode["cols"]))
{
	$barcode["cols"] = 1;
}

if (empty($barcode["rows"]))
{
	$barcode["rows"] = 1;
}

$width = $barcode["width"];
$height = $barcode["height"];

// Multiply by 2 incase mpdf right & bottom margin assign same as top & left.
$width = ($width - (($barcode['leftMargin'] * 1) / 10));
$height = ($height - (($barcode['topMargin'] * 1) / 10));

// Threshold
$width -= 0.1;
$height -= 0.1;

$lableWidth = !empty($barcode['lableWidth']) ? $barcode['lableWidth'] : ($width / $barcode["cols"]);
$lableHeight = !empty($barcode['lableHeight']) ? $barcode['lableHeight'] : ($height / $barcode["rows"]);

if ($showBorder)
{
	$lableWidth -= 0.1;
	$lableHeight -= 0.1;
}

// $columnSpacing = $barcode['rightMargin'] / 10;
// $rowSpacing = $barcode['bottomMargin'] / 10;

// $barcode['rightMargin'] = 1;

$barcode["rPadding"] = $barcode['rightMargin'];
$barcode["bPadding"] = $barcode['bottomMargin'];

// Padding 2 mm each side (top + bottom = 4mm, left + right = 4mm)
$paddingStyles = "";
if (!empty($barcode["lPadding"]))
{
	$lableWidth -= ($barcode["lPadding"] / 10);
	$paddingStyles .= 'padding-left:' . $barcode["lPadding"] . 'mm;' . PHP_EOL;
}
if (!empty($barcode["rPadding"]))
{
	$lableWidth -= ($barcode["rPadding"] / 10);
	$paddingStyles .= 'padding-right:' . $barcode["rPadding"] . 'mm;' . PHP_EOL;
}
if (!empty($barcode["tPadding"]))
{
	$lableHeight -= ($barcode["tPadding"] / 10);
	$paddingStyles .= 'padding-top:' . $barcode["tPadding"] . 'mm;' . PHP_EOL;
}
if (!empty($barcode["bPadding"]))
{
	$lableHeight -= ($barcode["bPadding"] / 10);
	$paddingStyles .= 'padding-bottom:' . $barcode["bPadding"] . 'mm;' . PHP_EOL;
}

$lableWidth = floor($lableWidth * 100) / 100;
$lableHeight = floor($lableHeight * 100) / 100;

$from_row = !empty($from_row) ? $from_row : 1;
$from_col = !empty($from_col) ? $from_col : 1;

$qty = !empty($qty) ? $qty : 1 ;
if(!empty($items)&& $items[0]['itemName'] == 'Item Name'){
	$qty = $barcode["cols"] * $barcode["rows"];
}
/*
$barCodeSize	= array("S" => 0.75,"N" => 1,	"B" => 1.5,	"L" => 2 );
$barCodeHeight	= array("S" => 0.7,	"N" => 0.7,	"B" => 0.8,	"L" => 0.8 );
*/

$barCodeSize	= array("S" => 0.65,"N" => 1,	"B" => 1.5,	"L" => 2 );
$barCodeHeight	= array("S" => 0.7,	"N" => 0.7,	"B" => 0.8,	"L" => 0.8 );
$salSettings = get_company("salSettings");
if (!empty($salSettings))
{
	$currFraction = !empty($salSettings["currFraction"]) ? $salSettings["currFraction"] : (get_company("fraction") ? get_company("fraction") : 2);
	$rateFraction = !empty($salSettings["rateFraction"]) ? $salSettings["rateFraction"] : 0;
}

$aligns = array(
	"L"	=> "text-align:left;",
	"C"	=> "text-align:center;",
	"R"	=> "text-align:right;"
);

?>
<html>
	<head>
		<style>
			body {
				font-family: sans-serif;
				font-size: 10pt;
			}
			div {
				line-height: 1.3;
			}
			h5, p {
				margin: 0pt;
			}
			.row {
				display: inline-block;
				float: left;
				clear: both;
			}
			.row .main {
/*
				background-color: #AAA;
*/
				display: inline-block;
				float: left;
				text-align: center;
				vertical-align: middle;
				width:<?php echo $lableWidth; ?>cm;
				height:<?php echo $lableHeight; ?>cm;
				<?php
					if (!empty($paddingStyles))
					{
						echo $paddingStyles;
					}
				?>
/*
				padding: <?php // echo $padding; ?>mm;
*/
/*
				padding-right: <?php // echo $columnSpacing; ?>cm;
				padding-bottom: <?php // echo $rowSpacing; ?>cm;
*/
/*
				margin-right: <?php // echo $columnSpacing; ?>cm;
				margin-bottom: <?php // echo $rowSpacing; ?>cm;
*/
<?php if ($showBorder) { ?>
				border-right: <?php echo $border; ?>;
				border-bottom:<?php echo $border; ?>;
<?php } ?>
			}
			.row .main .bold {
				font-weight: bold;
			}
			.row .main .line {
				width: <?php echo $lableWidth - 0.2; ?>cm;
				float: left;
				padding-right: 1mm;
				padding-left: 1mm;
				
			}
			.row .main .lineQuartL {
				width: <?php echo ($lableWidth/3) - 0.2; ?>cm;
				float: left;
				padding-left: 1mm;
			}
			.row .main .lineQuartR {
				width: <?php echo ($lableWidth/3) - 0.2; ?>cm;
				float: left;
				padding-right: 1mm;
			}
			.row .main .lineL {
				width: <?php echo ($lableWidth/2) - 0.2; ?>cm;
				float: left;
				padding-left: 1mm;
			}
			.row .main .lineR {
				width: <?php echo ($lableWidth/2) - 0.2; ?>cm;
				float: left;
				padding-right: 1mm;
			}
			.fS {
				font-size: 10px;
			}
			.fN {
				font-size: 16px;
			}
			.fB {
				font-size: 22px;
			}
			.fL {
				font-size: 32px;
			}
			.LfS {
				font-size: 22px;
			}
			.LfN {
				font-size: 30px;
			}
			.LfB {
				font-size: 35px;
			}
			.LfL {
				font-size: 40px;
			}
			.cQR {
				max-width: 50%;
			}
			.cQR, .QR {
				display: inline-block;
				text-align: left;
			}
			.wsnw {
				white-space: nowrap;
			}
		</style>
		<!-- style>
		table.barcode {
<?php
		if ($showBorder)
		{
?>
			border-left:1px dashed #EEE;
			border-top:1px dashed #EEE;
<?php
		}
?>
		}
		table.barcode tbody tr td.main {
			text-align: center;
			vertical-align: middle;
			width:<?php // echo $lableWidth; ?>cm;
			height:<?php // echo $lableHeight; ?>cm;
			padding-left: <?php // echo $columnSpacing; ?>cm;
			padding-top: <?php // echo $rowSpacing; ?>cm;
<?php
			if ($showBorder)
			{
?>
				border-right: 1px dashed #EEE;
				border-bottom:1px dashed #EEE;
<?php
			}
/*
			border-right:1px dashed #000;
			border-bottom:1px dashed #000;
*/
?>
		}
		.barcode {
			padding: 1.5mm;
			margin: 0;
			vertical-align: top;
			color: #000000;
		}
		.barcodecell {
			text-align: center;
			vertical-align: middle;
			padding: 0;
		}
		
		table.qr tbody td {
			text-align: left;
		}
		td {
			padding : 0px !important;
		}
		</style -->
	</head>
	<body style="margin:0 auto;">
		<?php
			$tdWid = 'width:' . (100 / $barcode['cols']) . '%;';
			$html = "";
			$lines = is_array($barcode['lines']) ? $barcode['lines'] : json_decode($barcode['lines'], true);

			$labels = $_imgArr = array();
			
			if ($from_col > 1)
			{
				for ($i=0; $i<$from_col-1; $i++)
				{
					// $labels[] = '<div style="' . $tdWid . '" class="main"></div>';
					$labels[] = '<div class="main"></div>';
				}
			}
			
			$r=1;$c=1;

			function enc_replace($text, $ln)
			{ 
				//Got error if special characters are present in $ln['enc'] .Removed special characters 
				$ln['enc'] =  !empty($ln['enc']) ? preg_replace('/[^A-Za-z0-9\-]/', '', $ln['enc']) : ''; 
				if (!empty($ln["enc"]))
				{
					$text = round(floatval($text));
					return str_replace(array(0,1,2,3,4,5,6,7,8,9), str_split($ln["enc"], 1), $text);
				}

				return $text;
			}

			foreach ($items as $item)
			{
				$customTxtReplacer = array(
					"{tDate}"	=> !empty($item["tDate"]) ? $item["tDate"] : "",
					"{tNo}"		=> !empty($item["tNo"]) ? $item["tNo"] : "",
					"{conId}"	=> !empty($item["conId"]) ? $item["conId"] : "",
					"{conName}"	=> !empty($item["conName"]) ? $item["conName"] : ""
				);

				$item["saleRate"] = (!empty($item["saleRate"]) && (int)$item["saleRate"]) ? $item["saleRate"] : "";
				$item["mrp"] = (!empty($item["mrp"]) && (int)$item["mrp"]) ? $item["mrp"] : "";
				$item["rate"] = (!empty($item["rate"]) && (int)$item["rate"]) ? $item["rate"] : "";
				$item['currencyCode'] = !empty($item['currencyCode']) ? $item['currencyCode'] : $currencyCode;
				$bar_html = "";
				$infoHtml = "";
				$isQr = false;
				//page is variable from stockjrnl page .For stockjrnl qty will be considered as value given in no of copies input box
				if (!empty($item["qty"]))
				{
					$qty = $item["qty"]-0;
				}

				$hasLeft = false;
				
				$infoHtml .= '<div style="width:100%;">';
				// $infoHtml .= '<div>';
				$infoHtmlArr= array();
				$tmpInfoHtml = "";
				
				foreach ($lines as $ln)
				{
					if (empty($ln["align"]))
					{
						$ln["align"] = "C";
					}

					$ln["bold"] = !empty($ln["bold"]) ? "bold" : "";

					$fontSize = ($ln["font"] == 'C' && !empty($ln["fontSize"])) ? ("font-size:" . $ln["fontSize"] . "px;") : "";

					$align = strtoupper($ln["align"]);
					$style = $aligns[$ln["align"]];

					if ($align != "R")
					{
						$hasLeft = false;
						$hasCenter = false;
					}
					if ($align == "L")
					{
						$hasLeft = true;
					}
					if ($align == "C")
					{
						$hasCenter = true;
					}
					if (!empty($ln["txt"]))
					{
						$ln["txt"] = str_replace(array_keys($customTxtReplacer), array_values($customTxtReplacer), $ln["txt"]);
						$ln["txt"] = nl2br(str_replace("\\n", PHP_EOL, $ln["txt"]));
					}

					$bcrCode = "";
					if (!empty($item["hasAutoSerial"]) || !empty($item["itemAttrId"]))
					{
						$bcrCode = !empty($item['sNo']) ? $item['sNo'] : (!empty($item['SKU']) ? $item['SKU'] : (!empty($item['uNo']) ? $item['uNo'] : ""));
					}
					else
					{
						$bcrCode = !empty($item['SKU']) ? $item['SKU'] : (!empty($item['sNo']) ? $item['sNo'] : (!empty($item['uNo']) ? $item['uNo'] : ""));
					}

					// $item['pNo'] = "";
					$purbcrCode = !empty($item['pNo']) ? $item['pNo'] : (!empty($item['sNo']) ? $item['sNo'] : (!empty($item['SKU']) ? $item['SKU'] : ""));
					if($ln['type'] == "barCodepur")
					{
						$bcrCode = $purbcrCode;
					}

					switch ($ln['type'])
					{
						case 'img' :
							if(!empty($ln['imgPath']))
							{
								$infoHtmlArr[] = '<div style="' . $style . $fontSize . '" class="line img Lf' . $ln['font'] . ' ' . $ln["bold"] . '"><img style="height: 1em;" src='.$ln['imgPath'].'></div>';
							}
						break;
						
						case "barCode":
						case "barCodepur":	
							$isQr = ($ln['code'] == "QR") ? "QR" : false;

							if (!is_numeric($item['SKU']) && !in_array($ln['code'],array('C128A','C39','QR')))
							{
								$bar_html .= '<div class="line barCodepur ' . $ln["bold"] . '">' . $ln['code'].' not support non-numeric value in barcode.please change the barcode type or item sku value</div>';
							}
							else
							{
								if ($ln["font"] == 'C' && !empty($ln["barcodeWidth"]) && !empty($ln["barcodeHeight"]))
								{
									$bcrSize = $ln["barcodeWidth"];
									$bcrHeight = $ln["barcodeHeight"];
								}
								else
								{
									$bcrSize = !empty($ln['width']) ? $ln['width'] : (empty($barCodeSize[$ln['font']]) ? 1 : $barCodeSize[$ln['font']]);
									$bcrHeight = !empty($ln['height']) ? $ln['height'] : (empty($barCodeHeight[$ln['font']]) ? 0.7 : $barCodeHeight[$ln['font']]);
								}

								$bar_html .= '<div class="line barcodecell f' . $ln['font'] . ' ' . $ln['code'] . ' ' . $ln["bold"] . '" style="' . $aligns[$ln["align"]] . 'margin-bottom:0.2mm;" >';
								$bar_html .= '<barcode code="' . $bcrCode . '" class="barcode" size="' . $bcrSize . '" text="0" type="' . $ln['code'] . '" height="' . $bcrHeight . '" />';
								$bar_html .= '</div>';
							}

							if ($infoHtml || !$isQr)
							{
								$infoHtmlArr[] = '<div class="' . $ln["bold"] . '" style="' . $style . '">' . $bar_html . '</div>';
								$bar_html = "";
							}
							/*
							else if (!empty($ln['inTxt']))
							{
								$infoHtml .= '<div class="line f' . $ln['font'] . ' ' . $isQr . '">' . $item['SKU'] . '</div>';
							}
							*/
						break;
						case "barCodeType":
						    $tmpInfoHtml = '<div class="line f' . $ln['font'] . ' ' . $isQr . ' ' . $ln["bold"] . '" style="' . $style . $fontSize . '">';
						    $tmpInfoHtml .= !empty($ln["txt"]) ? $ln["txt"] : "";
						    $tmpInfoHtml .= $item['SKU'];
						    $tmpInfoHtml .= '</div>';
							$infoHtmlArr[] = $tmpInfoHtml;
						break;
						case "barCodepurValue":
						    $tmpInfoHtml = '<div class="line barCodepurValue f' . $ln['font'] . ' ' . $isQr . ' ' . $ln["bold"] . '" style="' . $style . $fontSize . '">';
						    $tmpInfoHtml .= !empty($ln["txt"]) ? $ln["txt"] : "";
						    $tmpInfoHtml .= $purbcrCode;// str_replace(array("TID#", "UID#", "AID#", "SID#"), "", $purbcrCode);
						    $tmpInfoHtml .= '</div>';
							$infoHtmlArr[] = $tmpInfoHtml;
							break;
						case "barCodeValue":
							$tmpInfoHtml = '<div class="line barCodeValue f' . $ln['font'] . ' ' . $isQr . ' ' . $ln["bold"] . '" style="' . $style . $fontSize . '">';
							$tmpInfoHtml .= !empty($ln["txt"]) ? $ln["txt"] : "";
							$tmpInfoHtml .= $bcrCode;
							$tmpInfoHtml .= '</div>';
							$infoHtmlArr[] = $tmpInfoHtml;
						break;
						case "category":
							if(!empty($item['category']))
							{ 
								$infoHtmlArr[] = '<div class="line category f' . $ln['font'] . ' ' . $isQr . ' ' . $ln["bold"] . '" style="' . $style . $fontSize . '">' .(!empty($ln['txt']) ? $ln['txt'] : '').$item['category'] . '</div>';
							}
						break;
						case "printName":
							if(!empty($item['printName']))
							{ 
								$infoHtmlArr[] = '<div class="line printName f' . $ln['font'] . ' ' . $isQr . ' ' . $ln["bold"] . '" style="' . $style . $fontSize . '">' .(!empty($ln['txt']) ? $ln['txt'] : '').$item['printName'] . '</div>';
							}
						break;
						case "curDate":
							// // Get the current date, you can format it as needed
							$currentDate = !empty($ln['enc']) ? date($ln['enc']) : date("m-Y"); // Example format: 14-05-2025						
							$infoHtmlArr[] = '<div class="line curDate f' . $ln['font'] . ' ' . $isQr . ' ' . $ln["bold"] . '" style="' . $style . $fontSize . '">' . (!empty($ln['txt']) ? $ln['txt'] : '') . $currentDate . '</div>';
											
						break;
						case "txt":
							if (!empty($ln["txt"]))
							{
								$tmpInfoHtml = '<div class="line txt f' . $ln['font'] . ' ' . $isQr . ' ' . $ln["bold"] . '" style="' . $style . $fontSize . '">';
								$tmpInfoHtml .= enc_replace($ln["txt"], $ln);
								$tmpInfoHtml .= '</div>';
								$infoHtmlArr[] = $tmpInfoHtml;
							}
						break;
						case "rate":
							//$unitrate = Relative units display
							if(!empty($unitrate)){
								$item["saleRate"] = $unitrate;
							}
							if (!empty($item["rate"]) || !empty($item["saleRate"]))
							{
								$tmpInfoHtml = '<div class="line rate f' . $ln['font'] . ' ' . $isQr . ' ' . $ln["bold"] . '" style="' . $style . $fontSize . '">';
								$tmpInfoHtml .= !empty($ln["txt"]) ? $ln["txt"] : "";
								if (!empty($saleRatePrefix) || !empty($saleRateSuffix))
								{
									$tmpInfoHtml .= empty($saleRatePrefix) ? "" : $saleRatePrefix;
									$tmpInfoHtml .= (int)(!empty($item["saleRate"]) ? $item["saleRate"] : $item["rate"]);
									$tmpInfoHtml .= empty($saleRateSuffix) ? "" : $saleRateSuffix;
								}
								else
								{
									$tmpInfoHtml .= enc_replace(formatAmount((!empty($item["saleRate"]) ? $item["saleRate"] : $item["rate"]), $currencyCode, "0.00", true,$rateFraction), $ln);
								}
								$tmpInfoHtml .= '</div>';

								$infoHtmlArr[] = $tmpInfoHtml;
							}
						break;
						case "purRate":
							if(!empty($item['purRate']))
							{
								$tmpInfoHtml = '<div class="line purRate f' . $ln['font'] . ' ' . $isQr . ' ' . $ln["bold"] . '" style="' . $style . $fontSize . '">';
								$tmpInfoHtml .= !empty($ln["txt"]) ? $ln["txt"] : "";
								$tmpInfoHtml .= enc_replace(formatAmount((!empty($item["purRate"]) ? $item["purRate"] : $item["rate"]), $currencyCode, "0.00", true,$rateFraction), $ln);
								$tmpInfoHtml .= '</div>';
								$infoHtmlArr[] = $tmpInfoHtml;
							}
						break;
						case "mrp":
							if (!empty($item["mrp"]))
							{
								$tmpInfoHtml = '<div class="line mrp f' . $ln['font'] . ' ' . $isQr . ' ' . $ln["bold"] . '" style="' . $style . $fontSize . '">';
								$tmpInfoHtml .= !empty($ln["txt"]) ? $ln["txt"] : "";
								if(in_array('MC',$salModCodes)) {
									$tmpInfoHtml .= enc_replace((!empty($item['mrpCurrency'])? $item['mrpCurrency'] : '').' '.formatAmount($item["mrp"], $item["currencyCode"], "0.00", true,$rateFraction), $ln);
								}else{
									$tmpInfoHtml .= enc_replace(formatAmount($item["mrp"], $item["currencyCode"], "0.00", true,$rateFraction), $ln);
								}
								$tmpInfoHtml .= '</div>';
								$infoHtmlArr[] = $tmpInfoHtml;
							}
						break;
						case "mrprate":
							if (!empty($item["mrp"]) && (!empty($item["rate"]) || !empty($item["saleRate"])))
							{
							
								$tmpInfoHtml = '<div class="line saleRate f' . $ln['font'] . ' ' . $isQr . ' ' . $ln["bold"] . '" style="' . $style . $fontSize . '">';
								$tmpInfoHtml .= !empty($ln["txt"]) ? $ln["txt"] : "";
								$tmpInfoHtml .= '<span>'.$this->currency_symbol.'  <s>'. enc_replace(formatAmount($item["mrp"], $item["currencyCode"], "0.00", true,$rateFraction), $ln).'</s></span>';
								$tmpInfoHtml .= "&nbsp;&nbsp;&nbsp;&nbsp;";
								$tmpInfoHtml .= '<span class="line fN"><b>'.enc_replace(formatAmount((!empty($item["saleRate"]) ? $item["saleRate"] : $item["rate"]), $currencyCode, "0.00", true,$rateFraction), $ln).'</b></span>';
								$tmpInfoHtml .= '</div>';
								$infoHtmlArr[] = $tmpInfoHtml;
							}
						break;
						case "discOnMrp":
							if(!empty($item['discOnMrp']))
							{
								$tmpInfoHtml = '<div class="line discOnMrp f' . $ln['font'] . ' ' . $isQr . ' ' . $ln["bold"] . '" style="' . $style . $fontSize . '">';
								$tmpInfoHtml .= !empty($ln["txt"]) ? $ln["txt"] : "";
								$tmpInfoHtml .= $item["discOnMrp"] . "%";
								$tmpInfoHtml .= '</div>';
								$infoHtmlArr[] = $tmpInfoHtml;
							}
						break;
						default:
							if ($ln['type'] == "itemName" && !empty($ln['len']))
							{
								$item['itemName'] = substr($item['itemName'],0,$ln['len']);
							}

							if (!empty($item[$ln['type']]))
							{
								$tmpInfoHtml = '<div class="line ' . $ln['type'] . ' wsnw f' . $ln['font'] . ' ' . $isQr . ' ' . $ln["bold"] . '" style="' . $style . $fontSize . '">';
								$tmpInfoHtml .= !empty($ln["txt"]) ? $ln["txt"] : "";

								// $tmpInfoHtml .= explode(PHP_EOL, wordwrap($item[$ln['type']], 30, PHP_EOL))[0];
								// $tmpInfoHtml .= substr($item[$ln['type']], 0, 30);
								if (!empty($ln["enc"])){
									$tmpInfoHtml .= enc_replace($item[$ln['type']], $ln);
								} else {
									$tmpInfoHtml .= $item[$ln['type']];
								}
								$tmpInfoHtml .= '</div>';
								$infoHtmlArr[] = $tmpInfoHtml;
							}
						break;
					}

					if ($hasLeft && $align == "R" && count($infoHtmlArr)-2 >= 0 && strpos($infoHtmlArr[count($infoHtmlArr)-2], "text-align:center") <= 0)
					{
						$infoHtmlArr[count($infoHtmlArr)-2] = str_replace('class="line', 'class="lineL', $infoHtmlArr[count($infoHtmlArr)-2]);
						$infoHtmlArr[count($infoHtmlArr)-1] = str_replace('class="line', 'class="lineR', $infoHtmlArr[count($infoHtmlArr)-1]);

						$leftHtml = $infoHtmlArr[count($infoHtmlArr)-2];
						$rightHtml = $infoHtmlArr[count($infoHtmlArr)-1];
						$infoHtmlArr[count($infoHtmlArr)-2] = '<div style="display:inline-block;float:left;width:100%;">' . $leftHtml . $rightHtml . '</div>';

						$infoHtmlArr[count($infoHtmlArr)-1] = "";

						$hasLeft = false;
					}
					if ($hasCenter && $align == "R" && count($infoHtmlArr)-3 >= 0 && count($infoHtmlArr)-2 >= 0 && strpos($infoHtmlArr[count($infoHtmlArr)-2], "text-align:center" ) >  0 && strpos($infoHtmlArr[count($infoHtmlArr)-1], "text-align:right") > 0)
					{
						$infoHtmlArr[count($infoHtmlArr)-3] = str_replace('class="line', 'class="lineQuartL', $infoHtmlArr[count($infoHtmlArr)-3]);
						$infoHtmlArr[count($infoHtmlArr)-2] = str_replace('class="line', 'class="lineQuartL wsnw', $infoHtmlArr[count($infoHtmlArr)-2]);
						$infoHtmlArr[count($infoHtmlArr)-1] = str_replace('class="line', 'class="llineQuartR wsnw', $infoHtmlArr[count($infoHtmlArr)-1]);
						$leftHtml = $infoHtmlArr[count($infoHtmlArr)-3];
						$centerHtml = $infoHtmlArr[count($infoHtmlArr)-2];
						$rightHtml = $infoHtmlArr[count($infoHtmlArr)-1];
						$infoHtmlArr[count($infoHtmlArr)-3] = '<div style="display:inline-block;width:100%;">' . $leftHtml .$centerHtml. $rightHtml . '</div>';
						$infoHtmlArr[count($infoHtmlArr)-2] = "";
						$infoHtmlArr[count($infoHtmlArr)-1] = "";

						$hasCenter = false;
					}
				}

				$infoHtml .= implode("", $_imgArr);
				$infoHtml .= implode("", $infoHtmlArr);
				$infoHtmlArr = array();

				$infoHtml .= '</div>';

				for ($i=0; $i<$qty; $i++)
				{
					$html = '<div class="main ' . $isQr . '">';

					if ($isQr && $bar_html)
					{
						$html .= '<div class="qr">' . $bar_html . $infoHtml . '</div>';
					}
					else
					{
						$html .= $infoHtml;
					}
					$html .= '</div>';
					$labels[] = $html;
				}
			}

			$html = "";
			if ($from_row > 1)
			{
				for ($i=0; $i < $from_row - 1; $i++)
				{
					$html .= '<div class="row">' . PHP_EOL;
					$html .= str_repeat('<div class="main ' . $isQr . '"></div>', $barcode['cols']) . PHP_EOL;
					$html .= '</div>' . PHP_EOL;
				}
			}

			$labels = array_chunk($labels, $barcode['cols']);
			
			foreach($labels as $k => $v)
			{
				$html .= '<div class="row">' . PHP_EOL;
				$html .= implode(PHP_EOL, $v);

				if (count($v) < $barcode['cols'])
				{
					$html .= str_repeat('<div class="main ' . $isQr . '"></div>', $barcode['cols'] - count($v));
				}

				$html .= '</div>' . PHP_EOL;
			}

			echo $html;
		?>
	</body>
</html>
<?php // exit; ?>

