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

// Details Layout Begins

	$paymentTypes = array(
		"SP" => "Receipt #",
		"SC" => "Credit Note #",
		"JV" => "Journal #",
		"PP" => "Payment #",
		"PD" => "Debit Note #",
		"AO" => "Opening Balance #"
	);
	$borderColor = empty($borderColor) ? '#000000' : '#000000';
	if($tType == 'SH') {
		//$isBankDetail = false;
		$notes = $terms = '';
	}
	$headColor = (empty($is_email) ? $bgColor : $email_color);
	$roundAmount = formatAmount($roundAmount, $currencyCode, '');
	$dueAmount = abs($dueAmount);
	$dueAmount = ($dueAmount != $totAmount) ? $dueAmount : 0;
	$dueAmount = formatAmount($dueAmount, $currencyCode, '');
	$totAmount = formatAmount($totAmount, $currencyCode);

	$totTax = formatAmount($totTax, $currencyCode);
	$tdsAmount = formatAmount($tdsAmount, $currencyCode);

	$taxableAmount = formatAmount($taxableAmount, $currencyCode, false, true);
	$excTaxableAmount = formatAmount($excTaxableAmount, $expCurrencyCode, false, true);
	$totForexAmt = formatAmount($totForexAmt, $expCurrencyCode, false, true);
	$forexDueAmount = formatAmount($forexDueAmount, $expCurrencyCode, false, true);

	$isPrint = $export_type ? true : false;
	
	/*if (!empty($company['invsign']))
	{
		if ($isPrint && !$signOnPrint) {
			$company['invsign'] = null;
		}

		if ((!$isPrint || $is_email) && !$signMailPdf) {
			$company['invsign'] = null;
		}
	}*/

	if ($isQuote || $tType == 'PO') {
		$isCustSign = false;
	}

	if($isPrint && $printcolor == 'transparent') {
		$foreColor = "#000000";
	}
	if (!empty($is_email) && $color != 'transparent') {
		$foreColor = "#ffffff";
	}

	if(!empty($bgColor)) {
		if($bgColor == 'transparent') {
			$showVerticalLine= false;
		}
	}
	else {
		$showVerticalLine = true;
	}

	$gridFields = array();
	if (!empty($fields))
	{
		foreach ($fields as $row)
		{
			if (($row['tType'] == 'IG' || $row['tType'] == 'RG') && !empty($row['isPrint']))
			{
				$row['fValue'] = json_decode($row['fValue'], true);
				$gridFields[] = $row;
			}
		}
	}

	if (empty($gstin)) {
		$showTax = false;
	}
