<?php defined('BASEPATH') OR exit('No direct script access allowed'); 

$addressTmpl = array();
if (!empty($address1))
{
	$addressTmpl[] = $address1;
}

if (!empty($address2))
{
	$addressTmpl[] = $address2;
	// $addressTmpl[0] .= ", " . $address2;
}
if(!isset($isAddTo)) {
	$isAddTo = false;
}
//print_R($isAddTo);exit;
//if (!empty($addressTmpl))
//{
	$_city = '';
	if(!empty($city))
	{
		$_city .= $city;
		if($zip)
		{
			$_city .= ' - ' . $zip;
		}
		// $addressTmpl[] = $_city;
	}

	$state = $_city ? $_city . ', ' : '';
	if (!empty($stateName))
	{
		$state .= $stateName;
	}
	else if (!empty($pos))
	{
		$state .= $pos;
	}

	if (!empty($country))
	{
		$state .= ($state ? ', ' : '') . $country;
	}

	$addressTmpl[] = $state . '.';

	$addressTmpl = implode(",<br>", $addressTmpl);

	if(!empty($mobile))
	{ 
		$addressTmpl .= '<br>Phone : ' . $mobile;
		$addressTmpl .= empty($phone) ? "" : (", " . $phone);
	}
	else if(!empty($phone))
	{
		$addressTmpl .= '<br>Phone : ' . $phone;
	}

	if(!empty($email))
	{
		$addressTmpl .= '<br>Email : ' . $email;
	}
	if(!empty($gstin))
	{
		$addressTmpl .= '<br>'.lang("GSTIN") .' : ' . $gstin;
	}
	if(!empty($pan))
	{
		$addressTmpl .= '<br>'.lang("PAN") .' : ' . $pan;
	}
	if(!empty($isRegisteredMSME))
	{
		$addressTmpl .= '<br>'.mylang("MSME") .' '. $msmet  .' : ' . $msmen ;
	}
	if(!empty($addInfo))
	{
		$addressTmpl .= '<br>' . nl2br($addInfo);
	}
	if(!empty($extraCont))
	{
		$addressTmpl .= '<br>' . nl2br($extraCont);
	}
	if(!empty($below_addr) ) {
		$addressTmpl .= ',<br>'	;	
		$i = 0;
		foreach($below_addr as $row) {
			$addcomma = '';
			if($i < count($below_addr)-1) {
				$addcomma = ',<br>';
			}
			$addressTmpl .= empty($row) ? "" : ($row.$addcomma);
			$i++;
		}
	}
/*
} else {
	$addressTmpl = "";
}
*/
echo '<p class="address nm">';

if (!empty($name))
{
	$isAddToCaption = '';
	if($isAddTo) {
		$isAddToCaption = 'To : ';
	}
	echo is_english($name) ? $isAddToCaption.'<h3 style="margin:0px;">'.$name . '</h3>' : $name;
}
if(!empty($above_addr)) {
	foreach($above_addr as $row) {
		$row = empty($row) ? "" : $row;
		$row .= ',<br>';
		echo $row;
	}
}
echo $addressTmpl;

?></p>

