<?php

$flag1 = false;
$wrap = true;

if (empty($custFieldsCols))
{
	$custFieldsCols = 3;
}
if ($fields)
{
	$td = array();
	$i = 0;
	$custFieldsCols = in_array(count($fields), array(1, 2, 4)) ? 2 : 3;

	if (count($fields) > 6)
	{
		// $wrap = false;
	}

	foreach ($fields as $row)
	{
		if (!empty($row['isGrid']))
		{
			continue;
		}

		if ($row['fValue'] && !empty($row['isPrint']))
		{
			$flag1 = true;
			if (empty($td[$i]))
			{
				$td[$i] = "";
			}
			
			if (!empty($row["fType"]) && $row["fType"] == "date")
			{
				$row["fValue"] = format_date($row["fValue"]);
			}

			if (!empty($row["fType"]) && $row["fType"] == "time")
			{
				$row["fValue"] = date("h:i A", strtotime($row["fValue"]));
			}

			if (!$wrap || $custFieldsCols == 2)
			{
				$td[$i] .= '<p class="nm"><span>' . $row['fName'] . ': <b>' . $row['fValue'] . '</b></span></p>';
			}
			else
			{
				$td[$i] .= '<p class="nm">' . $row['fName'] . ':</p>';
				$td[$i] .= '<p class="nm" style="padding-bottom:3px;"><b>' . $row['fValue'] . '</b></p>';
			}

			$i++;
		}

		if ($i == $custFieldsCols)
		{
			$i = 0;
		}
	}

	if ($flag1)
	{
?>
<table border="0" cellspacing="0" cellpadding="0" class="nbv nbb vat <?php echo empty($isThermalPrint) ? "" : "noborder dashed"; ?>" width="50%">
	<tbody>
		<tr class="custFields"><?php
			$style = '';
			if(!empty($isTaxSheet) || !empty($issimpletemp))
			{
				$style="style='border-top:none'";
			}
			
			$wid = 100 / $custFieldsCols;			
			for ($i=0; $i<$custFieldsCols; $i++)
			{
				echo '<td ' .$style.' width="' . $wid . '%">'. (!empty($td[$i]) ? $td[$i] : ' ').'</td>';
			}
		?>
		</tr>
	</tbody>
</table>
<?php
	}
}