?>
	<div class="page-break">
	<table align='left' cellspacing="0" cellpadding="0" style="width:100%" class="wpw vat nbb taxbob ft <?php echo empty($_view_noborder) ? '' : 'noborder'; ?>" ><?php
		$expCurLable = '';
		$curLable = '';
		$bothCur = '';

		$curLable = '<small>(' . $currencyCode . ')</small>';
		if($isExport) {
			$expCurLable = '<small>(' . $expCurrencyCode . ')</small>';
			$bothCur .= '<p class="curr nm"><small class="">(' . $expCurrencyCode . ')</small>';
		} else {
			$bothCur .= '<br>';
		}
		$bothCur .= '<small class="">(' . $currencyCode . ')</small></p>';

		$totWid = 100;
		$cols = 1;
		$chargesCol1 = 0;
		$chargesCol2 = 0;
		$subTotalCols = 0;
		$subTotalCols1 = 0;

		$colTag = '';
		$headTag = '<tr>' . PHP_EOL;
		$bodyTag = '<tr>' . PHP_EOL;
		$salChargeTag = '<tr>' . PHP_EOL;

		// Row Number
		if (!empty($isSlNoCol)) {
			//$colTag .= '<col style="width:6%">' . PHP_EOL;
			$headTag .= '<th style="border-top:none;border-bottom:0.5px solid;" class="">'.lang("SNo").'</th>' . PHP_EOL;
			$bodyTag .= '<td  width="6%" class="ac">{rowNum}</td>' . PHP_EOL;

			$totWid -= 6;
			$cols++;
			$chargesCol1++;
			$subTotalCols++;
		}

		if (!empty($firstFieldGrid))
		{
			//$colTag .= '<col style="width:20%">' . PHP_EOL;
			$headTag .= '<th  style="border-top:none;border-bottom:0.5px solid;" class="fnt-11">' . $firstFieldGrid['fName'] . '</th>' . PHP_EOL;
			$bodyTag .= '<td width="20%" class="fnt-11 {cf_class}">{cf_' . $firstFieldGrid['fId'] . '}</td>' . PHP_EOL;

			$cols++;
			$chargesCol1++;
			$subTotalCols++;

			$totWid -= 20;
		}

		// Name & Desc
		//$colTag .= '<col style="width:{nameWid}%">' . PHP_EOL;
		$headTag .= '<th style="border-top:none;border-bottom:0.5px solid;" class="">'.lang("ItemDescription").'</th>' . PHP_EOL;
		$desc = '';
		if (!empty($isItemDesc)) {
			$desc = '<br><span class="fnt-11 desc nm pretxt">{itemDesc}</span>';
		}
		$bodyTag .= '<td width="38%">{itemName}' . $desc . '</td>' . PHP_EOL;
		$cols++;
		$chargesCol1++;
		$subTotalCols++;

		// HSN/SAC Code
		if ($hasHSN)
		{
			//$colTag .= '<col style="width:10%">' . PHP_EOL;
			$headTag .= '<th  style="border-top:none;border-bottom:0.5px solid;"  class="fnt-11">'.lang("HSN/SAC").'</th>' . PHP_EOL;
			$bodyTag .= '<td width="10%" class="fnt-11">{itemHS}</td>' . PHP_EOL;

			$totWid -= 10;
			$cols++;
			$chargesCol1++;
			$subTotalCols++;
		}

		$isGridFields = false;
		// Custom Fields Grid
		if (!empty($gridFields))
		{
			foreach($gridFields as $val)
			{
				if (!empty($val['fValue']))
				{
					$isGridFields = true;
				}

				if ($isGridFields)
				{
					break;
				}
			}

			if (!$isGridFields)
			{
				$gridFields = array();
			}
			else
			{
				$cnt = count($gridFields);
				$wid = 10 * $cnt;
				if ($cnt > 2)
				{
					$wid = 10;
				}

				foreach($gridFields as $val)
				{
					//$colTag .= '<col style="width:' . ($wid / $cnt) . '%">' . PHP_EOL;
					$headTag .= '<th style="border-top:none;border-bottom:0.5px solid;"  class="fnt-11">' . $val['fName'] . '</th>' . PHP_EOL;
					$bodyTag .= '<td width="' . ($wid / $cnt) . '%" class="fnt-11 ' . ($val['fType'] == 'number' ? 'ar' : '') . '{cf_class}">{cf_' . $val['fId'] . '}</td>' . PHP_EOL;

					$cols++;
					$chargesCol1++;
				}

				$totWid -= $wid;
			}
		}

		// Quantity, Unit Name
		//$colTag .= '<col style="width:7%">' . PHP_EOL;
		$headTag .= '<th style="border-top:none;border-bottom:0.5px solid;"  class="ac">'.lang("Qty").'</th>' . PHP_EOL;
		$bodyTag .= '<td width="7%" class="ar">{qty}<small><small>{unit}</small></small></td>' . PHP_EOL;
		$totWid -= 7;
		$cols++;
		$chargesCol1++;
		$subTotalCols1++;

		// Rate Per Unit
		//$colTag .= '<col style="width:12%">' . PHP_EOL;
		$headTag .= '<th style="border-top:none;border-bottom:0.5px solid;"  class="ar">'.lang("Rate") . ($isExport && $currencyCode != $expCurrencyCode ? $expCurLable : $curLable) . '</th>' . PHP_EOL;
		$bodyTag .= '<td width="12%" class="ar">{rate}' . '</td>' . PHP_EOL;
		$totWid -= 12;
		$cols++;
		$chargesCol1++;
		$subTotalCols1++;

		// Discount
		if($hasDiscount)
		{
			//$colTag .= '<col style="width:10%">' . PHP_EOL;
			$headTag .= '<th style="border-top:none;border-bottom:0.5px solid;"  class="ar">'.lang("Discount").'</th>' . PHP_EOL;
			$bodyTag .= '<td width="7%" class="ar">{discPercentage}</td>' . PHP_EOL;

			$totWid -= 10;
			$cols++;
			$chargesCol1++;
			$subTotalCols1++;
		}

		$salChargeTag .= '<td class="ar {chargeClass}" colspan="' . $chargesCol1 . '">{itemName}</td>' . PHP_EOL;

		// Tax Name
		if (!empty($useSimpleTaxCol))
		{
			if (($showTax) && !empty($taxTypes))
			{
				//$colTag .= '<col style="width:10%">';
				$headTag .= '<th style="border-top:none;border-bottom:0.5px solid;"  class="ac">'.lang("Tax").'</th>';
				$bodyTag .= '<td width="10%" class="ar">{taxName}</td>';

				$salChargeTag .= '<td width="5% class="ar {chargeClass}">{taxName}</td>' . PHP_EOL;

				$totWid -= 10;
				$cols++;
				$subTotalCols1++;
			}
		}
		else
		{
			if ($showTax && !empty($taxTypes))
			{
				foreach($taxTypes as $taxType) {
				
					//$colTag .= '<col style="width:8%">' . PHP_EOL;
					$headTag .= '<th style="border-top:none;border-bottom:0.5px solid;"  class="">' . $taxType . $curLable . '</th>' . PHP_EOL;
					$bodyTag .= '<td width="8%" class="ar fnt-small">{' . $taxType . 'Value}<br><small>{' . $taxType . 'Rate}</small></td>' . PHP_EOL;

					$salChargeTag .= '<td width="8%" class="ar fnt-small {chargeClass}">{' . $taxType . 'Value}<br><small>{' . $taxType . 'Rate}</small></td>' . PHP_EOL;

					$totWid -= 8;
					$cols++;
					$subTotalCols1++;
				}
			}
		}

		if ($isEstimate && $isExport && $currencyCode != $expCurrencyCode)
		{
			//$colTag .= '<col style="width:17%">' . PHP_EOL;
			$headTag .= '<th style="border-top:none;border-bottom:0.5px solid;"  class="ar">'.lang("Amount") . $expCurLable . '</th>' . PHP_EOL;
			$bodyTag .= '<td width=10%" class="ar">{excTaxableAmount}</td>' . PHP_EOL;

			$salChargeTag .= '<td width="10%"class="ar {chargeClass}">{taxableAmount}</td>' . PHP_EOL;
			$totWid -= 10;
			$cols++;
		}
		else
		{
			// Taxable Amount in foreign currency
			if ($isExport && $currencyCode != $expCurrencyCode)
			{
				//$colTag .= '<col style="width:15%">' . PHP_EOL;
				$headTag .= '<th  style="border-top:none;border-bottom:0.5px solid;" class="ar">'.lang("Amount") . $expCurLable . '</th>' . PHP_EOL; // $bothCur
				$bodyTag .= '<td width="10%"class="ar">{excTaxableAmount}</td>' . PHP_EOL;

				$salChargeTag .= '<td width="10%"class="ar {chargeClass}">{rate}</td>' . PHP_EOL;

				$totWid -= 17;
				$cols++;
			}

			// Taxable Amount
			//$colTag .= '<col style="width:17%">' . PHP_EOL;
			$headTag .= '<th style="border-top:none;border-bottom:0.5px solid;"  class="ar">'.lang("Amount") . $curLable . '</th>' . PHP_EOL;
			if ($includeTax)
			{
				$bodyTag .= '<td width="10%" class="ar">{itemTotal}</td>' . PHP_EOL;
				$salChargeTag .= '<td width="10%" class="ar {chargeClass}">{itemTotal}</td>' . PHP_EOL;
			}
			else
			{
				$bodyTag .= '<td width="10%" class="ar">{taxableAmount}</td>' . PHP_EOL;
				$salChargeTag .= '<td width="10%" class="ar {chargeClass}">{taxableAmount}</td>' . PHP_EOL;
			}
			$totWid -= 10;
			$cols++;
		}

		$headTag .= '</tr>' . PHP_EOL;
		$bodyTag .= '</tr>' . PHP_EOL;
		$salChargeTag .= '</tr>' . PHP_EOL;

		if (!$showTax){
			$chargesCol1 += $chargesCol2;
		}

		echo str_replace('38', $totWid, $colTag);

		?><thead class="bgcolor vam"><?php echo $headTag; ?></thead>
		<tbody><?php
			if (!empty($details))
			{
				$cnt = count($details);

				foreach ($details as $key => $val)
				{
					//display printname if given
					if(!empty($val['printName']) && trim($val['printName'])){
						$val['itemName'] =  trim($val['printName']);
					}
					$val['qty'] = $val['qty'] > 0 ? floatval($val['qty']) : '';
					$val['rate'] = formatAmount($val['rate'], $currencyCode, false, true);
					$val['discAmount'] = formatAmount($val['discAmount'], $currencyCode, false, true);
					$val['excDiscAmount'] = formatAmount($val['excDiscAmount'], $expCurrencyCode, false, true);
					$val['taxableAmount'] = formatAmount($val['taxableAmount'], $currencyCode, false, true);
					$val['excTaxableAmount'] = formatAmount($val['excTaxableAmount'], $expCurrencyCode, false, true);
					$val["itemTotal"] = formatAmount($val['itemTotal'], $currencyCode, false, true);

					if (!empty($firstFieldGrid) && !empty($firstFieldGrid['fValue'][$val['id']]))
					{
						$val['cf_' . $firstFieldGrid['fId']] = $firstFieldGrid['fValue'][$val['id']];
					}

					foreach($gridFields as $k => $gf)
					{
						if (empty($gf['fValue'][$val['id']]))
						{
							continue;
						}

						$val['cf_' . $gf['fId']] = $gf['fValue'][$val['id']];

						if ($gf['isTotCol'])
						{
							if (empty($gf['total']))
							{
								$gf['total'] = 0;
							}
							$gf['cf_class'] = "al";
							if (is_numeric($gf['fValue'][$val['id']]))
							{
								$gf['total'] += floatval($gf['fValue'][$val['id']]);
								$val['cf_class'] = "ar";
							}

							$gridFields[$k] = $gf;
						}
					}

					if ($val['discPercentage'])
					{
						$val['discPercentage'] = round($val['discPercentage'], 2);
						$val['discPercentage'] = $val['discPercentage'] . "%";
					}

					$val['rowNum'] = $key+1;

					echo $this->parser->parse_str($bodyTag, $val, true);

					if ($isPrint && $isFullPage && $key == $cnt-1)
					{
						echo $this->parser->parse_str($bodyTag, array("itemName" => '<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" width="10px" height="##TransImgHeight##mm" />'), true);
						// echo $this->parser->parse_str($bodyTag, array("itemName" => '<div style="display:inline-block;width:20px;height:##TransImgHeight##mm;"></div>'), true);
					}
				}
			}

			if (!empty($charges))
			{
				foreach($charges as $key => $charge_item)
				{
					$charge_item['taxableAmount'] = formatAmount($charge_item['taxableAmount'], $currencyCode, false, true);
					if ($key > 0){
						$charge_item["chargeClass"] = "nbt";
					}
					echo $this->parser->parse_str($salChargeTag, $charge_item, true);
				}
			}
		?><tr><?php
			if (empty($gridFields))
			{
				$subTotalCols = $cols - ($isExport ? 3 : 2);

				if ($isExport && $isEstimate)
				{
					$subTotalCols++;
				}

				?><td style="border-bottom: 0.5px solid #000000;border-top:0.5px solid #000000;" colspan="<?php echo $subTotalCols; ?>" class="ar subTotal title bob"><?php echo $includeTax ? "(Tax Included) " : ""; ?><b><?php echo lang("Sub Total"); ?></b></td><?php
			}
			else
			{
				?><td <?php echo !empty($isPrint) ?' style="border-bottom:0.5px solid #000000;border-top:0.5px solid #000000;"':' style="border-top:0.5px solid #000000;"'; ?>  colspan="<?php echo $subTotalCols; ?>" class="bob"></td><?php
				foreach($gridFields as $gf)
				{
					echo '<td style="border-bottom:0.5px solid #000000;border-top:0.5px solid #000000;" class="ar bob">' . (!empty($gf['total']) ? $gf['total'] : '') . '</td>';
				}
				echo '<td style="border-bottom:0.5px solid #000000;border-top:0.5px solid #000000;" class="ar subTotal title bob" colspan="' . $subTotalCols1 . '">' . ($includeTax ? "(Tax Included) " : "") . '<b>'.lang("Sub Total").'</b></td>';
			}

			if ($isExport && $currencyCode != $expCurrencyCode)
			{
				echo '<td style="border-bottom:0.5px solid #000000;" class="ar subTotal value export bob"><b>' . $excTaxableAmount . '</b><br/><small><small>' . $expCurrencyCode . '</small></small></td>';
			}
			if (!$isExport || !$isEstimate || ($isExport && $currencyCode == $expCurrencyCode))
			{
				echo '<td class="ar subTotal value bob" style="border-bottom:0.5px solid #000000;border-top:0.5px solid #000000;"><b>' . $taxableAmount . ($isExport && $currencyCode != $expCurrencyCode ? '</b><br/><small><small>' . $currencyCode . '</small></small>' : '</b>') . '</td>';
			}
			?>
		</tr>
		</tbody>
	</table>
	
<?php
	$isFullPage = false;

	// Details Layout End
	// Footer Layout Begins

	$rowspan = 1;
	/*
	if ($charges) {
		// $rowspan += count($charges);
	}
	*/
	if (!empty($tax) && (!$isExport || !$isEstimate)) {
		$rowspan += count($tax);
	}
	if (!empty($roundAmount)) {
		$rowspan++;
	}
	if (!empty($tdsPercentage)) {
		$rowspan++;
	}

	$rowspan++; // Total Amt

	if (!empty($trans_payment)) {
		$rowspan += count($trans_payment);
	}
	if ($dueAmount) {
		$rowspan++;
	}
?>
<table align="left" border="0" cellspacing="0" cellpadding="0" class="footTable vat nbh2 wpw" ><?php
	if (!$isExport || $isEstimate)
	{
		$col_wd = $col_wd1 = 'style="width:50%;"';
	}
	else
	{
		$col_wd = 'style="width:58%;"';
		$col_wd1 = 'style="width:42%;"';
	}
?>
	<!-- <thead>
		<tr>
			<th class="nb np"></th>
			<th class="nb np"></th>
		</tr>
	</thead> -->
	<tbody>
		<tr>
			<td class="wrp" <?php echo $col_wd;?>>
				&nbsp;
			</td>
			<td class="np wrp" style="padding:0;" <?php echo $col_wd1;?>>
				<table align="left" cellspacing="0" cellpadding="0" class="noborder">
					<!--<col style="width:36%;" />
					<col style="width:30%;" />
					<col style="width:34%;" />-->
					<!-- <thead>
						<tr>
							<th class="nb np"></th>
							<th class="nb np"></th>
							<th class="nb np"></th>
						</tr>
					</thead> -->
					<tbody><?php
					if (!empty($tax) && (!$isExport || !$isEstimate))
					{
						if ($showTaxBreakup)
						{
							// Tax to be paid on Reverse Charge
							foreach ($tax as $key => $tax_item)
							{
					?><tr class="<?php echo empty($isReverse) ? '' : 'reversecharge'; echo $includeTax ? 'includetax' : ''; ?>">
						<td class="ar tax title wrp" colspan="2"><?php
							if ($isReverse) {
								echo '<span class="asterisk">*</span>&nbsp;&nbsp;';
							}
							echo $tax_item['taxTypeCode'] . ' ' . round($tax_item['taxRate'], 2); ?>% <small>on <?php echo empty($tax_item['taxableAmt']) ? '' : formatAmount($tax_item['taxableAmt'], $currencyCode, '', true); ?></small>
						</td>
						<td class="ar tax value wrp"><b><?php echo formatAmount($tax_item['taxValue'], $currencyCode, false, true); ?></b></td>
					</tr><?php
							}
						}
						else if (!empty($totTaxByCode))
						{
							foreach ($totTaxByCode as $key => $val)
							{
					?><tr class="<?php echo empty($isReverse) ? '' : 'reversecharge'; ?>">
						<td class="ar tax title wrp" colspan="2"><?php
							if ($isReverse) {
								echo '<span class="asterisk">*</span>&nbsp;&nbsp;';
							}
							echo $key;
						?></td>
						<td class="ar tax value "><b><?php echo formatAmount($val, $currencyCode, false, true); ?></b></td>
					</tr><?php
							}
						}
					}

					if (($isExport && $classCode == 'EXPWOP') || $classCode == 'SEZWOP')
					{
						echo '<tr class="">';
						echo '<td class="ar tax title wrp" colspan="2">';
						echo 'IGST @ 0.00% on ' . $taxableAmount;
						echo '</td>';
						echo '<td class="ar tax value wrp"><b>0.00</b></td>';
						echo '</tr>';
					}

					if(!empty($roundAmount))
					{
					?><tr>
						<td class="ar round title wrp" colspan="2">Round Off </td>
						<td class="ar round value wrp"><b><?php echo $roundAmount; ?></b></td>
					</tr><?php
					}

					if(!empty($tdsPercentage) && $tdsPercentage != 0)
					{
					?><tr>
						<td class="ar tds title wrp">TDS @ <b><?php echo $tdsPercentage; ?>%</b></td>
						<td class="ar tds value wrp" colspan="2"><b><?php echo $tdsAmount; ?></b></td>
					</tr><?php
					}
					?><tr>
						<td class="total value vam wrp" <?php echo !empty($isPrint)? 'style="border-top:none;"':'style="border-top: 0.5px solid #b7b7b7"';?>><b><?php echo lang("TOTAL")?></b></td>
						<td class="ar total value vam wrp" colspan="2" <?php echo !empty($isPrint)? 'style="border-top:none;padding:0px;"':'style="border-top: 0.5px solid #b7b7b7;"';?>><?php
						// Export invoices
						// !$isQuote &&
						if ($isExport && $currencyCode != $expCurrencyCode)
						{
							// echo '<td class="ar total value vam" colspan="3"><b>Total</b>:&nbsp;&nbsp;&nbsp;<b>' . $excTaxableAmount . '</b><br/><small><small>' . $expCurrencyCode . '</small></small></td>';
							echo '<b>' . $excTaxableAmount . '</b><br/><small><small>' . $expCurrencyCode . '</small></small>';
						}
						else
						{
							// echo '<td class="ar total value vam" colspan="3" ><b>Total</b>:&nbsp;&nbsp;&nbsp;<b>' . $totAmount . '</b></td>';
							echo '<b>' . $totAmount . '</b>';
						}
						?></td><?php
			/*
			?>
						<td class="total ar title vam" colspan="2"><?php
							if ($isReverse)
							{
								?><small class="fltlt"><span class="asterisk">*</span>&nbsp;&nbsp;to be paid on Reverse Charge</small>&nbsp;&nbsp;&nbsp;<?php
							}
							?><b class="fltrt">Total</b>
						</td><?php

						if ($isQuote && $isExport)
						{
							echo '<td class="ar total value vam"><b>' . $excTaxableAmount . '</b><br/><small><small>' . $expCurrencyCode . '</small></small></td>';
						}
						else
						{
							if ($isExport)
							{
								// echo '<td class="ar totForexAmt value export vab"><b>' . $totForexAmt . '</b></td>';
							}
							if (!$isExport || !$isEstimate)
							{
								echo '<td class="ar total value vam" ><b>' . $totAmount . '</b></td>';
							}
						}
*/
					?></tr><?php
				if (!empty($trans_payment))
				{
					$class = '';
					foreach ($trans_payment as $key => $tpi)
					{
						$class = ($key == 0) ? 'bot' : (($key == count($trans_payment)-1) ? 'bob' : '');
					?><tr class="">
						<td class="payment title wrp <?php echo $class; ?>" <?php echo $isExport ? '' : 'colspan="2"'; ?> ><?php echo $paymentTypes[$tpi['tType']] . $tpi['tNo']; ?></td><?php
						if ($isExport && $currencyCode != $expCurrencyCode)
						{
							echo '<td class="ar forexAmount value export wrp ' . $class . '">' . $tpi['forexAmount'] . '</td>';
						}
						if (!$isExport || !$isEstimate || ($isExport && $currencyCode == $expCurrencyCode))
						{
							echo '<td class="ar payment value wrp ' . $class . '">' . formatAmount($tpi['allotAmt'] + $tpi['tdsAmt'], $currencyCode, false, true) . '</td>';
						}
					?></tr><?php
					}
				}
				if (!empty($dueAmount))
				{
					?><tr>
						<td class="ar dueamt title wrp" <?php echo $isExport ? '' : 'colspan="2"'; ?>><?php echo $dueAmount_text; ?></td><?php
					if ($isExport && $currencyCode != $expCurrencyCode)
					{
						echo '<td class="ar forexDueAmount value wrp"><b>' . $forexDueAmount . '</b></td>';
						
					}?>
					<td class="ar dueamt value wrp"><b><?php echo ((!$isExport || ($isExport && $currencyCode == $expCurrencyCode)) && !$isEstimate) ? $dueAmount : ''; ?></b></td>
					</tr><?php
				}
					/*
					// if (empty($isFullPage) && empty($isHsnBreakup))
					if (empty($isHsnBreakup))
					{
					?><tr>
						<td valign="top" colspan="3" class="vat ar bot eoe nb">
							<small>E & O.E</small>
						</td>
					</tr><?php
					}
					*/
					?></tbody>
				</table>
			</td>
		</tr>
	</tbody>
</table><table align="left" cellspacing="0" cellpadding="0">
		<tbody>
				<tr>
					<td width="50%" style="border-top:none;border-right:none;" >
						<p class="nm amtinwords" >Amount (in words) :<?php
							if ($isExport && $expCurrencyCode)
							{
								echo $expCurrencyCode . ' ' . $exp_amt_str . " only";
							}
							else
							{
								echo ' ' . $amt_str . " only";
							}
						?></p><br><td style="text-align:right;border-top:none;" class="vat"><?php if (!empty($isHsnBreakup)){echo '<small>E & O.E</small>';}?></td>
					</td>
				</tr>
		</tbody>
</table>
<?php
	// if (!empty($isFullPage) || !empty($isHsnBreakup)) {
	//if (!empty($isHsnBreakup)) {
		//echo '<p class="nm ar"><small>E & O.E</small></p>';
	//}

	if (!empty($taxTypes) && !empty($isHsnBreakup))
	{
		$this->view("export/hsn", array('istaxsheet' => 1));
	}

		if (!empty($isFullPage))
		{
			// echo '<end_last_page end_height="30mm"><page_footer>';
		}

		// echo (!empty($isFullPage) || !empty($isHsnBreakup)) ? 'nb' : 'nbt';

	$eOe = "";
	if (empty($isHsnBreakup)) {
		$eOe = '<p class="nm ar"><small>'.lang("E & O.E").'</small></p>';
	}
?>
<table  style="page-break-inside: avoid"  align="left" cellspacing="0" cellpadding="0" class="footTable vat <?php echo (!empty($isHsnBreakup)) ? '' : 'nbt'; ?> wpw" >
	<!--<col style="width:50%;">
	<col style="width:50%;">-->
	<tbody><?php
	if ($terms)
	{
		?><tr>
			<td width="50%" valign="bottom" style="border-right:none !important; border-top:none !important;" class="vab terms" ><?php
			?><div class="noside " style="display:inline-block;"><span class="nm pretxt"><?php echo lang("Terms")?> :<br><?php echo nl2br($terms); ?></span></div>
			</td>
			
				
				
			<td width="50%"  style="border-top:none;" class="ar"><?php echo $eOe;$eOe = ""; ?><?php
				if(!empty($isShowFor)) // && !empty($company['invsign'])
				{
					?><br></span><?php
				}
			?></td>
		</tr><?php
	}
	else if(!empty($isShowFor)) // && !empty($company['invsign'])
	{
		?><tr>
			<!--<td  style="border-top:none;border-left:none;" class="ar" colspan="2"><br></span></td>-->
		</tr><?php
	}
		?>

				<tr><?php			
				echo '<td valign="bottom" style="border-top:none;" class="vab nbr custsign" >';

				
				if($tType != 'PI' && !empty($isBankDetail) && !empty($bankAccId) && !empty($accType))
				{
					?><div >
					<table class="bank accInfo noborder nopadding" border="0" cellspacing="0" cellpadding="0" <?php echo !empty($showVerticalLine) ? 'style="width:100%;padding:5px;border-left: 4px solid '.$headColor.'"' : '' ?> style="page-break-inside:avoid;" >
						<tbody>
							<tr>
								<td colspan="2">
									<p class="bank title nm">Our Bank Details</p>
								</td>
							</tr>
							<tr>
								<td class="accNumber title" style="width:25%">Account No</td>
								<td class="accNumber value">&nbsp;: <b><?php echo $accNumber; ?></b></td>
							</tr>
							<tr>
								<td class="accName title">Account Name</td>
								<td class="accName value">&nbsp;: <b><?php echo $bankAccName; ?></b></td>
							</tr>
							<tr>
								<td class="bankName title">Bank</td>
								<td class="bankName value">&nbsp;: <b><?php echo $bankName; ?></b></td>
							</tr>
							<tr>
								<td class="branch title">Branch</td>
								<td class="branch value">&nbsp;: <b><?php echo $branchName; ?></b></td>
							</tr>
							<tr>
								<td class="ifsc title">IFSC Code</td>
								<td class="ifsc value">&nbsp;: <b><?php echo $ifscRouteCode; ?></b></td>
							</tr>
							<?php
					if ($isExport)
					{
						if ($swiftCode) {
							?><tr>
								<td class="swift title">Swift Code</td>
								<td class="swift value">&nbsp;: <b><?php echo $swiftCode; ?></b></td>
							</tr><?php	
						}
						if ($adCode) {
							?><tr>
								<td class="dealer title">AD Code</td>
								<td class="dealer value">&nbsp;: <b><?php echo $adCode; ?></b></td>
							</tr><?php
						}
					}
						?></tbody>
					</table></div><br><?php
				}
				
				if (!empty($isCustSign))
				{
					echo '<span class=""  style="margin-top:40px;">'.lang("Customer Signature").'</span>';
				}
				echo '</td>';
				
				echo '<td width="50%" colspan="3" valign="bottom" style="border-top:none;" class="vab ar authsign">';
				echo $eOe;$eOe = ""; 
				if(!empty($isShowFor)) // && !empty($company['invsign'])
				{
					echo '<br>For <span class="ar" style="font-size:12px;">'.$company['name'].' </span><br>';
				}
				else if(!empty($isShowFor)){
				echo $eOe;$eOe = ""; 
					echo '<br>For <span class="ar" style="font-size:12px;">'.$company['name'].' </span><br>';
				}
				if ($tType != 'PI') {
					if (!empty($company['invsign']) && (!$isPrint || $is_email || !empty($signOnPrint)))
					{
						echo '<span class="sign" style="float:right;"><img src="' . $company['invsign'] . '" width="" height="" /><br>Authorized Signature</span>';
					}
					else if (!$is_email || !empty($company['invsign']))
					{
						echo '<br><br><br><span class="" style="margin-top:40px;float:right;">'.lang("Authorized Signature").'</span>';
					}
				}
				echo '</td>';	
				
				
		?></tr>
	</tbody>
</table></div><?php
$email_color = empty($color) ? '#208ED3' : $color;
$headColor = (empty($is_email) ? $bgColor : $email_color);

		if (!empty($footerText))
		{
			echo '<p class="footerTxt nm pretxt">' . $footerText . '</p>';
		}
/*
		if (!empty($isFullPage))
		{
			// echo '</page_footer></end_last_page>';
		}

		if (!$isQuote)
		{
			echo '<page_footer><p class="genby nm">' . lang('COMPUTER_GENERATED_DOCUMENT') . '</p></page_footer>';
		}
*/
?>
<style>
.detailTable {
	width: 100%;
	display: inline-block;
	margin-top: 10px;
}
.accInfo {
	width: auto;
}
table, table td, table th {
	border-color:<?php echo $headColor == "transparent"?'#000000':$borderColor ?>;
	border-spacing: 0px;
}
table thead.bgcolor th {
	background-color: <?php echo $headColor ?>;
	color: <?php echo $foreColor; ?>;
	border-spacing: 0px;
}
p.curr small {
	width: 50%;
	text-align: center;
	display: inline-block;
}
.tc {
	color: <?php echo $headColor ?>;
}
.total {
	background-color: <?php echo $headColor ?>;
	color: <?php echo $foreColor; ?>;
}
.vl {
 	border-left: 4px solid <?php echo $headColor ?>;
	padding-left:5px !important;


}
.ft{
	font-size: <?php echo !empty($fontsize) ? $fontsize-1 : $fontsize ; ?>px !important;
}
.as {
	color:black;
}
.bob {
	border-bottom:1px solid #000000 !important;
}
td {	
	white-space: nowrap !important;
}

/*table{
    page-break-inside: avoid !important;
}*/

</style>

