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

$this->load->language("printtmpl");
// Details Layout Begins
	// echo $isHideTotal;
	$dueAmount_text = (!empty($label) && !empty($label['Balance'])) ? $label['Balance'] :(!empty($dueAmount_text)? $dueAmount_text : "Balance") ;
	if (!isset($sysAttrAsCol))
	{
		$sysAttrAsCol = false;
	}
	//In JOb Order if rate is disabled disable all settings related to rate,amount
	if($tType == 'JO' && empty($isRate)){
		$hideAllAmount = true;
		$isratewithTax = false;
		$isgrossAmount = false;
		$hasDiscount = false;
	}
	if($tType == 'PO' && !empty($categoryCode) && $categoryCode == 'TL'){
		$hideAllAmount = true;
		$isratewithTax = false;
		$isgrossAmount = false;
		$hasDiscount = false;
		$isFreeQty = false;
	}
	
/*
	if ($includeDiscount)
	{
		$hasDiscount = false;
	}
*/
	$hideRate = empty($isRate);

	if (!empty($hideAllAmount))
	{
		$hideAmount = true;
		$showTax = false;
		$hideRate = true;
	}

	$paymentTypes = array(
		"SP" => "Receipt #",
		"SC" => "Credit Note #",
		"JV" => "Journal #",
		"SI" => "Sales #",
		"PI" => "Purchase #",
		"PP" => "Payment #",
		"PD" => "Debit Note #",
		"AO" => "Opening Balance #",
		"PC" => "Sup.Credit Note #"
	);
	if(!empty($sigOnPrint))
	{
		$isSign = 1;
	}
	$isExpNonnGst = $classCode == "XPNG" ? true : false;
	$hideQty = false;
	if ($isExpNonnGst)
	{
		$hideRate = true;
		$hideQty = true;
	}

	$imgexsist = false;
	$isAllAccount = true;
	$unitRate = false;
	$subItems_parents = array();
	if(!empty($details))
	{      
		$parentItem = null;
		foreach ($details as $key => $val)
		{	if($val["itemId"]==0){
			$val['itemTotal']=0;
			$val['taxableAmount']=0;
		}
			if(!empty($val['ptitemId']) && (float)$val['ptitemId'] != (float)$val['id'] ) {
				$subItems_parents[] = $val['ptitemId'];
			}
			if(!empty($val["isHide"])){
				continue;
			}
			if (!empty($val["subCode"]) && in_array($val["subCode"],array('AL','OA')) ) {
				continue;
			}
			if (!$val["itemType"] || $val["itemType"] == "B")
			{
				$parentItem = &$details[$key];
				$parentItem["itemTotal"] = 0;
				$parentItem["_itemTotal"] = 0;
				$parentItem["taxableAmount"] = 0;
				$parentItem["_taxableAmount"] = 0;
			}

			if (!empty($val['itemId']) || $val['itemType'] == 'G' || $val['itemType'] == 'S')
			{
				$isAllAccount = false;
			}

			if (!empty($val['filePath']))
			{
				$imgexsist = true;
			}

			if (!empty($parentItem))
			{
				
				$parentItem["itemTotal"] += $val["itemTotal"];
				$parentItem["_itemTotal"] += $val["_itemTotal"];
				$parentItem["taxableAmount"] += $val["taxableAmount"];
				$parentItem["_taxableAmount"] += $val["_taxableAmount"];
			}
		}
	}

	if($isAllAccount && $tType == "PI")
	{
		$hideRate = $hideQty = true;
	}
	$bo_style = '';
	if(!empty($isDiminishPad) && empty($isvertical)) {
		$bo_style='border-top:1px solid #D3D3D3';
	}

	$align = array("al", "ac", "ar");

	$isHsnBreakup = empty($isTaxPanel) ? false : true;

	///$borderColor = empty($borderColor) ? '#000000' : $borderColor;
	//if($tType == 'SH') {
		//$isBankDetail = false;
		//$notes = $terms = '';
	//}
	//For retail invoice prepare bank details for display
	if(!empty($banks) && !empty($bankid))
	{
		$bank = '';
		foreach ($banks as $key => $val)
		{
			if ($val['accId'] == $bankid)
			{
				$bank = $val ;
				if(!empty($val['upiId']))
				{
					$upi['name'] = $val['accName'];
					$upi['id'] = $val['upiId'];
				}
			}
		}
	}

	if(!empty($upiId))
	{
		$upi['name'] = $bankAccName;
		$upi['id'] = $upiId;
	}

	$headColor = (empty($is_email) ? $bgColor : $color);

	$roundAmount = !empty($roundAmount) ? number_format($roundAmount,$currFraction) : 0;

	if($roundAmount == '0.00')
	{
		$roundAmount = 0;
	}

	// $roundAmount = formatAmount($roundAmount, $currencyCode, '');
	if (empty($dueAmount))
	{
		$dueAmount = 0;
	}
	$dueAmount = abs($dueAmount-0);
	// $dueAmount = ($dueAmount != $totAmount) ? $dueAmount : 0;

	// if ($isReverse)
	// {
	// 	$totAmount -= $totTax;
	// }

	$f_dueAmount = formatAmount(($dueAmount != $totAmount) ? $dueAmount : 0, $currencyCode, '',$currFraction);
	$f_totAmount = formatAmount($totAmount, $isExport ? $expCurrencyCode : $currencyCode, "-", $isExport ? true : false,$currFraction);

	if ($isExport)
	{
		$isratewithTax = false;
	}

	if (empty($dueAmount))
	{
		$outstanding = '';
	}
	if (!empty($outstanding))
	{
		$oldDue = $outstanding - $dueAmount;
		$oldDue = ($oldDue > 0) ? formatAmount($oldDue, $currencyCode,'','',$currFraction) : '';
		$newDue = ($outstanding > 0) ? formatAmount($outstanding, $currencyCode,'','',$currFraction) : '';
	}

	// $totTax = formatAmount($totTax, $currencyCode);
	$tdsAmount = empty((float)$tdsAmount) ? "" : formatAmount($tdsAmount, $currencyCode);
	$totDiscAmt = 0;

	if (!empty($totDisc))
	{
		//$totDisc = round(floatval($totDisc), 2);
		$totDiscAmt = $totDisc;
		$totDisc = formatAmount($totDisc, $currencyCode, "-", true,$currFraction);
	}

	if (!empty($totDiscItem))
	{
		$totDiscItemAmt = $totDiscItem;
		$totDiscItem = formatAmount($totDiscItem, $currencyCode, "-", true,$currFraction);
	}

	$_taxableAmount = 0;
	$_itemTotal = 0;

	$fTaxableAmount = formatAmount($taxableAmount, $currencyCode, false, $isExport ? true : false,$currFraction);
	$tottaxAmount = formatAmount($tottaxAmount, $currencyCode, false, true,$currFraction);
	$forexTaxableAmount = !empty($forexTaxableAmount)?formatAmount($forexTaxableAmount, $expCurrencyCode, false, true,$currFraction):0;
	$forexTotAmount = !empty($forexTotAmount)?formatAmount($forexTotAmount, $expCurrencyCode, false, true,$currFraction):0;
	$totForexAmt = formatAmount($totForexAmt, $expCurrencyCode, false, true,$currFraction);
	$f_forexDueAmount = $forexDueAmount != 0 ? formatAmount($forexDueAmount, $expCurrencyCode, false, true,$currFraction) : null;

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

		if ((!$isPrint || $is_email) && !$signMailPdf) {
			$company['invsign'] = null;
		}
	}*/
	if (!empty($company['invsign']))
	{
		//For PDF(1),Display sign only in the mail Pdf
		if (!empty($download) && $download == 1 && $signOnPrint == 1)
		{
			$company['invsign'] = null;
		}
	}
	//$company['invsign'] = null;
	
	if ($tType == 'PO')
	{
		$isCustSign = false;
	}

	if($isPrint && $printcolor == 'transparent')
	{
		$foreColor = "#000000";
	}

	if (!empty($is_email))
	{
		$foreColor = $color != 'transparent' ? "#ffffff" : "#000000";
	}

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

	$gridFields = array();
	$attribFields = array();
	if (!empty($fields))
	{
		foreach ($fields as $row)
		{
			if (empty($row['fValue']))
			{
				continue;
			}

			if (!empty($row['isPrint']) && $row['fType'] == 'calc')
			{
				$row["fOptions"] = json_decode($row["fOptions"], true);

				$row['fValue'] = json_decode($row['fValue'], true);
				$fValue = array();
				foreach($row['fValue'] as $key => $val)
				{
					if (empty($fValue[$key]))
					{
						if (!empty($row["fOptions"]["calcDisp"]))
						{
							$fValue[$key] = str_replace(preg_filter("/^/", "#", array_keys($val)), array_values($val), $row["fOptions"]["calcDisp"]);
						}
						else
						{
							$fValue[$key] = array();
							foreach($val as $fName => $fVal)
							{
								$fValue[$key][] = ucfirst($fName) . " : " . $fVal;
							}
							$fValue[$key] = implode(", ", $fValue[$key]);
						}

						$attribFields[$key] = $fValue[$key];
					}
				}
				$row["_fValue"] = $fValue;
				// $attribFields[] = $row;
			}
			else if (!empty($row['isPrint']) && !empty($row['isGrid']))
			{
				$row['fValue'] = json_decode($row['fValue'], true);
				$gridFields[] = $row;
			}
		}
	}

	if (empty($gstin) || $isComposition || $classCode == "BOS")
	{
		$showTax = false;
	}
	
	if(($tType == 'PI' || $tType == 'PQ' || $tType == 'PC')&& !empty($contact['taxNo']) && ($contact['conTaxScheme'] != 'C')){
		$showTax = true;
	}
	
	if(!empty($company['countryCode']) && $company['countryCode'] != 'IN')
	{
		$showTax = true;
	}

	if ($isExport && $isQuote)
	{
		$showTax = false;
		$tax = array();
	}

	$taxlenth = 0;
	if($showTax && !empty($taxTypes))
	{
		$taxlenth = count($taxTypes);
	}
	$totQty = 0;
	$totFreeQty = 0;
	if(!empty($printColors)) {
		$headColor = $printColors;
	}
?>
<?php if ( !empty($headerText) && !in_array($tType, array(PURINV, PURCRNOTE, PURDBNOTE, PURADVPMT, EXPRETAIL, PURPMT)))
		{
			$sty ='';
			if(!empty($fields)){
				$sty = 'text-align: left;border-top: 1px solid black;font-size: 13px !important';
			}else{
				$sty = 'text-align: left;font-size: 13px !important';
			}
			echo '<p class="footerTxt nm" style="'.$sty.'">' . nl2br($headerText) . '</p>';
		}
?><table align='left' cellspacing="0" cellpadding="0" style="width:100%;border-collapse: collapse;" class="inv_details wpw  bot ft<?php echo empty($tax) ? '' : 'nbb'; ?><?php echo empty($_view_noborder) ? '' : 'noborder'; ?>" style="width:100%;"><?php
		$expCurLable = '';
		$curLable = '';
		$bothCur = '';
		$isAddBr = '<br>';
		if(!empty($isDiminishPad)) {
			$isAddBr = '';
		}
		$curLable = $isAddBr.'<small>(' . $currencyCode . ')</small>';
		if($isExport) {
			$expCurLable = '<br><small>(' . $expCurrencyCode . ')</small>';
			$bothCur .= '<br><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;
		$qtyTotalCols = 0 ;

		$colTag = '';
		$headTag = '<tr>' . PHP_EOL;
		$bodyTag = '<tr class="tbody {trClass} {subItemParentClass}">' . PHP_EOL;
		$sectionTag = '<tr class="tbody section">' . PHP_EOL;
		$sectionSpan = 1;
		$subItemsSpan = 1;
		$subItemsTag = '<tr class="tbody subItem {subItemParentClass}">' . PHP_EOL;
		$salChargeTag = '<tr class="charges">' . PHP_EOL;
		$afterTaxTag = '<tr class="charges charges2">' . PHP_EOL;

		// Row Number
		if (!empty($isSlNoCol)) {
			//$colTag .= '<col style="width:6%">' . PHP_EOL;
			$headTag .= '<th style="width:9.5mm; background-color:'.$headColor.'" >'.mylang("SNo").'</th>' . PHP_EOL;
			$bodyTag .= '<td class="ac sNo" style="'.$bo_style.'">{rowNum}</td>' . PHP_EOL;
			$sectionTag .= '<td class="ac sNo" style="'.$bo_style.'">{rowNum}</td>' . PHP_EOL;
			$subItemsTag .= '<td class="ac sNo" style="border-top: none;"></td>' . PHP_EOL;

			//- $totWid -= 6;
			$cols++;
			$chargesCol1++;
			$subTotalCols++;
			$qtyTotalCols++;
			// $subItemsSpan++;
		}
		
		if(!empty($isitemimage) &&  $imgexsist){
			$headTag .= '<th style="max-width:9.5mm; background-color:'.$headColor.'" class="first">Item image</th>' . PHP_EOL;
			$bodyTag .= $imgexsist ? '<td class="ac" style="'.$bo_style.'" ><img src="{filePath}" width="70px" height="70px"></td>' . PHP_EOL : '<td></td>';

			//- $totWid -= 6;
			$cols++;
			$chargesCol1++;
			$subTotalCols++;
			$qtyTotalCols++;
			$sectionSpan++;
			$subItemsSpan++;
		}
		
		if (!empty($firstFieldGrid))
		{
			//$colTag .= '<col style="width:20%">' . PHP_EOL;
			$headTag .= '<th style="border-bottom:0.5px solid #000000;border-right:0.5px solid #000000;background-color:'.$headColor.'" class="">' . $firstFieldGrid['fName'] . '</th>' . PHP_EOL;
			$bodyTag .= '<td style="white-space:nowrap;'.$bo_style.'" class="{cf_class}">{cf_' . $firstFieldGrid['fId'] . '}</td>' . PHP_EOL;

			$cols++;
			$chargesCol1++;
			$subTotalCols++;
			$qtyTotalCols++;
			$sectionSpan++;
			$subItemsSpan++;

			//- $totWid -= 20;
		}

		// Name & Desc
		//$colTag .= '<col style="width:{nameWid}%">' . PHP_EOL;
		$headTag .= '<th style="max-width:{nameWid}%;background-color:'.$headColor.'" class="">'.mylang('ItemDescription');
		if (!$sysAttrAsCol && !empty($sys_attrs_grp))
		{
			$headTag.='<table align="left" cellspacing="0" cellpadding="0" width="100%" class="noborder"><thead><tr>';
			$wid = 100 / count($sys_attrs_grp);
			foreach($sys_attrs_grp as $k=>$v)
			{
				$headTag .= '<th width="' . $wid . '%" class="' . $align[$k%3] . '"><small>' . $v["name"] .'</small></th>';
			}
			$headTag .= '</tr></thead></table>';
		}
		$headTag .= '</th>' . PHP_EOL;

		$desc = '';
		if (!empty($isItemDesc))
		{
			$desc .= '{itemDesc}'; // '<br><span class="fnt-11 desc nm pretxt">{itemDesc}</span>';
			if ($isExpNonnGst)
			{
				$desc .= '{conName}';
			}
		}
		//Items custom fields 
		$desc .= '{cfList}';// '<br><span class="fnt-11 desc nm pretxt">{cfList}</span>';
		
		$desc .= '{attribField}';// '<br><span class="fnt-11 desc nm pretxt">{itemDesc}</span>';

		if (!$sysAttrAsCol && !empty($sys_attrs_grp))
		{
			$desc .= "{sys_attrs}";
		}

		$desc .= '<p class="desc nm pretxt"><small>{attrs}</small></p>';

		// width="{nameWid}%"
		$bodyTag .= '<td class="" style="'.$bo_style.'">{itemName}' . $desc . '</td>' . PHP_EOL;
		$sectionTag .= '<td class="" style="'.$bo_style.'" colspan="{sectionSpan}">{itemName}' . $desc . '</td>' . PHP_EOL;
		$subItemsTag .= '<td class="" style="'.$bo_style.'" colspan="{subItemsSpan}">{itemName}' . $desc . '</td>' . PHP_EOL;

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

		if ($sysAttrAsCol && !empty($sys_attrs_grp))
		{
			foreach($sys_attrs_grp as $_sys_attr)
			{
				$headTag .= '<th class="">' . $_sys_attr["name"] . '</th>';
				$bodyTag .= '<td class="" >{attr_' . $_sys_attr["attrGrpId"] . '}</td>' . PHP_EOL;

				$cols++;
				$chargesCol1++;
				$subTotalCols++;
				$qtyTotalCols++;
			}
		}
		
/*
		if ($sysAttrAsCol && !empty($sys_attrs_grp))
		{
			foreach($sys_attrs_grp as $k=>$attr_name)
			{
				$headTag .= '<th width="5%" class="">' . $attr_name . '</th>';
				$bodyTag .= '<td class="">{' . $attr_name . '}</td>' . PHP_EOL;

				$cols++;
				$chargesCol1++;
				$subTotalCols++;
			}
		}
*/
		// SKU Code
		if (!empty($isSkuCol) && $isSkuCol && $isSkuCol == 2)
		{
			//$colTag .= '<col style="width:10%">' . PHP_EOL;
			$headTag .= '<th style="background-color:'.$headColor.'" class="">'.mylang("SKU").'</th>' . PHP_EOL;
			$bodyTag .= '<td class="" style="'.$bo_style.'">{SKU}</td>' . PHP_EOL;

			//- $totWid -= 10;
			$cols++;
			$chargesCol1++;
			$subTotalCols++;
			$qtyTotalCols++;
			$sectionSpan++;
			$subItemsSpan++;
		}

		// HSN/SAC Code
		if ($isHsnCol && $hasHSN)
		{
			//$colTag .= '<col style="width:10%">' . PHP_EOL;
			$headTag .= '<th style="max-width:21mm;background-color:'.$headColor.'" class="">'.mylang("HSN/SAC").'</th>' . PHP_EOL;
			$bodyTag .= '<td class="" style="'.$bo_style.'">{itemHS}</td>' . PHP_EOL;

			//- $totWid -= 10;
			$cols++;
			$chargesCol1++;
			$subTotalCols++;
			$qtyTotalCols++;
			$sectionSpan++;
			$subItemsSpan++;
		}
		
		$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="white-space:nowrap;background-color:'.$headColor.'" class="">' . $val['fName'] . '</th>' . PHP_EOL;
					$bodyTag .= '<td class=" ' . ($val['fType'] == 'number' ? 'ar' : '') . '{cf_class}" style="'.$bo_style.'">{cf_' . $val['fId'] . '}</td>' . PHP_EOL;

					$cols++;
					$chargesCol1++;
					$qtyTotalCols++;
					$sectionSpan++;
					$subItemsSpan++;
				}

				//- $totWid -= $wid;
			}
		}
		if (!empty($isRef) && !empty($tType) &&  $tType == "SH") {
			//$colTag .= '<col style="width:6%">' . PHP_EOL;
			$headTag .= '<th style="width:21mm; background-color:'.$headColor.'" >Ref#</th>' . PHP_EOL;
			$bodyTag .= '<td class="ac" style="'.$bo_style.'">{trno}</td>' . PHP_EOL;

			
			$cols++;
			$chargesCol1++;
			$subTotalCols++;
			$qtyTotalCols++;
			$sectionSpan++;
			$subItemsSpan++;
		}
		if (!empty($isitemLocation)) {
			//$colTag .= '<col style="width:6%">' . PHP_EOL;
			$headTag .= '<th style="background-color:'.$headColor.'" >'.mylang("Location").'</th>' . PHP_EOL;
			$bodyTag .= '<td class="ac" style="'.$bo_style.'">{location_name}</td>' . PHP_EOL;

			
			$cols++;
			$chargesCol1++;
			$subTotalCols++;
			$qtyTotalCols++;
		}
		// Quantity, Unit Name
		//$colTag .= '<col style="width:7%">' . PHP_EOL;

		if (empty($hideQty) && !empty($isqty))
		{
			$headTag .= '<th style="max-width:14.5mm;background-color:'.$headColor.'" class="ac">'.mylang("Qty");
			if (!$isCompact)
			{
				$headTag .= (!empty($commonUnit) ? '<br/><small><small>' . $commonUnit . '</small></small>' : '');
			}
			$headTag .= '</th>' . PHP_EOL;
			// $stk = ($tType == SALORD && $status == 'S' && empty($isPrint) && $curStk < $qty) ? "outofstk" : "";
			// $bodyTag .= '<td nowrap="nowrap" class="ar qty'. $stk .'" style="'.$bo_style.'"> {qty}' . (empty($commonUnit) && !empty($units) && ($units == 1) ? '&nbsp;<small><small> {unit} </small></small>' : (!empty($units) && ($units == 3) ? '&nbsp;{unit}' : '' )) . '</td>' . PHP_EOL;
			$bodyTag .= '<td nowrap="nowrap" class="ar qty {curStkClass}" style="'.$bo_style.'"> {qty}' . (empty($commonUnit) && !empty($units) && ($units == 1) ? '&nbsp;<small><small> {unit} </small></small>' : (!empty($units) && ($units == 3) ? '&nbsp;{unit}' : '' )) . '</td>' . PHP_EOL;
			//- $totWid -= 7;
			$cols++;
			$chargesCol1++;
			$subTotalCols1++;
			$sectionSpan++;
			$subItemsSpan++;
		}
		
		if (!empty($units) && $units && $units == 2)
		{
			//$colTag .= '<col style="width:10%">' . PHP_EOL;
			$headTag .= '<th style="background-color:'.$headColor.'" class="">'.mylang("Units").'</th>' . PHP_EOL;
			$bodyTag .= '<td class="unit" style="'.$bo_style.'">{unit}</td>' . PHP_EOL;

			//- $totWid -= 10;
			$cols++;
			$chargesCol1++;
			$subTotalCols1++;
			$sectionSpan++;
			$subItemsSpan++;
		}
		if (!empty($relunits) && $relunits && $relunits == 2)
		{
			//$colTag .= '<col style="width:10%">' . PHP_EOL;
			$headTag .= '<th style="background-color:'.$headColor.'" class="">'.mylang("Sec.Unit").'</th>' . PHP_EOL;
			$bodyTag .= '<td class="unit" style="'.$bo_style.'">{relunit}</td>' . PHP_EOL;

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


		if (empty($hideQty) && !empty($isFreeQty))
		{
			// Free Qty
			//$colTag .= '<col style="width:12%">' . PHP_EOL;
			$headTag .= '<th style="" class="ar">' . mylang("FreeQty");
			if (!$isCompact)
			{
				$headTag .= (!empty($commonUnit) ? '<br/><small><small>' . $commonUnit . '</small></small>' : '');
			}
			$headTag .= '</th>' . PHP_EOL;
			$bodyTag .= '<td class="ar freeQty" style="'.$bo_style.'">{freeQty}' . (!$isCompact && empty($commonUnit)  && !empty($units) ? '&nbsp;<small><small>{unit}</small></small>' : '') . '</td>' . PHP_EOL;
			// $totWid -= 12;
			$cols++;
			$chargesCol1++;
			$subTotalCols1++;
			$sectionSpan++;
			$subItemsSpan++;
		}

		if (empty($hideRate))
		{
			// Rate Per Unit
			//$heading = (!empty($issalerate_after_disc) && $hasDiscount)  ?  lang("Value") : lang("Rate") ;
			//$colTag .= '<col style="width:12%">' . PHP_EOL;
			$headTag .= '<th style="max-width:26mm;background-color:'.$headColor.'" class="wsnw ar">'.mylang("Rate"). ($isExport ? $expCurLable : '') . '</th>' . PHP_EOL;
			$bodyTag .= '<td nowrap="nowrap" class="ar rate" style="white-space: pre !important;' . $bo_style . '">{rate}</td>' . PHP_EOL;
			// $bodyTag .= (!empty($includeTax) && empty($isratewithTax)) ? '{rateWithTax}' : '{rate}' . '</td>' . PHP_EOL;
			//- $totWid -= 12;
			$cols++;
			$chargesCol1++;
			$subTotalCols1++;
			$sectionSpan++;
			$subItemsSpan++;
		}
		
		if (!empty($isratewithTax))
		{
			// Rate With Tax
			//$colTag .= '<col style="width:12%">' . PHP_EOL;
			$headTag .= '<th style="max-width:21mm;background-color:'.$headColor.'" class="ar">' . (empty($hideRate) ? mylang("Rate (Incl. Tax)") : mylang("Rate")) . ($isExport ? $expCurLable : '') . '</th>' . PHP_EOL;
			$bodyTag .= '<td nowrap="nowrap" class="ar netrate rateWithTax" style="'.$bo_style.'">{rateWithTax}' . '</td>' . PHP_EOL;
			//- $totWid -= 12;
			$cols++;
			$chargesCol1++;
			$subTotalCols1++;
			$sectionSpan++;
			$subItemsSpan++;
		}
		if (!empty($isgrossAmount))
		{
			// Gross Amount
			//$colTag .= '<col style="width:12%">' . PHP_EOL;
			$headTag .= '<th style="" class="ar">'.mylang("Gross Amount") . '</th>' . PHP_EOL;
			$bodyTag .= '<td class="ar" style="'.$bo_style.'">{grossamt}</td>' . PHP_EOL;
			// $totWid -= 12;
			$cols++;
			$chargesCol1++;
			$subTotalCols1++;
			$sectionSpan++;
			$subItemsSpan++;
		}
		if (!empty($issaleRate) &&  ($tType == PURINV || $tType == 'SK')) 
		{ //hassalerates
			// Sales Rate
			//$colTag .= '<col style="width:12%">' . PHP_EOL;
			$headTag .= '<th style="" class="ar">'.mylang("SaleRate") . '</th>' . PHP_EOL;
			$bodyTag .= '<td class="ar" style="'.$bo_style.'">{saleRate}</td>' . PHP_EOL;
			// $totWid -= 12;
			$cols++;
			$chargesCol1++;
			$subTotalCols1++;
			$qtyTotalCols++;
			$sectionSpan++;
			$subItemsSpan++;
		}
	
		if ((!empty($isSales) || !empty($mrpInPurSal)) && !empty($isMrpCol) && $hasMrp)
		{
			// MRP
			//$colTag .= '<col style="width:12%">' . PHP_EOL;
			$headTag .= '<th style="" class="ar">' . mylang("MRP") . '</th>' . PHP_EOL;
			$bodyTag .= '<td class="ar" style="'.$bo_style.'">{mrp}</td>' . PHP_EOL;
			// $totWid -= 12;
			$cols++;
			$chargesCol1++;
			$subTotalCols1++;
			$sectionSpan++;
			$subItemsSpan++;
		}

		// If Tax details column selected & totalDiscount entered then consider it as normal.
		if (!empty($totLbtCharges) || $includeDiscount)
		{
			$isTaxDetailCol = 1;
		}

		if (!$hasDiscount && $isTaxDetailCol == 2 && $includeDiscount)
		{
			$isTaxDetailCol = 1;
			// $hasDiscount = true;
			// $includeDiscount = false;
		}

		// Discount
		if ($hasDiscount)// && (empty($issalerate_after_disc) || ($issalerate_after_disc == 1)))
		{
			//$colTag .= '<col style="width:10%">' . PHP_EOL;
			$headTag .= '<th style="max-width:21mm;background-color:'.$headColor.'" class="ar" >'.mylang("Discount") . ($isExport ? $expCurLable : $curLable) . '</th>' . PHP_EOL;
			$bodyTag .= '<td class="ar" style="' . $bo_style . '">{discount}</td>' . PHP_EOL;
/*
			if ($isCompact)
			{
				$bodyTag .= '<td class="ar" style="'.$bo_style.'"><small>{discount}</small><br/>{' . ($isExport ? 'excDiscAmount' : ($isTaxDetailCol == 2 ? '_discAmount' : 'discAmount')) . '}</td>' . PHP_EOL;
			}
			else
			{
				if(!empty($issalerate_after_disc) && $issalerate_after_disc == 1)
				{
					$bodyTag .= '<td class="ar" style="' . $bo_style . '">{discount}</td>' . PHP_EOL;
				}
				else
				{
					$bodyTag .= '<td class="ar" style="'.$bo_style.'">{' . ($isExport ? 'excDiscAmount' : ($isTaxDetailCol == 2 ? '_discAmount' : 'discAmount')) . '}<br><small> {discPercentage}</small></td>' . PHP_EOL;
				}
			}
*/
			//- $totWid -= 10;
			$cols++;
			$discol = $cols;

			$chargesCol1++;
			$subTotalCols1++;
			$sectionSpan++;
			$subItemsSpan++;
		}

		//unitRate
		if (!empty($issalerate_after_disc)) 
		{
			$headTag .= '<th style="width:65px;" class="ac">' . mylang("SalesRate(AfterDisc)") . '</th>';
			$bodyTag .= '<td class="ar" style="'.$bo_style.'">{unitRate}</td>';
			$cols++;
			$chargesCol1++;
			$subTotalCols1++;
			$sectionSpan++;
			$subItemsSpan++;
		}

		$salChargeTag .= '<td class="ar {chargeClass}" colspan="' . $chargesCol1 . '" style="'.$bo_style.'">{itemName}</td>' . PHP_EOL;
		$afterTaxTag .= '<td class="ar {chargeClass}" colspan="' . ($isExport && !$isQuote ? 1 : 2) . '" style="'.$bo_style.'">##LESS##{itemName}</td>' . PHP_EOL;
		if ($isExport)
		{
			$afterTaxTag .= '<td class="ar {chargeClass}" style="'.$bo_style.'">{forexItemTotal}</td>' . PHP_EOL;
		}

		// Tax Name
		if ($isTaxDetailCol == 1)
		{
			if ($showTax && empty($isExempted))
			{
				//$colTag .= '<col style="width:10%">';
				$headTag .= '<th style="width:20mm;" class="ac">'.mylang("Tax").'</th>';
				$bodyTag .= '<td class="ar" style="'.$bo_style.'">{taxName}</td>';

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

				// $totWid -= 10;
				$cols++;
				$subTotalCols1++;
				$sectionSpan++;
				$subItemsSpan++;
			}
			else
			{
				$showTax = false;
			}
		}

		if (empty($hideAmount) && empty($isclassictemp))
		{
			/*
			if ($isEstimate && $isExport)
			{
			//	$colTag .= '<col style="width:17%">' . PHP_EOL;
				$headTag .= '<th class="ar" style="min-width:100px;background-color:'.$headColor.'">'.lang("Amount"). $expCurLable . '</th>' . PHP_EOL;
				$bodyTag .= '<td nowrap="nowrap" class="ar" style="'.$bo_style.'">{forexItemTotal}</td>' . PHP_EOL;

				$salChargeTag .= '<td nowrap="nowrap" class="ar {chargeClass}" style="'.$bo_style.'">{taxableAmount}</td>' . PHP_EOL;
				$afterTaxTag .= '<td nowrap="nowrap" class="ar {chargeClass}" style="'.$bo_style.'"><b>{taxableAmount}</b></td>' . PHP_EOL;
				// $totWid -= 15;
				$cols++;
			}
			else
			{
			*/
				// Taxable Amount in foreign currency
				if ($isExport && $currencyCode != $expCurrencyCode)
				{
					//$colTag .= '<col style="width:15%">' . PHP_EOL;
					$headTag .= '<th class="ar" style="max-width:26mm;background-color:'.$headColor.'">'.mylang("Amount") . $expCurLable . '</th>' . PHP_EOL; // $bothCur
					$bodyTag .= '<td nowrap="nowrap" class="ar" style="'.$bo_style.'">{forexTaxableAmount}</td>' . PHP_EOL;
					$sectionTag .= '<td nowrap="nowrap" class="ar" style="'.$bo_style.'"><b>{forexTaxableAmount}</b></td>' . PHP_EOL;

					$salChargeTag .= '<td class="ar {chargeClass}" style="'.$bo_style.'">{rate}</td>' . PHP_EOL;
					// $totWid -= 15;
					$cols++;
				}

				if (!$isExport || !$isQuote || ($isExport && $currencyCode == $expCurrencyCode))
				{
					// Taxable Amount
					//$colTag .= '<col style="width:17%">' . PHP_EOL;
					$headTag .= '<th class="ar" style="max-width:26mm;background-color:'.$headColor.'">';
					$headTag .= (!$showTax || $isTaxDetailCol == 1 ) ? (mylang("Amount") . $curLable ) : (mylang("TaxableAmount")) . $curLable ;
					//$headTag .= mylang("Amount") . $curLable;
					//$headTag .= ($isExport ? substr($curLable, 4) : '') . '</th>' . PHP_EOL;
					$headTag .= '</th>' . PHP_EOL;
					if ($includeTax && (!$isTaxDetailCol || ($isTaxDetailCol == 1 || $isTaxDetailCol == 3)))
					{
						if (!$includeDiscount)
						{
							// Inclusive tax & Line Item Discount
							$bodyTag .= '<td nowrap="nowrap" class="lt1 ar taxableAmount" style="'.$bo_style.'">{itemTotal}</td>' . PHP_EOL;
							$sectionTag .= '<td nowrap="nowrap" class="lt1 ar" style="'.$bo_style.'">{itemTotal}</td>' . PHP_EOL;
							$subItemsTag .= '<td nowrap="nowrap" class="lt1 ar taxableAmount" style="'.$bo_style.'"></td>' . PHP_EOL;
							$salChargeTag .= '<td class="lt1 ar {chargeClass}" style="'.$bo_style.'">{itemTotal}</td>' . PHP_EOL;
							$afterTaxTag .= '<td class="lt1 ar {chargeClass}" style="'.$bo_style.'"><b>{itemTotal}</b></td>' . PHP_EOL;
						}
						else
						{
							// Inclusive tax & Line Item Discount
							$bodyTag .= '<td nowrap="nowrap" class="lt2 ar taxableAmount" style="'.$bo_style.'">{_itemTotal}</td>' . PHP_EOL;
							$sectionTag .= '<td nowrap="nowrap" class="lt2 ar" style="'.$bo_style.'">{_itemTotal}</td>' . PHP_EOL;
							$salChargeTag .= '<td class="lt2 ar {chargeClass}" style="'.$bo_style.'">{_itemTotal}</td>' . PHP_EOL;
							$afterTaxTag .= '<td class="lt2 ar {chargeClass}" style="'.$bo_style.'"><b>{_itemTotal}</b></td>' . PHP_EOL;
							$subItemsTag .= '<td nowrap="nowrap" class="lt1 ar taxableAmount" style="'.$bo_style.'"></td>' . PHP_EOL;
						}
					}
					else
					{
						if (!$includeDiscount)
						{
							// Exclusive tax & Line Item Discount
							$bodyTag .= '<td nowrap="nowrap" class="lt3 ar taxableAmount" style="'.$bo_style.'">{taxableAmount}</td>' . PHP_EOL;
							$sectionTag .= '<td nowrap="nowrap" class="lt3 ar" style="'.$bo_style.'">{taxableAmount}</td>' . PHP_EOL;
							$salChargeTag .= '<td class="lt3 ar {chargeClass}" style="'.$bo_style.'">{taxableAmount}</td>' . PHP_EOL;
							$afterTaxTag .= '<td class="lt3 ar {chargeClass}" style="'.$bo_style.'"><b>{itemTotal}</b></td>' . PHP_EOL;
							$subItemsTag .= '<td nowrap="nowrap" class="lt1 ar taxableAmount" style="'.$bo_style.'"></td>' . PHP_EOL;
						}
						else
						{
							// Exclusive tax & Total Discount
							$bodyTag .= '<td nowrap="nowrap" class="lt4 ar taxableAmount" style="'.$bo_style.'">{_taxableAmount}</td>' . PHP_EOL;
							$sectionTag .= '<td nowrap="nowrap" class="lt4 ar" style="'.$bo_style.'">{_taxableAmount}</td>' . PHP_EOL;
							$salChargeTag .= '<td class="lt4 ar {chargeClass}" style="'.$bo_style.'">{_taxableAmount}</td>' . PHP_EOL;
							$afterTaxTag .= '<td class="lt4 ar {chargeClass}" style="'.$bo_style.'"><b>{_itemTotal}</b></td>' . PHP_EOL;
							$subItemsTag .= '<td nowrap="nowrap" class="lt1 ar taxableAmount" style="'.$bo_style.'"></td>' . PHP_EOL;
						}
					}

					$cols++;
				}
				// $subItemsSpan++;
				//- $totWid -= 15;
			// }
		}

		if ($isTaxDetailCol == 2)
		{
			if ($showTax && !empty($taxTypes))
			{
				foreach($taxTypes as $taxType)
				{
					//	$colTag .= '<col style="width:8%">' . PHP_EOL;
					$headTag .= '<th style="" class="">' . $taxType . $curLable . '</th>' . PHP_EOL;
					if ($isCompact)
					{
						$bodyTag .= '<td class="ar fnt-small" style="'.$bo_style.'"><small>{' . $taxType . 'Rate}</small>&nbsp;&nbsp;{' . $taxType . 'Value}</td>' . PHP_EOL;
						$sectionTag .= '<td class="ar fnt-small" style="'.$bo_style.'"><small>{' . $taxType . 'Rate}</small>&nbsp;&nbsp;{' . $taxType . 'Value}</td>' . PHP_EOL;
					}
					else
					{
						$bodyTag .= '<td class="ar fnt-small" style="'.$bo_style.'">{' . $taxType . 'Value}<br><small>{' . $taxType . 'Rate}</small></td>' . PHP_EOL;
						$sectionTag .= '<td class="ar fnt-small" style="'.$bo_style.'">{' . $taxType . 'Value}<br><small>{' . $taxType . 'Rate}</small></td>' . PHP_EOL;
					}

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

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

				// Item Total
				$headTag .= '<th style="min-width:100px;" class="ar">'.mylang("Amount") . $curLable . '</th>' . PHP_EOL;
				$bodyTag .= '<td nowrap="nowrap" class="ar">{itemTotal}</td>' . PHP_EOL;
				$sectionTag .= '<td nowrap="nowrap" class="ar">{itemTotal}</td>' . PHP_EOL;
				$salChargeTag .= '<td nowrap="nowrap" class="ar {chargeClass}">{itemTotal}</td>' . PHP_EOL;
				//- $totWid -= 15;
				$cols++;
				$subTotalCols1++;
				$subItemsSpan++;
			}
		}

		$remarksTag = '';
		if (!empty($isRemarks))
		{
		
			$headTag .= '<th>Remarks</th>';
			$bodyTag .= '<td style="max-width:2cm;">&nbsp;</td>';
			$sectionTag .= '<td style="max-width:2cm;">&nbsp;</td>';
			$subItemsTag.= '<td style="max-width:2cm;">&nbsp;</td>';
			$salChargeTag .= '<td style="max-width:2cm;">&nbsp;</td>';
			$remarksTag = '<td style="max-width:2cm;border-bottom:1px solid black;">&nbsp;</td>';
		}

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

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

		echo $colTag;

		//- $bodyTag = str_replace('{nameWid}', $totWid ? $totWid : 20, $bodyTag);
		// echo str_replace('{nameWid}', $totWid, $bodyTag);
		if ($isExport)
		{
			$nameWid = ($cols <= 5 ? 70 : ($cols <= 9 ? (strlen($forexTaxableAmount) <= 9 ? 50 : 40) : 30));
			if (strlen($forexTaxableAmount) > 10)
			{
				$nameWid -= 10;
			}
		}
		else
		{
			$nameWid = ($cols <= 5 ? 70 : ($cols <= 9 ? (strlen($taxableAmount) <= 9 ? 40 : 40) : 30));
		}
		$headTag = str_replace('{nameWid}', $nameWid, $headTag);
		$tothead = 0; 
		$tothead = $cols-2;
		$chargesHtml = array( "ABT" => "", "LBT" => "", "AAT" => "", "LAT" => "", "AAL" => "", "LAL" => "", "ASV" => "");
		$lessChargesAmt = 0;
		$afterTaxCharges = 0;
		$beforeTaxCharges = 0;
		if (!empty($charges) && !($isSlip))
		{
			foreach($charges as $key => $charge_item)
			{
				// $charge_item["taxableAmount"]		= formatAmount($charge_item["taxableAmount"], $currencyCode, "-", true);
				// $charge_item["forexTaxableAmount"]	= formatAmount($charge_item["forexTaxableAmount"], $expCurrencyCode, "-", true);

				// if ($charge_item["unit"] == "LAT" || $charge_item["unit"] == "LBT" || $charge_item["unit"] == "LAL")
				if ($charge_item["unit"] != "ABT" && $charge_item["unit"] != "AAT" && $charge_item["unit"] != "ASV")
				{
					$lessChargesAmt += (float)$charge_item['taxableAmount'];
				}

				if ($charge_item["unit"] == "ABT")
				{
					$_itemTotal += (float)$charge_item['itemTotal'];
					$_taxableAmount += (float)$charge_item['taxableAmount'];
				}

				if ($charge_item["unit"] == "AAT" || $charge_item["unit"] == "LAT" || $charge_item["unit"] == "AAL" || $charge_item["unit"] == "LAL")
				{
					$afterTaxCharges += (float)$charge_item['taxableAmount'];
				}

				$lessReplace = "";
				if ($charge_item["unit"] == "LAT" || $charge_item["unit"] == "LBT" || $charge_item["unit"] == "LAL")
				{
					$charge_item['taxableAmount'] = formatAmount(abs($charge_item['taxableAmount']), $currencyCode, "-", true, $currFraction);
					$charge_item['itemTotal'] = formatAmount(abs($charge_item['itemTotal']), $currencyCode, "-", true, $currFraction);
					$lessReplace = "<i>(less)</i> ";
				}
				else
				{
					$charge_item['taxableAmount'] = formatAmount($charge_item['taxableAmount'], $currencyCode, "-", true,$currFraction);
					$charge_item['itemTotal'] = formatAmount($charge_item['itemTotal'], $currencyCode, "-", true,$currFraction);
				}

				if (!empty($charge_item['_taxableAmount']))
				{
					$charge_item['_taxableAmount'] = formatAmount($charge_item['_taxableAmount'], $currencyCode, "-", true, $currFraction);
				}
				else
				{
				    $charge_item['_taxableAmount'] = $charge_item['taxableAmount'];
				}

				if (!empty($charge_item['_itemTotal']))
				{
					$charge_item['_itemTotal'] = formatAmount($charge_item['_itemTotal'], $currencyCode, "-", true, $currFraction);
				}
				else
				{
				    $charge_item['_itemTotal'] = $charge_item['itemTotal'];
				}

				if ($isExport)
				{
					$charge_item['forexTaxableAmount'] = formatAmount($charge_item['forexTaxableAmount'], $expCurrencyCode, false, true, $currFraction);
					$charge_item['forexItemTotal'] = formatAmount($charge_item['forexItemTotal'], $expCurrencyCode, false, true, $currFraction);
				}

				//$charge_item['_forexTaxableAmount'] = formatAmount($charge_item['_forexTaxableAmount'], $currencyCode, "-", true, $currFraction);
				//$charge_item['_forexItemTotal'] = formatAmount($charge_item['_forexItemTotal'], $currencyCode, "-", true, $currFraction);

				if ($charge_item["unit"] == "ASV")
				{
					$charge_item['itemTotal'] = $charge_item['taxableAmount'];
				}

				if (!empty($charge_item["unit"]))
				{
					if ($charge_item["unit"] == "ABT")
					{
						$chargesHtml[$charge_item["unit"]] .= $this->parser->parse_str($salChargeTag, $charge_item, true);
					}
					else
					{
						$chargesHtml[$charge_item["unit"]] .= $this->parser->parse_str(str_replace("##LESS##", $lessReplace, $afterTaxTag), $charge_item, true);
					}
				}
			}
		}

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

				foreach ($details as $key => $val)
				{
					if (!empty($val["isHide"]))
					{
						continue;
					}	

					if (empty($val["itemName"]))
					{
						continue;
					}

					if (!empty($val['itemType']) && $val['itemType'] == 'S' && $val['unit'] == ''){
						$val["qty"] = "";
						$val["rate"] = "";
						$val["rateWithTax"] = "";
						$val["unit"] = "";
					}

					if(in_array($val["id"],$subItems_parents)) {
						$val["subItemParentClass"] =  "subItemParent";
					} else {
						$val["subItemParentClass"] =  "";										
					}

					$val["trClass"] = "item" . $key;
					if (!$val["itemType"] || $val["itemType"] == "B")
					{
						$val["qty"] = "";
						$val["itemName"] = '<b style="margin: 0px;">' . $val["itemName"] . '</b>';
						$val["itemTotal"] = '<b style="margin: 0px;">' . formatAmount($val["itemTotal"], $currencyCode, "-", true, $currFraction) . '</b>';
						$val["taxableAmount"] = '<b style="margin: 0px;">' . formatAmount($val["taxableAmount"], $currencyCode, "-", true, $currFraction) . '</b>';
						$val["_taxableAmount"] = '<b style="margin: 0px;">' . formatAmount($val["_taxableAmount"], $currencyCode, "-", true, $currFraction) . '</b>';

						$bodyTagHtml = $sectionTag;
						$val["trClass"] .= " section";
						$val["sectionSpan"] = $sectionSpan;
						echo $this->parser->parse_str($bodyTagHtml, $val, true);

						continue;
					}					
					if (!empty($val["subCode"]) && in_array($val["subCode"],array('AL','OA')))
					{
						
						if(count($details) > $key+1) {		
							if(!empty($details[$key+1]['subCode'] && in_array($details[$key+1]["subCode"],array('AL','OA')))){
								$val["subItemParentClass"] =  "subItemParent";
							}
						}
				
						$val["qty"] = "";									
						if($val["subCode"] == 'AL') {
							// $val["itemName"] = "<td class='noborder nopadding subCode_Al'><span class='alterItems'> OR </span></td><td class='noborder nopadding'><span> <span style='margin: 0px;'>". $val["itemName"];
							$val["itemName"] = "<td class='noborder nopadding subCode_Al'><img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAjCAYAAAAAEIPqAAAABHNCSVQICAgIfAhkiAAAABl0RVh0U29mdHdhcmUAZ25vbWUtc2NyZWVuc2hvdO8Dvz4AAAMBSURBVFiF7ZhPaNNQHMe/SZr+td2abRLbqRurCJvQKcgOE9lBqBcZKMXTFMGzIDhBUDz5B/HqSS9DBNn0MLzYeRBXT4Kw6iwbtNhS54pbm63t2iZN+jyIblmzueXQNrDP8ffyy/vk5ZeX9x5FCCEwGHSjBfSwJ10vTFrBj8k8QvEcYlkRFaX+Jc8yFHycBYEeF04ddta010iPzWTwbamEYK8bft4OM0PVRXQjkkIQSRcxERUQFyRc7m9TX0A2EE7kyOhUiohylTQDolwlo1MpEk7kVHFVTYfiOQR73Q0ZXS3MDIVgrxuheE4VV0nHsiL8vL2uYv/Dz9sRy4qqmEq6opCmGeW/mBmqZjIw5JRnSGnNeXonrJRljM8K+Ly4htVyFS4LDT9vx8VjHNrtf26bWJFwI5QCS6+XHMtQ6HZbMOLn4OOs9ZPOiwpuvVtAl9uM26c94J0sltZkvIoKuDn1A48DneBs67ceO9/971sRZYLJOQH3PqTxdPgwTPTuvyFd5TE5vwIbS2N0kMfBFjNYmoLHyeLawH54XSzGZ4Utcy0mCmePtCAvKVguynq61yf9JV3C4KF9oKnaURrqcmImXdwytywTvJlfRYfdhHaHvurUlVWQFNXr3whnM6EgKqrY1ckEAIAAKFWqGPA6cGfIA5PGQ+8EXdKtVhMyxYpmW7Ykw2VlVLFnw10wMxTkKsH1tyn4eTs8TlZP1wB0lkc/b8N0sgBZY9MznczjxAGHZp6JpnDJ34YXXzPIbXobu0GX9LmjrSAAHobTSK5KqFQJFvMVPPn0Cz9zFQT7WrfMPel1wMdZ8TyS0eusT9rG0rh/xgveweLB9CJGXn/H3fcLoCkKjwKdaLFuX3VXjrchnChgbrmsS1q1NL3wMlbXpedO2exlyN/4nnS9ML40y1CQGrD73g5JIWA3bUxU0j7Ogsg264ZGEEkX4eMsqphKOtDjwkRUaJrRlhSCiaiAQI9LFacIUf+Lm+3co6/DVnPuUSMNNP8Jk6Z0s2P8Kc8oGFL6N4i0Y+8UhW/qAAAAAElFTkSuQmCC'/></td><td class='noborder nopadding'><span> <span style='margin: 0px;'>". $val["itemName"];
							
						}

						if($val["subCode"] == 'OA') {
							// $val["itemName"] = "<td class='noborder nopadding subCode_OA'><span class='addonItem'> + Optional </span></td><td class='noborder nopadding'><span><span style='margin: 0px;'>". $val["itemName"];
							$val["itemName"] = "<td class='noborder nopadding subCode_OA'><img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFYAAAAhCAYAAABDcVyOAAAABHNCSVQICAgIfAhkiAAAABl0RVh0U29mdHdhcmUAZ25vbWUtc2NyZWVuc2hvdO8Dvz4AAAVXSURBVGiB7ZpRSFNfHMc/W2tmlkpuQQ0y10icSGRKMWMFPlRsEQW9hGDBoKKnkrAiKLBIgopeih7qIXwYWNDDGrGXYFpdLaIgrwaxomgP6zJTx+auW/f/EF5cm2nO6b+4n8fz+51zf/fL75z7O+dcnaIoChrzjn6xA/hX0YQtEIZcjX19fQSDQUKhEKlUaqFj+t9jMBiwWq04nU62bt2a2+fXhu7ubt6/f4/b7cZut2M0Ggse6N+GLMuIoojP5+Pz588cPHgw20mZgiAISkdHh5JMJhWNmUkmk0pHR4ciCEKWLWONDQaDuN1uLUtnidFoxO12EwwGs2wZwoZCIex2+4IF9i9gt9sJhUJZ7RnCplIpLVv/EKPRmPMDr5VbBSJnuTXfpNNpnjx5giAISJJEUVERVVVVuFwubDbbrMZ4+fIldrudkpISnj9/Tk9PD+3t7QWL+cyZM7S2tlJTUzOn/nkJm0gkCIVC1NbWTuujKAq3bt1CkiRaWlpYv349iUQCQRC4fv06x48fp66ubsZnPXr0iMrKSkpKSmhoaGDTpk35hF5w8hI2Go3i8/l+K+zAwACDg4NcunSJVatWAVBUVMTu3bsZHx/H6/VSV1dHb28v/f39mM1mwuEwsViMXbt2sX37dm7fvk0kEuHGjRscOHCAiYkJNWNlWebBgweIooiiKJjNZlpaWjCZTLx48YK+vj4sFgufPn1ieHiY5uZmmpubAXj37h0PHz4kkUig1+txuVw0NTXlI4lKwddYURSx2WyqqFNxOBxEIhEkSUKv1zM0NERTUxPt7e0cO3aMrq4uhoeHOXr0KAAnT56ksbExYwy/3084HObChQtcvnyZyspK7t69C/zcIQ0NDbF582ZOnz6Nx+Ohu7ubiYkJUqkUd+7cYf/+/XR2dnL48GHu37/P2NjYvLz3nDL2ypUrSJJEOp1mfHyctrY2APbu3cvOnTszfOPxOOXl5TnHmWyPxWIAmM1mrFYrABaLBbPZzIcPH9iyZcu0sbx+/RqXy8XSpUsB2LFjB36/n3g8DkBFRYW6jq9bt450Os3IyAgmk4mrV6+ybNkyADZu3MiSJUuQJImVK1fORZYM5iTs2bNnAfj69StdXV2//YiUlpby8ePHnLbv37+rPuFwmBUrVmTYi4uLVYGmY3R0NEOIyTFGR0fVMSbR639O0B8/fgDQ29vLq1evVHs6nUaZp1PUglcFtbW1BAIBIpEIq1evzrAJgsCaNWvUZWJSjElisViW2L9SVlaW0W9yKpeXl/Ply5dp+719+5bHjx9z/vx5TCYTiqJw4sSJP3q331HwNba6upr6+npu3rzJ4OAgyWSSkZERAoEAgUCAQ4cOqb7RaJSBgQHg5y4wGo1is9nQ6XTo9fqc2VtfX09PT49apD99+pSamhp1ik/H2NgYpaWlVFRUoCgKfr8fnU5HMpmcl/fOK2MtFsusakmPx0MgEMDr9fLt2zeMRiMbNmygra2Nqqoq1c9qtfLmzRu8Xi+pVIrW1lbKysoAaGxs5Nq1a+zbt4/ly5erffbs2UM8HufixYsoisLatWs5cuTIjDE1NDTQ39/PuXPnKC4uxuVysW3bNu7du8epU6fmoMYvTD2R8Xg8C3AmlJtnz54pnZ2di/b8fMilm7alLRCasAViQc4KZoPD4cDhcCx2GPOGlrEFIkNYg8GALMuLFctfiSzLGAzZEz9DWKvViiiKCxbUv4Aoiuo2fCoZwjqdTnw+n5a1s0SWZXw+H06nM8umU5TMzbF2/T0zU6+/q6urc15/ZwkL2g8bMzGbHzZyCquRP1q5VSA0YQuEJmyB+A/QvqO23rk5+AAAAABJRU5ErkJggg=='/></td><td class='noborder nopadding'><span><span style='margin: 0px;'>". $val["itemName"];
						}
						// if(!empty($val['bom'])) {
						// 	$bom = json_decode($val['bom'],true);
						// 	print_r($bom);
						// 	exit;							
						// }
						
						if (!empty($val["itemDesc"]))
						{
							$val["itemDesc"] = "<br><small style='padding-left:2px' class='subItemsItemDesc'>".str_replace(array("\r\n", "\r", "\n"), "<br>", $val["itemDesc"])."</small>";
						}
						$val["itemName"] = '<table class="noborder nopadding" style="width : 100%"><tbody><tr>'. $val["itemName"] .'</span><span>&nbsp;&nbsp;'.((!empty($includeTax) && empty($isratewithTax)) ?  formatAmount($val["rateWithTax"], $currencyCode, "-", true, $currFraction)  :  formatAmount($val["rate"], $currencyCode, "-", false, $currFraction)) .'</span><span> / </span><small>'.$val["unit"].'</small> </span>'.(!empty($val["itemDesc"]) ?  $val["itemDesc"]:'').'</td></tr></tbody></table>';
						// $val["itemName"] = '<div style="display: inline-flex; align-items: center;">'. $val["itemName"] . '</span> <b>'. ((!empty($includeTax) && empty($isratewithTax)) ?  formatAmount($val["rateWithTax"], $currencyCode, "-", true, $currFraction)  : formatAmount($val["rate"], $currencyCode, "-", false, $currFraction)) .'</b><span> / <small>'.$val["unit"].'</small> '.(!empty($val["itemDesc"]) ?  $val["itemDesc"]:'').'</span></div></div>';
						// echo '<pre>',print_r($val["itemName"],1),'</pre>';
						// exit;
						if (!empty($val["itemDesc"]))
						{
							$val["itemDesc"];
							$subItemsTag = str_replace('{itemDesc}', "", $subItemsTag);
						}
						$val["itemTotal"] = '<b style="margin: 0px;">' . formatAmount($val["itemTotal"], $currencyCode, "-", true, $currFraction) . '</b>';

						$bodyTagHtml = $subItemsTag;
						$val["trClass"] .= " subCode";
						$val["subItemsSpan"] = $subItemsSpan;
						echo $this->parser->parse_str($bodyTagHtml, $val, true);

						continue;
					}
					// if($val["subCode"]) {
					// 	echo  ''.$subItemsSpan;
					// 	exit;
					// }

					// if (!empty($val["subCode"]))
					// {
					// 	$val["qty"] = "";
					// 	$val["itemName"] = '<b style="margin: 0px;">' . $val["itemName"] . '</b>';
					// 	$val["itemTotal"] = '<b style="margin: 0px;">' . formatAmount($val["itemTotal"], $currencyCode, "-", true, $currFraction) . '</b>';

					// 	$bodyTagHtml = $sectionTag;
					// 	$val["trClass"] .= " section";
					// 	$val["sectionSpan"] = $sectionSpan;
					// 	echo $this->parser->parse_str($bodyTagHtml, $val, true);

					// 	continue;
					// }

					$rowNum++;

					$val['rate'] = !empty($val['rate'])?$val['rate']:0;
					//display printname if given
					if(!empty($val['printName']) && trim($val['printName']))
					{
						$val['itemName'] =  trim($val['printName']);
					}

					if ($isExpNonnGst && !empty($val['conName']))
					{
						$val['conName'] = " - " . $val['conName'];
					}

					if (!empty($isgrossAmount))
					{
						if ($includeTax)
						{
							$val['grossamt'] = $val['qty'] * $val['rateWithTax'];
						}
						else
						{
							$val['grossamt'] = $val['qty'] * $val['rate'];
						}
						$val['grossamt'] = formatAmount(!empty($val['grossamt']) ? $val['grossamt'] : 0, $isExport ? $expCurrencyCode : $currencyCode, "-", true, $currFraction);
					}
					// Pack Unit Changes.
					if (!empty($val["relUnitType"]) && $val["relUnitType"] == "P")
					{
						$val['itemName'] = $val['itemName'] . ' - ' . $val["relUnitName"];
						$val['unit'] = 'NOS';
					}
					if(!empty($val['unit'])){
						$unitArr[] = $val['unit']; 
						$val['qty'] = !empty($val['qty']) && $val['qty'] > 0 ? floatval($val['qty']) : 0;
						if(!empty($val['qty']))
						{
							$totQty += $val['qty'];
							if (!empty($val['freeQty']))
							{
								$totFreeQty += $val['freeQty'];
							}
						}
					}
					if (!empty($relunits) && $relunits == 1)
					{
						if(!empty($val['rel_units']) && empty($val['relUnitType']))
						{
							foreach($val['rel_units'] as $_key => $_val)
							{
								if($val['unit']  != $_val['name'])
								{
									if(!empty($val['qty']) && !empty($_val['convFactor']) && floatval($_val['convFactor']) > 0)
									{
										$val['unit'] = $val['unit'] .'<br>(' . number_format(($val['qty'] / $_val['convFactor']),2) .'&nbsp;'.$_val['name'] .')'; 
									}
								}
							}
						}

						if(!empty($val['rel_units']) && !empty($val['relUnitType']))
						{
							foreach($val['rel_units'] as $_key => $_val)
							{
								if($val['relUnitName']  != $_val['name'])
								{
									if(!empty($val['qty']) && !empty($val['convFactor']) && floatval($val['convFactor']) > 0)
									{
										if(empty($_val['type']))
										{
											$val['rel_qty'] = ($val['qty'] * $val['convFactor']);
											$val['unit'] = $val['unit'] .'<br>(' . ($val['rel_qty']) .'&nbsp;'.$_val['name'] .')'; 
										}
										if(!empty($_val['type']) && !empty($val['rel_qty']))
										{
											$val['unit'] = $val['unit'] .'<br>(' . number_format(($val['rel_qty'] / $_val['convFactor']),2) .$_val['name'] .')'; 
										}
									}
								}
							}
						}
					}
					if (!empty($relunits) && $relunits == 2) {
						if (!empty($val['rel_units'])) {
							foreach ($val['rel_units'] as $_val) {
								// Process when `relUnitType` is empty
								if (empty($val['relUnitType']) && $val['unit'] != $_val['name'] && !empty($val['qty']) && !empty($_val['convFactor']) && floatval($_val['convFactor']) > 0) {
									$convertedQty = number_format($val['qty'] / $_val['convFactor'], 2);
									$val['relunit'] = $convertedQty .'&nbsp;<small><small>'. $_val['name'].'</small></small>';
								}
					
								// Process when `relUnitType` is not empty
								if (!empty($val['relUnitType']) && $val['relUnitName'] != $_val['name'] && !empty($val['qty']) && !empty($val['convFactor']) && floatval($val['convFactor']) > 0) {
									$relQty = $val['qty'] * $val['convFactor'];
					
									if (empty($_val['type'])) {
											$val['relunit'] =  $relQty .'&nbsp;<small><small>'. $_val['name'] .'</small></small>';
									} elseif (!empty($val['rel_qty'])) {
										$convertedRelQty = number_format($val['rel_qty'] / $_val['convFactor'], 2);
										$val['relunit'] = $convertedRelQty .'&nbsp;<small><small>'. $_val['name'] .'</small></small>';
									}
								}
							}
						}
					}
					if (!empty($isSkuCol) && $isSkuCol && $isSkuCol == 1)
					{
						if(empty($val['SKU']))
						{
							$val['SKU'] = '';
						}
						if(!empty($val['SKU']))
						{
							$val['itemName'] = $val['SKU'] . " - " . $val['itemName'];
						}
					}
					if(!empty($isitemimage))
					{
						if(empty($val['filePath']))
						{
							$val['filePath'] = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
						}
					}
					
					if (empty($val["taxId"]) && !empty($company['countryCode']) && $company['countryCode'] == 'IN')
					{
						$val["taxName"] = "GST 0%";
					}
					$taxName = true;
					if((empty($val["taxName"]) && empty($val["taxId"])) || $val["taxName"]=="GST 0%")
					{
						$taxName = false;
					}
					
					if(!empty($val['freeQty']))
					{
						$val['freeQty'] = floatval($val['freeQty']);
					}

					// if (!empty($val['unit']))
					// {
					// 	$val['qty'] = !empty($val['qty']) && $val['qty'] > 0 ? floatval($val['qty']) : 0;
					// 	if(!empty($val['qty']) && $details[0]['unit'] == $val['unit'])
					// 	{
					// 		$totQty += $val['qty'];
					// 		if (!empty($val['freeQty']))
					// 		{
					// 			$totFreeQty += $val['freeQty'];
					// 		}
					// 	}
					// }
					if($tType == SALORD && empty($isPrint) && $status == 'S'  && !empty($val['curStk']) &&  floatval($val['qty']) > floatval($val['curStk']))
					{
						$val['curStkClass'] = 'outofstock';
					}
					else
					{
						$val['curStkClass'] = '';
					}

					if(!empty($taxTypes))
					{
						foreach($taxTypes as $_taxType)
						{
							$val[$_taxType . 'Value'] =  formatAmount(!empty($val[$_taxType.'Value']) ? $val[$_taxType.'Value'] : 0, $currencyCode, "-", true,$currFraction);
						}
					}

/*
					if (!empty($val['rateWithTax']))
					{
						if ($val['discType'] == '%' && !empty($val['discPercentage']))
						{
							$val['rateWithTax'] = $val['rateWithTax'] / (1 - $val['discPercentage']/100);
						}
						else if ($val['discType'] != '%' && !empty($val['discAmount']) && !empty($val['qty']) && $val['qty']!= '0')
						{
							$val['rateWithTax'] = $val['rateWithTax'] - ($val['discAmount'] / $val['qty']);
						}
					}
					else
					{
						if ($val['discType'] == '%' && !empty($val['discPercentage']))
						{
							$val['rateWithTax'] = $val['rate'] * (1 - $val['discPercentage']/100);;
						}
						else if ($val['discType'] != '%' && !empty($val['discAmount']) && !empty($val['qty']) && $val['qty']!= '0')
						{
							$val['rateWithTax'] = $val['rate'] - ($val['discAmount'] / $val['qty']);
						}
					}

					if(!empty($isratewithTax) && empty($includeTax) && !empty($val['totTaxRate']) && !empty($val['rateWithTax'])  )
					{
						$val['rateWithTax'] = round($val['rateWithTax'] * (1 + $val['totTaxRate'] / 100), 3);
					}

					if(!empty($isratewithTax) && !empty($includeTax) && $showTax && !empty($val['totTaxRate']))
					{
						$val['rate'] = round($val['rateWithTax'] / (1 + $val['totTaxRate'] / 100), 3);
					}
*/				
					if(!empty($val['_discAmount']))
					{
						$val['_discAmount'] = round($val['_discAmount'], 2);

						/*
						if ($includeDiscount)
						{
							$val['rateWithTax'] += ($val['_discAmount'] * $val['totTaxRate'] / 100);
						}
						*/
					}

					if(!empty($val['discAmount']))
					{
						$val['discAmount'] = round($val['discAmount'], 2);
					}
					
					if(!empty($val['rateWithTax']))
					{
						//$val['rateWithTax'] = round($val['rateWithTax'], 2);
					}

					if (!empty($val['discPercentage']))
					{
						$val['discPercentage'] = round($val['discPercentage'], 2);
						$val['discPercentage'] = empty(floatval($val['discPercentage'])) ? "" : ($val['discPercentage'] . "%");
					}

					if ($includeDiscount)
					{
						$val['discAmount'] = "";
						$val['excDiscAmount'] = "";
						// $val['taxableAmount'] = $val['qty'] * $val['rate'];

						$subTotal += $val['taxableAmount'];
					}
					else
					{
						$val['excDiscAmount'] =  !empty($val['discAmount']) ? $val['discAmount']: "";
						$val['discAmount'] = !empty($val['discAmount']) ? formatAmount($val['discAmount'], $currencyCode, "", true, $currFraction) : "";
						// $val['excDiscAmount'] = formatAmount($val['excDiscAmount'], $expCurrencyCode, "-", true);
						
					}

					$val['discount'] = $isExport ? $val['excDiscAmount'] : (!empty($val['discItem']) ? $val['discItem'] : 0);
					if(!empty($val['discount'])){
						$val['discount'] =  formatAmount($val['discount'], $expCurrencyCode, "", true, $currFraction);
					}
/*				
					if (empty($val['discount']) && !empty($val['_discAmount']) && $hasDiscount && (empty($issalerate_after_disc) || ($issalerate_after_disc == 1)))
					{
						$val['discount'] = $val['discItem'];// $val['_discAmount'];
					}
*/
					if (!empty($val['discType']) && $val['discType'] == "%" && !empty($val['discPercentage']) && empty($isdiscount))
					{
						$val['discount'] .= "<br/><small>" . $val["discPercentage"] . "</small>";
					}
					if(!empty($isdiscount) && $isdiscount == 2 && !empty($val['discType']) && ($val['discType'] == "%")){
						$val['discount'] =  $val["discPercentage"] ;
					}
					if (empty($val['discount']))
					{
						$val['discount'] = "-";
					}

					/*
					else
					{
						$val['discount'] = $isExport ? $val['excDiscAmount'] : $val['discAmount'];
						$val['discount'] = empty($val['discount']) ? "-" : $val['discount'];
						$val['_discAmount'] = "";
						$val['discAmount'] = "";
					}
					*/

					/*
					If 2 decimal selected & for customer input 
						5, it will display as 5
						5.1 , it will display as 5.10
						5.13 , it will display as 5.13
						5.112 , it will display as 5.112
						5.1124 , it will display as 5.112

						If 3 decimal selected & for customer input 
						5, it will display as 5
						5.1 , it will display as 5.100
						5.13 , it will display as 5.130
						5.112 , it will display as 5.112
						5.1124 , it will display as 5.112 (since in db we are having 3 digits only)
					*/
					if (!empty($val['qty']))
					{
						if (strpos( $val['qty'], '.' ) === false)
						{
							$val['qty'] = round($val['qty'],3);
						}
						else
						{
							$decimal_places = strlen(substr(strrchr($val['qty'], "."), 1));
							if ($decimal_places >= 3)
							{
								$val['qty'] = round($val['qty'],3);
							}
							else
							{
								$decimal_range  = (!empty($qtyFraction) && $qtyFraction == 3) ? "%.3f" : "%.2f";
								$val['qty'] = sprintf($decimal_range,round($val['qty'],3));
							}
						}
					}
					else
					{
						$val['qty'] = "";
					}

					$val['rateWithTax'] = formatAmount(!empty($val['rateWithTax']) ? $val['rateWithTax'] : 0, $isExport ? $expCurrencyCode : $currencyCode, "-", true, $rateFraction);

					if (!empty($val['unitRate']))
					{
						$unitRate = true;
					}

					//Netsale rate format changes
					if(!empty($val['unitRate']))
					{
						$val['unitRate'] =  formatAmount(!empty($val['unitRate']) ? $val['unitRate'] : 0, $isExport ? $expCurrencyCode : $currencyCode, "", true,$rateFraction);
					}

					$val['rate'] = formatAmount(!empty($val['rate']) ? $val['rate'] : 0, $isExport ? $expCurrencyCode : $currencyCode, "", true, $rateFraction);

					/*//Multiple currency changes
					if (!empty($val["rel_units"]))
					{
						foreach($val['rel_units'] as $_key => $_val)
						{
							if(!empty($_val['type']) && $_val['type'] == 'I'){
								if(!empty( $_val['saleRate'])){
									$val['rate'] = $val['rate'] .'<br><small style="font-style: italic;color: grey;font-weight: bold;">' . $_val['saleRate'].'&nbsp;'.$_val['name'] .'</small>';
								}
							}
						}
					}*/
					$strSalModCodes = get_company('salModCodes');
          			$salModCodes = explode(',',$strSalModCodes);
        		   	if(in_array('MC',$salModCodes)){
						$val["mrp"] = formatAmount(!empty($val['mrp']) ? $val['mrp'] : 0,$isExport ? $expCurrencyCode : $currencyCode, "-", true,$currFraction);
						if(!empty($val['itemcurrencyCode']) && !empty($val['mrp'])){
							if($tType != 'PI' && (( $isExport && $expCurrencyCode != $val['itemcurrencyCode']) ||  ( !$isExport && $val['itemcurrencyCode']!= get_company("currency")))){
								$val['mrp'] = $val['chargesAmount'] .'<br><small style="font-style: italic;color: grey;font-weight: bold;">' .$val['mrp'].'&nbsp;'.$val['itemcurrencyCode'] .'</small>';
							}else if($tType != 'PI' &&  $isExport && $expCurrencyCode == $val['itemcurrencyCode'] ){
								$val['mrp'] =  $val['mrp'] .'<small style="font-style: italic;color: grey;font-weight: bold;">' .'&nbsp;'.$val['itemcurrencyCode'] .'</small>';
							}
							else if($tType == 'PI' || ($tType == 'SI' && $val['itemcurrencyCode']== get_company("currency"))){
								$val['mrp'] =  $val['mrp'] .'<small style="font-style: italic;color: grey;font-weight: bold;">' .'&nbsp;'.$val['itemcurrencyCode'] .'</small>';
							}

						}
					}
					$val["_discAmount"] = !empty($val["_discAmount"]) ? $val["_discAmount"] : $val["discAmount"];

					if(!empty($val['_taxableAmount']))
					{
						$_taxableAmount += $val['_taxableAmount'];
						$val['_taxableAmount'] = formatAmount($val['_taxableAmount'], $currencyCode, "-", true,$currFraction);
					}
					$val['saleRate'] =  !empty($val['saleRate'])?formatAmount($val['saleRate'], $expCurrencyCode, "-", true,$currFraction):0;
					//$val['mrp'] =  !empty($val['mrp'])?formatAmount($val['mrp'], $expCurrencyCode, "-", true,$currFraction):0;
					$val['taxableAmount'] = formatAmount($val['taxableAmount'], $currencyCode, "-", true,$currFraction);
					$val['forexTaxableAmount'] = !empty($val['forexTaxableAmount'])?formatAmount($val['forexTaxableAmount'], $expCurrencyCode, "-", true,$currFraction):0;
					// $val['_forexTaxableAmount'] = !empty($val['_forexTaxableAmount'])?formatAmount($val['_forexTaxableAmount'], $expCurrencyCode, "-", true,$currFraction) : $val['forexTaxableAmount'];
					$val["itemTotal"] = formatAmount($val['itemTotal'], $currencyCode, "-", true,$currFraction);
					if (!empty($val['_itemTotal']))
					{
						$_itemTotal += $val['_itemTotal'];
						$val['_itemTotal'] = formatAmount($val['_itemTotal'], $currencyCode, "-", true,$currFraction);
					}

					if (!empty($val["itemDesc"]))
					{
						$val["itemDesc"] = str_replace(array("\r\n", "\r", "\n"), "<br>", $val["itemDesc"]);
					}
					
					if(!empty($val['specifications']))
					{
						$cnt = 0;
						foreach($val['specifications'] as $_key => $_val)
						{
							$val["itemDesc"] .= $_key.' : ';
							foreach($_val as $vl => $_vl)
							{
								$cnt++;
								$val["itemDesc"] .= $_vl;
								if($cnt !=  count($_val))
								{
									$val["itemDesc"] .= ', ';
								}
							}
							$cnt = 0;
							$val["itemDesc"] .= "<br>";
						}
					}

					if (!empty($val['sys_attrs']))
					{
						$sys_attrs	='<table align="left" cellspacing="0" cellpadding="0" width="100%" class="noborder"><tbody><tr>';
						$idx=0;
						$wid = 100 / count($val['sys_attrs']);
						foreach($val['sys_attrs'] as $k=>$sys)
						{
							$val['attr_' . $k] = $sys ? $sys : "-";
							if (!empty($sys))
							{
								$sys_attrs .= '<td class="' . $align[$idx%3] . '" style="width: ' . $wid . '%;background:none"><small>' . ($sys ? $sys : '-') . '</small></td>';
							}
							$idx++;
						}
						$sys_attrs.='</tr></tbody></table>';
						$val['sys_attrs'] = $sys_attrs;
					}

					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;
						}
					}

					$val['rowNum'] = $rowNum;

					$bodyTagHtml = $bodyTag;
					if(empty($val['freeQty']))
					{
						$bodyTagHtml = str_replace("{freeQty}", "-", $bodyTagHtml);
						$bodyTagHtml = str_replace("&nbsp;<small><small>{unit}</small></small>", "", $bodyTagHtml);
					}

					$val["attribField"] = "";
					if (!empty($attribFields) && !empty($attribFields[$val["id"]]))
					{
						$val["attribField"] = '<br><span class="desc nm pretxt">' . $attribFields[$val["id"]] . '</span>';
					}

					$bodyTagHtml = str_replace("{itemDesc}", (!empty($isItemDesc) &&!empty($val['itemDesc']))? '<br><span class="fnt-11 desc nm pretxt">{itemDesc}</span>' : '', $bodyTagHtml);
					$bodyTagHtml = str_replace("{cfList}", (!empty($isItemDesc)&&!empty($val['cfList'])) ? '<br><span class="fnt-11 desc nm pretxt">{cfList}</span>' : '', $bodyTagHtml);

					echo $this->parser->parse_str($bodyTagHtml, $val, true);
					
					if ($isPrint && $isFullPage &&  $key == $cnt-1)
					{
						if (!empty($paper))
						{
							echo "{{EMPTY";
							echo $this->parser->parse_str($bodyTag, array("itemName" => '<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" width="10px" height="##TransImgHeight##mm"  />',"filePath"  =>"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"), true);
							echo "EMPTY}}";
						}
						// echo $this->parser->parse_str($bodyTag, array("itemName" => '<div style="display:inline-block;width:20px;height:##TransImgHeight##mm;"></div>'), true);
					}
				}
			}
			$unitArr = array_map("strtoupper", $unitArr);
			//To find if the quantity is same for all
			$unitArrCnt = count(array_unique($unitArr));
			/******Multiple units(two distinct units ) total qty calculation ******/
			$multiple_units = array_values(array_unique($unitArr));
			if(!empty($unitArrCnt) && ($unitArrCnt > 0) && ($unitArrCnt <= 2))
			{
				$_totQty = $_totfreeQty = array();

				foreach ($multiple_units as $_val)
				{
					$_val = strtoupper($_val);
					if(!isset($_totQty[$_val]))
					{
						$_totQty[$_val] = 0;
					}
					if(!isset($_totfreeQty[$_val]))
					{
						$_totfreeQty[$_val] = 0;
					}
				}

				foreach ($details as $key => $val)
				{
					$_val = strtoupper($val['unit']);
					if(isset($_totQty[$_val]))
					{
						$_totQty[$_val] = $_totQty[$_val] + $val['qty'];
					}
					if(isset($_totfreeQty[$_val]) && !empty($val['freeQty']))
					{
						$_totfreeQty[$_val] = $_totfreeQty[$_val] + $val['freeQty'];
					}
				}
			}
			
			if (!empty($chargesHtml["ABT"]))
			{
				echo $chargesHtml["ABT"];
			}	
			//For delivery challan classic template to display totalqty ensure qty setting and totqty setting is enabled
	if(((empty($hideAmount) && empty($isclassictemp)) || (!empty($isclassictemp)&& !empty($gridFields) && !empty($istotqty)) || (!empty($isclassictemp)&& !empty($isqty) && !empty($istotqty) && !empty($unitArrCnt) && $unitArrCnt<3 )) && ($tType !='PE'))
	{
		?><tr class="subtot"><?php
			if ($isAllAccount && $tType =='PI')
			{
				// $subTotalCols += -1;
			}
			$_subTotalCols = $subTotalCols;
			$flag1 = true;
			
			$subTotalTd = '<td style="border-bottom:1px solid black" class="subTotal title bob" colspan="##SUBTOTALCOLS##">';// ' . $subTotalCols . '
			$subTotalTd .= '<table width= "100%" class="nb noborder np"><tr>';
			 //Total savings will be displayed for net sale rate without disc column setting 
			if(!empty($issalerate_after_disc) && ($issalerate_after_disc == 2) && !empty($totDisc) && ($hasDiscount))
			{
				$subTotalTd .= '<td width= "50%"><b>'.mylang("TotalSavings").'&nbsp;&nbsp;&nbsp;' .$totDisc.'</b></td>';
			}
			if (empty($fontname))
			{
				$subTotalTd .= '<td class="ar np" style="padding-top: -2px;" width= "50%">'.($includeTax && empty($isclassictemp) ? "(Tax Included) " : "") . '<b>' . mylang('SubTotal') . '</b></td></tr></table>';
			}
			else
			{
				$subTotalTd .= '<td class ="ar np" style="padding-top: -2px;" width= "50%">'.($includeTax && empty($isclassictemp) ? "(Tax Included) " : "") . '<span>' . mylang('SubTotal') . '</span></td></tr></table>';
			}
			$subTotalTd .= '</td>';

			if (!empty($gridFields))
			{
				$flag1 = false;
				foreach($gridFields as $gf)
				{
					$subTotalTd .= '<td style="border-bottom:1px solid black" class="ar bob">';
					$subTotalTd .= !empty($gf['total']) ? $gf['total'] : '';
					$subTotalTd .= '</td>';
				}
			}

			// qty col
			if (empty($hideQty) && !empty($isqty) && !empty($istotqty))
			{
				/******Multiple units(two distinct units ) total qty calculation ******/
				if(!empty($_totQty) && !empty($unitArrCnt) && ($unitArrCnt == 2) && count($details) > 0)
				{
					$flag1 = false;
					$subTotalTd .= '<td style="border-bottom:1px solid black" class="ar bob qty">';
					foreach($_totQty as $_ky => $_vl)
					{
						$subTotalTd .= $_vl . '&nbsp;<small><small>' . $_ky . '</small></small><br>';
					}
					$subTotalTd .= '</td>';
					if (!empty($isFreeQty))
					{
						$subTotalTd .= '<td style="border-bottom:1px solid black" class="ar bob qty">';

						foreach($_totfreeQty as $_ky => $_vl)
						{
							if(!empty($_vl)){
								$subTotalTd .= $_vl . '&nbsp;<small><small>' . $_ky . '</small></small><br>';
							}
						}
						$subTotalTd .= '</td>';
					}
				}
				/***Total unit display if units are same ****/
				else if($unitArrCnt == 1 && count($details) > 0)
				{
					$flag1 = false;
					$subTotalTd .= '<td style="border-bottom:1px solid black" class="ar bob qty">';
					$subTotalTd .= $totQty . (!empty($units)  && ($units == 1) ? '&nbsp;<small><small>' . $details[0]['unit'] . '</small></small>': '' );
					$subTotalTd .= '</td>';
					if (!empty($isFreeQty))
					{
						if ($totFreeQty)
						{
							$subTotalTd .= '<td style="border-bottom:1px solid black" class="ar bob totFreeQty">';
							$subTotalTd .= $totFreeQty . (!empty($units) ?'&nbsp;<small><small>' . $details[0]['unit'] . '</small></small>' : '');
							$subTotalTd .= '</td>';
						}
						else
						{
							$subTotalTd .= '##EMPTYTD##';
							$_subTotalCols++;
						}
					}
				}
				else
				{
					$subTotalTd .= '##EMPTYTD##';
					$_subTotalCols++;

					if (!empty($isFreeQty))
					{
						$subTotalTd .= '##EMPTYTD##';
						$_subTotalCols++;
					}
				}
			}
			else if (empty($hideQty) && !empty($isqty) && empty($istotqty))
			{
				if (!empty($isFreeQty))
				{
					$subTotalTd .= '##EMPTYTD##';
					$_subTotalCols++;
				}
				$subTotalTd .= '##EMPTYTD##';
				$_subTotalCols++;
			}

			if (empty($hideQty) && empty($isqty) && !empty($isFreeQty))
			{
				$subTotalTd .= '##EMPTYTD##';
				$_subTotalCols++;
			}

			if (!empty($units) && $units && $units == 2){
				$subTotalTd .= '##EMPTYTD##';
				$_subTotalCols++;
			
			}
		
			if (!empty($relunits) && $relunits && $relunits == 2){
				$subTotalTd .= '##EMPTYTD##';
				$_subTotalCols++;
			
			}
			// MRP col
			if ((!empty($isSales) || !empty($mrpInPurSal)) && !empty($isMrpCol) && $hasMrp && empty($hideQty))
			{
				// $subTotalTd .= '<td style="border-bottom:1px solid black" class="ar bob"></td>';
				$subTotalTd .= '##EMPTYTD##';
				$_subTotalCols++;
			}

			if (!empty($issaleRate) && ($tType == PURINV || $tType == 'SK'))
			{
				$subTotalTd .= '##EMPTYTD##';
				$_subTotalCols++;
			}
			if(!empty($isratewithTax))
			{
				$subTotalTd .= '##EMPTYTD##';
				$_subTotalCols++;
			} 
			if(!empty($isgrossAmount))
			{
				$subTotalTd .= '##EMPTYTD##';
				$_subTotalCols++;
			} 
			// Rate col
			// $subTotalTd .= '<td style="border-bottom:1px solid black" class="ar bob"></td>';
			if (!$hideRate)
			{
				$subTotalTd .= '##EMPTYTD##';
				$_subTotalCols++;
			}
			// Discount col
			if ($hasDiscount && (empty($issalerate_after_disc) || ($issalerate_after_disc == 1)))
			{
				if (!empty($totDiscItem))
				{
					$subTotalTd .= '<td style="border-bottom:1px solid black" class="ar bob totDisc">';
					$subTotalTd .= $totDiscItem;
					$subTotalTd .= '</td>';
				}
				else
				{
					$subTotalTd .= '##EMPTYTD##';
					$_subTotalCols++;
				}
			}
			if (!empty($issalerate_after_disc) && $unitRate)
			{
				$subTotalTd .= '##EMPTYTD##';
				$_subTotalCols++;
			}

			if(!empty($issalerate_after_disc) && ($issalerate_after_disc == 2) && !empty($totDisc) && ($hasDiscount)){
				$subTotalTd .= '##EMPTYTD##';
				$_subTotalCols++;
			}

			if(!empty($isratewithTax))
			{
				//$flag1 = false;
				//$subTotalTd .= '##EMPTYTD##';
				//$_subTotalCols++;
			}
			
			if (!$flag1 || ($isExport && $currencyCode == $expCurrencyCode))
			{
				$subTotalTd = str_replace("##EMPTYTD##", '<td style="border-bottom:1px solid black" class="ar bob emptyTd"></td>', $subTotalTd);
				$subTotalTd = str_replace("##SUBTOTALCOLS##", $subTotalCols, $subTotalTd);
			}
			else
			{
				$subTotalTd = str_replace("##EMPTYTD##", '', $subTotalTd);
				$subTotalTd = str_replace("##SUBTOTALCOLS##", $_subTotalCols, $subTotalTd);
			}
		//$iscalssictemp ->Delivery challan classic template
		if(empty($isclassictemp)){
			// tax cols
			if($showTax && !empty($taxTypes) && $isTaxDetailCol)
			{
				if ($isTaxDetailCol == 2)
				{
					// Total taxable amt in export currency
					if ($isExport && $currencyCode != $expCurrencyCode)
					{
						$subTotalTd .= '<td nowrap="nowrap" style="border-bottom:1px solid black" class="ar subTotal value bob ST1"><b>';
						$subTotalTd .= $forexTaxableAmount;
						$subTotalTd .= '</b></td>';
					}

					$subTotalTd .= '<td nowrap="nowrap" style="border-bottom:1px solid black" class="ar subTotal value bob ST2"><b>';
					$subTotalTd .= formatAmount($taxableAmount, $currencyCode, false, $isExport ? true : false,$currFraction);
					$subTotalTd .= '</b></td>';

					foreach($taxTypes as $_taxType)
					{
						//if (!empty($totTaxes[$_taxType]))
						//{
							$subTotalTd .= '<td style="border-bottom:1px solid black" class="ar subTotal value bob ST3">';
							$subTotalTd .= !empty($totTaxes[$_taxType])  ?  formatAmount($totTaxes[$_taxType], $expCurrencyCode, false, true,$currFraction) : '';
							$subTotalTd .= '</td>';
						//}
					}
				}
				else
				{
					if($isTaxDetailCol != 3){
					$subTotalTd .= '<td style="border-bottom:1px solid black" class="ar bob"></td>';
					}
					// Total taxable amt in export currency
					if ($isExport && $currencyCode != $expCurrencyCode)
					{
						$subTotalTd .= '<td nowrap="nowrap" style="border-bottom:1px solid black" class="ar subTotal value bob ST4"><b>';
						$subTotalTd .= $forexTaxableAmount;
						$subTotalTd .= '</b></td>';
					}
					
				}
			}
			// Total taxable amt in export currency
			else if ($isExport && $currencyCode != $expCurrencyCode)
			{
				$subTotalTd .= '<td nowrap="nowrap" style="border-bottom:1px solid black" class="ar subTotal value bob ST5"><b>';
				$subTotalTd .= $forexTaxableAmount;
				$subTotalTd .= '</b></td>';
			}
			//GST 0%
			if(($showTax && empty($taxTypes) && $isTaxDetailCol == 1)){
				$subTotalTd .= '<td nowrap="nowrap" style="border-bottom:1px solid black" class="ar subTotal value bob ST7"><b> ';
			}
			if (($isExport && $currencyCode != $expCurrencyCode) || ($showTax && !empty($taxTypes) && $isTaxDetailCol == 2))
			{
				if ((!$isQuote ) || ($isQuote && !$isExport))
				{
					$subTotalTd .= '<td nowrap="nowrap" style="border-bottom:1px solid black" class="ar subTotal value bob ST6"><b>';
					// $subTotalTd .= $roundAmount ? $roundtot : $f_totAmount;
					$subTotalTd .= $roundAmount ? $roundtot : ($isExport ? ( $currencyCode != $expCurrencyCode ? formatAmount($_taxableAmount, $currencyCode, false, true,$currFraction) : $f_totAmount ) : $f_totAmount);
					$subTotalTd .= '</b>'.(!empty($headColor) ? '&nbsp;': '').'</td>';
				}
			}
			else
			{ 
				$subTotalTd .= '<td nowrap="nowrap" style="border-bottom:1px solid black" class="ar subTotal value bob ST7"><b> ';
/*
				$taxtot = !empty(($taxableAmount - $lessChargesAmt)) ? ($taxableAmount - $lessChargesAmt) : "";
				$taxtot = round(floatval($taxtot), 2);
				$subTotalTd .= formatAmount($taxtot, $currencyCode, "-", true,$currFraction);
*/

				if ($includeTax)
				{
					$taxtot = $_itemTotal;
				}
				else
				{
					$taxtot = $_taxableAmount;
				}
/*
				if ($includeTax && $isTaxDetailCol != 2)
				{
					$taxtot = !empty($afterTaxCharges) ? ($taxableAmount - $afterTaxCharges) : $taxableAmount;
					// $taxtot -= $lessChargesAmt;
				}
				else if (!$includeTax && !empty($_taxableAmount))
				{
					$taxtot = $_taxableAmount;
				}
				else if ($includeTax && $_itemTotal)
				{
					$taxtot = $_itemTotal;
				}
				else
				{
					$taxtot = $taxableAmount;// !empty($lessChargesAmt) ? ($taxableAmount + $lessChargesAmt) : $taxableAmount;
				}
*/
				// $taxtot += $beforeTaxCharges;
				$taxtot = round(floatval($taxtot), 2);//  + floatval($totDiscAmt)
				$subTotalTd .= formatAmount($taxtot, $currencyCode, "-", true,$currFraction);
				
				$subTotalTd .= '</b></td>';
			}
		}
			echo empty($isHideTotal) ? $subTotalTd : "";
			echo $remarksTag;
		?></tr><?php
	}
?>	</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 ($roundAmount) {
		$rowspan++;
	}
	if (!empty($tdsPercentage)) {
		$rowspan++;
	}

	$rowspan++; // Total Amt

	if (!empty($trans_payment)) {
		$rowspan += count($trans_payment);
	}
	if ($dueAmount) {
		$rowspan++;
	}

				
if (empty($hideAmount) || (!empty($isclassictemp) && !empty($isTaxDetailCol)))
{
	?>
<table align="left" border="0" cellspacing="0" cellpadding="0" class="footTable  hsntable nbh2 wpw" <?php echo empty($issimpletemp) ? 'style="width:100%;clear:both;"': 'style="width:100%;clear:both;"' ?>><?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 width="60%" class="wrp">
				<?php if(empty($isHideTotal) &&  !empty($isamountinwords) && $tType != 'PI') { ?>
				<div class="nm amtinwords" style="white-space: pre-line; word-wrap: break-word !important;">Amount (in words) :<br><?php
					if ($isExport && $expCurrencyCode)
					{
						echo $expCurrencyCode . ' ' . $exp_amt_str . " only";
					}
					else
					{
						// $currencyCode
						echo $amt_str . " only";
					}
				?></div><br><?php
				}

				if (!empty($returnableGoods) && !empty($isRG))
				{
					echo "Returnable Stock :";
					foreach($returnableGoods as $rKey => $rValue)
					{
						echo "<p>" . $rValue["itemName"] . " : <b>" . number_format($rValue["value"]) . "</b> <small>" . $rValue["uom"] . "</small></p>";
					}
					echo "<br>";
				}
				//Bank details display for "RETAIL INVOICE"
				//********************************************
				if(!empty($isBankDetail) && ($tType == 'SR' && !empty($bank)))
				{ 
					?><div>
					<table class="bank accInfo noborder nopadding nwrap" border="0" cellspacing="0" cellpadding="0" <?php echo !empty($showVerticalLine) ? 'style="width:100%;padding:5px;border-left: 4px solid '.$headColor.';page-break-inside: avoid"' : 'style="page-break-inside: avoid"' ?> autosize="1">
						<tbody>
							<tr>
								<td class="wrp" colspan="2">
									<p class="bank title nm">
									<?php if(empty($fontname)){ ?><?php echo mylang("OurBankDetails")?>
							<?php } else{?>
								<b><?php echo mylang("OurBankDetails")?></b>
								<?php } ?>
									</p>
								</td>
							</tr>
							<tr>
								<td class="accNumber title wrp vat" ><?php echo mylang("AccountNo"); ?></td>
								<td class="accNumber value wrp ">&nbsp;: <b><?php echo $bank['accNumber']; ?></b></td>
<?php
								if (!empty($upi))
								{
?>									<td rowspan="5"  >&nbsp;&nbsp;&nbsp;<barcode code="<?php echo getUpiLink($upi["name"], $upi["id"], $totAmount, $tNo); ?>" class="qr" size="1" text="0" disableborder="1" type="QR" /><br><?php if($isPrint){ echo $upi["id"]; }?></td>
<?php
								}
?>
							</tr>
							<tr>
								<td class="accName title wrp vat"><?php echo mylang("AccountName");?></td>
								<td class="accName value wrp">&nbsp;: <b><?php echo $bank['accName']; ?></b></td>
							</tr>
							<tr>
								<td class="bankName title wrp vat"><?php echo mylang("Bank");?></td>
								<td class="bankName value wrp">&nbsp;: <b><?php echo $bank['bankName']; ?></b></td>
							</tr>
							<tr>
								<td class="ifsc title wrp vat"><?php echo mylang("IFSCCode"); ?></td>
								<td class="ifsc value wrp">&nbsp;: <b><?php echo $bank['ifscRouteCode']; ?></b></td>
							</tr>
							<tr>
								<td class="branch title wrp vat"><?php echo mylang("Branch"); ?></td>
								<td class="branch value wrp">&nbsp;: <b><?php echo $bank['branchName']; ?></b></td>
							</tr>
							<?php  
								if(!empty($upi) && !empty($isBankDetail) && $isBankDetail == 3){?>
							<tr>
								<td class="branch title wrp vat"><?php echo mylang("UPI");?></td>
								<td class="branch value wrp">&nbsp;: <b><?php echo $upi['id']; ?></b></td>
							</tr>	
							<?php }					
							?>
							
							
<?php

					//if(!empty($company['countryCode']) && $company['countryCode'] != 'IN')
					if($isExport)
					{
						if ($swiftCode) {
							?><tr>
								<td class="swift title wrp vat"><?php echo mylang("SwiftCode"); ?></td>
								<td class="swift value wrp">&nbsp;: <b><?php echo $bank['swiftCode']; ?></b></td>
							</tr><?php
						}
						if (!empty($corrBank))
						{
							?><tr>
								<td class="corrBank title wrp"><?php echo mylang("CorrespondentBank"); ?></td>
								<td class="corrBank value">&nbsp;: <b><?php echo $bank['corrBank']; ?></b></td>
							</tr><?php
						}
/*
						if (!empty($corrBank))
						{
							$corrBank = array_map("trim", explode(",", $corrBank));
							$corrBank = implode(PHP_EOL, $corrBank);
							?><tr>
								<td class="corrBank title wrp">Correspondent Bank</td>
								<td class="corrBank value wrp">&nbsp;: <pre style="margin-left: 12px;"><b><?php echo $corrBank; ?></b></pre></td>
							</tr><?php
						}
*/
						if ($adCode) {
							?><tr>
								<td class="dealer title wrp"><?php echo mylang("ADCode"); ?></td>
								<td class="dealer value wrp">&nbsp;: <b><?php echo $bank['adCode']; ?></b></td>
							</tr><?php
						}
					}
						?></tbody>
					</table></div><br><?php
				}
				
				//Bank details display for "PURCHASE BILL & SALES INVOICE
				//*******************************************************
				if (!empty($isBankDetail) && $tType == 'PI')
				{
					if(!empty($conBank)){
					extract($conBank);
					}
				}
				if(!empty($isBankDetail) && ($tType == 'PI' || !empty($bankAccId)) && !empty($accType) && ($tType != 'SR'))
				{ 
					
					?><div>
					<table class="bank accInfo noborder nopadding nwrap" border="0" cellspacing="0" cellpadding="0" <?php echo !empty($showVerticalLine) ? 'style="width:100%;padding:5px;border-left: 4px solid '.$headColor.';page-break-inside: avoid"' : 'style="page-break-inside: avoid"' ?> autosize="1">
						<tbody>
							<tr>
								<td class="wrp" colspan="2">
									<p class="bank title nm">
									<?php if(empty($fontname)){ ?><?php echo mylang("OurBankDetails")?>
							<?php } else{?>
								<b><?php echo mylang("OurBankDetails")?></b>
								<?php } ?>
									</p>
								</td>
							</tr>
							<tr>
								<td class="accNumber title wrp vat" ><?php echo mylang("AccountNo"); ?></td>
								<td class="accNumber value wrp ">&nbsp;: <b><?php echo $accNumber; ?></b></td>
<?php
								if (!empty($upi) && !empty($isBankDetail) && $isBankDetail != 3)
								{
									if(!empty($isBankDetail) && $isBankDetail == 2)
									{
										$val = !empty($dueAmount) ? $dueAmount : $totAmount;
									}
									else
									{
										$val = '';
									}
									
?>									<td rowspan="5">&nbsp;&nbsp;&nbsp;<barcode code="<?php echo getUpiLink($upi["name"], $upi["id"],$val, $tNo); ?>" class="qr" size="1" text="0" disableborder="1" type="QR" /><br><?php if($isPrint){ echo $upi["id"]; }?></td>
<?php							}
?>							</tr>
							<tr>
								<td class="accName title wrp vat"><?php echo mylang("AccountName"); ?></td>
								<td class="accName value wrp">&nbsp;: <b><?php echo $bankAccName; ?></b></td>
							</tr>
							<tr>
								<td class="ifsc title wrp vat"><?php echo mylang("IFSCCode"); ?></td>
								<td class="ifsc value wrp">&nbsp;: <b><?php echo $ifscRouteCode; ?></b></td>
							</tr>
							<tr>
								<td class="bankName title wrp vat"><?php echo mylang("Bank");?></td>
								<td class="bankName value wrp">&nbsp;: <b><?php echo $bankName; ?></b></td>
							</tr>
							<tr>
								<td class="branch title wrp vat"><?php echo mylang("Branch");?></td>
								<td class="branch value wrp">&nbsp;: <b><?php echo $branchName; ?></b></td>
							</tr>
							
							<?php  
								if(!empty($upi) && !empty($isBankDetail) && $isBankDetail == 3){?>
							<tr>
								<td class="branch title wrp vat"><?php echo mylang("UPI");?></td>
								<td class="branch value wrp">&nbsp;: <b><?php echo $upi['id']; ?></b></td>
							</tr>	
							<?php }					
							?>
							
<?php
					//if(!empty($company['countryCode']) && $company['countryCode'] != 'IN'){
						if($isExport){
						if ($swiftCode) {
							?><tr>
								<td class="swift title wrp vat"><?php echo mylang("SwiftCode");?></td>
								<td class="swift value wrp">&nbsp;: <b><?php echo $swiftCode; ?></b></td>
							</tr><?php
						}
						if (!empty($corrBank))
						{
							?><tr>
								<td class="corrBank title wrp"><?php echo mylang("CorrespondentBank");?></td>
								<td class="corrBank value">&nbsp;: <b><?php echo $corrBank; ?></b></td>
							</tr><?php
						}
/*
						if (!empty($corrBank))
						{
							$corrBank = array_map("trim", explode(",", $corrBank));
							$corrBank = implode(PHP_EOL, $corrBank);
							?><tr>
								<td class="corrBank title wrp">Correspondent Bank</td>
								<td class="corrBank value wrp">&nbsp;: <pre style="margin-left: 12px;"><b><?php echo $corrBank; ?></b></pre></td>
							</tr><?php
						}
*/
						if ($adCode) {
							?><tr>
								<td class="dealer title wrp"><?php echo mylang("ADCode");?></td>
								<td class="dealer value wrp">&nbsp;: <b><?php echo $adCode; ?></b></td>
							</tr><?php
						}
					}
						?></tbody>
					</table></div><br><?php
				}
				if(!empty($is_ecom)){
					$json_data = json_decode($info,true);
				?>
					<table class="tbecom noborder nopadding nwrap" border="0">
						<colgroup>
							<col style="width:25%" />
							<col style="width:75%" />
						</colgroup>
						<tbody>
						<?php
							if(!empty($json_data['shipTitle'])){
						?>
							<tr>
								<td><b>Shipping Mode</b></td>
								<td>:&nbsp;<?= $json_data['shipTitle']; ?></td>
							</tr>
						<?php
							}
						?>
						<?php
							/*if(!empty($json_data['paymentTitle'])){
						?>
							<tr>
								<td><b>Payment Mode</b></td>
								<td>:&nbsp;<?= $json_data['paymentTitle']; ?></td>
							</tr>
						<?php
							}*/
						?>
						<?php
							if(!empty($json_data['payReference'])){
						?>
							<tr>
								<td><b>Reference ID</b></td>
								<td>:&nbsp;<?= $json_data['payReference']; ?></td>
							</tr>
						<?php
							}
						?>
						<?php
							if(!empty($json_data['payComments'])){
						?>
							<tr>
								<td><b>Comments</b</td>
								<td>:&nbsp;<?= $json_data['payComments']; ?></td>
							</tr>
						<?php
							}
						?>
						</tbody>
					</table>
				<?php
				}
				if($notes)
				{
					?><span class="nm notes pretxt"><?php echo $notes; ?></span><br><br><br><?php
				}
			?>
			</td>
			<td width="40%" class="npl npr wrp vat">
				<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 ($includeDiscount && $totDisc)
					{
?>						<tr>
							<td class="ar totDisc title wrp" colspan="<?php echo $isExport ? 1 : 2; ?>">
								<small><i>less</i></small> Discount <?php echo empty($discountPercent) ? "" : ((int)$discountPercent . "%"); ?>
							</td><?php

							if ($isExport)
							{
								?><td class="ar totDisc value wrp"><?php
									echo $totDisc;
								?></td><?php
							}
							?><td class="ar totDisc value wrp">
								<b><?php
									// echo $totDisc;
									echo $isExport ? formatAmount($forexTotDisc, $expCurrencyCode, false, true, $currFraction) : $totDisc;
								?></b>
							</td>
						</tr>
<?php
					}

					if (!empty($chargesHtml["LBT"]))
					{
						echo $chargesHtml["LBT"];
					}

					if ((($isTaxDetailCol == 3) || ($isTaxDetailCol == 1)) && !empty($tax) && (!$isExport || $classCode == 'EXPWP'))
					{
						if ($showTaxBreakup)
						{
							if(!empty($tax)){
							// Tax to be paid on Reverse Charge
							foreach ($tax as $key => $tax_item)
							{
					?><tr class="<?php echo 'taxitem-' . $key . ' '; 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['taxName'] . ' ' . round($tax_item['taxRate'], 2);

							if ($tax_item['taxCalc'] == "Q")
							{
								echo '/Unit';
							}
							else
							{
								echo '% <small>on ' . (empty($tax_item['taxableAmt']) ? '' : formatAmount($tax_item['taxableAmt'], $currencyCode, '', true,$currFraction)). '</small>';
							}
						?></td>
						<td class="ar tax value wrp"><?php
							echo $includeTax ? '' : '<b>';
							echo formatAmount($tax_item['taxValue'], $currencyCode, "-", true,$currFraction);
							echo $includeTax ? '' : '</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, "-", true,$currFraction); ?></b></td>
					</tr><?php
							}
						}
					}
				}
					if (($isExport && $classCode == 'EXPWOP' && !$isQuote) || $classCode == 'SEZWOP')
					{
						echo '<tr class="">';
						echo '<td class="ar tax title wrp" colspan="2">';
						// echo 'IGST @ 0.00% on ' . $taxableAmount;
						echo 'IGST @ 0% Against LUT';
						echo '</td>';
						echo '<td class="ar tax value wrp"><b>0.00</b></td>';
						echo '</tr>';
					}
					if($roundAmount && empty($isclassictemp))
					{
					?><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($chargesHtml["AAT"]))
					{
						echo $chargesHtml["AAT"];
					}
					if (!empty($chargesHtml["LAT"]))
					{
						echo $chargesHtml["LAT"];
					}
					if(!empty($tdsPercentage) && $tdsPercentage != 0 && !empty($tdsAmount))
					{
					?><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
					}

					$lessChargesHTML = "";
					$totLessCharges = 0;
					$tot_charge = false;
					if (!empty($charges))
					{
						foreach($charges as $key => $charge_item)
						{
							if( $charge_item["unit"] == "LAL" || $charge_item["unit"] == "AAL")
							{
								$tot_charge = true;
								$charge_item['taxableAmount'] = formatAmount($charge_item['taxableAmount'], $currencyCode, "-", true,$currFraction);
								if( $charge_item["unit"] == "AAL" ){
									$totLessCharges += abs($charge_item['itemTotal']);
								}
								if( $charge_item["unit"] == "LAL" ){
									$totLessCharges -= abs($charge_item['itemTotal']);
								}
								$lessChargesHTML .= '<tr class=""><td class="ar charges title wrp" colspan="2">';
								if($charge_item["unit"] == "LAL")
								{
									$lessChargesHTML .= '<i>(less) </i>';
								}
								$lessChargesHTML .= $charge_item["itemName"];
								if (!empty($charge_item["conName"]))
								{
									$lessChargesHTML .= ' <small>(' . $charge_item["conName"] . ')</small>';
								}
								$lessChargesHTML .= '</td>';
								
								$lessChargesHTML .= '<td class="ar charges value wrp"><b>';
								$lessChargesHTML .= formatAmount(abs($charge_item['itemTotal']), $currencyCode, "-", true,$currFraction);
								$lessChargesHTML .= '</b></td>';
								$lessChargesHTML .= '</tr>';
							}
						}

						if(!empty($tot_charge))
						{
							$lessChargesHTML .= '<tr class=""><td class="ar charges title wrp" colspan="2"><b>Final Total</b></td><td class="ar charges value wrp"><b>';
							//if ($charge_item["unit"] == "AAL")
							//{
								$lessChargesHTML .= formatAmount($totAmount +$totLessCharges, $currencyCode, "-", true,$currFraction);
							//}
							//else
							//{
							//	$lessChargesHTML .= $f_totAmount;
							//}
							$lessChargesHTML .= '</b></td></tr>';
						}
					}
					//For digital client ,in delivery challan classic template total must be displayed only if tax setting is enabled 
					if(!empty($isclassictemp)&& empty($isTaxDetailCol)){
						$isHideTotal = true;
					}
					if (empty($isHideTotal))
					{
					?><tr>
						<td class="ar total value vam wrp" colspan="<?php echo $isExport && !$isQuote ? 2 : 3; ?>" <?php echo !empty($isPrint)? 'style="border-top:none;padding:0px;"':'';?> style="background-color:<?php echo $headColor; ?>">
						<small><b><?php echo mylang("TOTAL"); ?>&nbsp;&nbsp;&nbsp;</b></small><?php
						// Export invoices
						// !$isQuote &&
						if ($isExport)
						{
							echo '<b>' . $forexTotAmount . '</b><br/><small><small>' . $expCurrencyCode . '</small></small>';
						}
						else
						{
							// echo '<b style="margin-right: 4px;">' . $f_totAmount . '</b>';
							echo '<b>';
							echo formatAmount($totAmount, $isExport ? $expCurrencyCode : $currencyCode, "-", $isExport ? true : false,$currFraction);
							echo '</b>';
						}

						?></td><?php
						if ($isExport && !$isQuote)
						{
							?><td class="ar total value vam wrp">
								<b><?php
									$totAmount = ($classCode == 'EXPWP' ? ($totAmount + $totTax) : $totAmount);
									$totAmount =formatAmount($totAmount, $currencyCode, "-", $isExport ? true : false, $currFraction);
									echo $totAmount  . '</b><br/><small><small>' . $currencyCode . '</small></small>';
								?></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>' . $forexTaxableAmount . '</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

						echo $lessChargesHTML;
					}

						if (!empty($trans_payment) && !empty($incOldBal) && (($incOldBal == 1) ||($incOldBal == 2)))
						{
							$class = '';
							$writeOff = $forexWriteOff = 0;
							// $totPayment = 0;
							foreach ($trans_payment as $key => $tpi)
							{
								// $totPayment += $tpi["allotAmt"];

								$class = (count($trans_payment) == 0) ? 'bob' : (($key == count($trans_payment)-1) ? 'bob' : '');
								if (!empty($tpi['writeOff']))
								{
									$writeOff += $tpi['writeOff'];
									// $totPayment += $tpi["writeOff"];
								}

								if (!empty($tpi['forexWriteOff']))
								{
									$forexWriteOff += $tpi['forexWriteOff'];
								}

								$bob_val = ($class  == 'bob')  ? "style='border-bottom: 1px solid black;'"  : "";

							?><tr class="">
								<td <?php echo $bob_val; ?> class="ar payment title wrp <?php echo $class; ?>" <?php echo $isExport ? '' : 'colspan="2"'; ?> ><?php
									echo '(-) ' . $paymentTypes[$tpi['tType']];
									if (!$isPrint)
									{
										echo '<a class="refLink" href="javascript:;" onClick="parent && parent.OBooks && typeof parent.OBooks.showTrans === \'function\' && parent.OBooks.showTrans(' . $tpi["id"] . ', \'' . $tpi["tType"] . '\', \'' . $tpi["tNo"] . '\')">' . $tpi['tNo'] . '</a>';
									}
									else
									{
										echo $tpi['tNo'];
									}
									echo ' ';
									echo '<small>' . date_format(date_create($tpi['tDate']),"d/m/Y") . '</small>';
								?></td><?php
								if ($isExport)
								{
									echo '<td colspan="2" class="ar forexAmount value export wrp ' . $class . '"' . $bob_val . '>';
									echo '<small>' . $expCurrencyCode . '</small>&nbsp;&nbsp;';
									echo $tpi['forexAmount'];
									echo '</td>';
								}
								if (!$isExport)
								{
									echo '<td class="ar payment value wrp ' . $class . '" ' . $bob_val . '>' . formatAmount($tpi['allotAmt'] + $tpi['tdsAmt'], $currencyCode, "-", true,$currFraction) . '</td>';
								}
							?></tr><?php
								if ($writeOff)
								{
									echo '<tr><td class="ar payment writeoff title wrp" '.($isExport ? '' : 'colspan="2"').'>Write-Off</td>';
									if ($isExport)
									{
										echo '<td class="ar forexAmount value export wrp ">' . $forexWriteOff. '</td>';
									}
									echo '<td colspan="2" class="ar payment value wrp" '.($isExport ? 'colspan="2"':'').'>'.formatAmount($writeOff, $currencyCode, "-", true,$currFraction).'</td></tr>';
								}
							}

							// if (($totPayment - $totAmount) > 0)
							// {
							// 	echo '<tr><td class="ar payment returnBal title wrp" ' . ($isExport ? '' : 'colspan="2"').'>Returnable Balance</td>';
							// 	if ($isExport)
							// 	{
							// 		echo '<td class="ar forexAmount value export wrp "></td>';
							// 	}
							// 	echo '<td colspan="2" class="ar payment returnBal value wrp" '.($isExport ? 'colspan="2"':'').'>'.formatAmount($totPayment - $totAmount, $currencyCode, "-", true);
							// 	echo '</td></tr>';
							// }
						}

						/*if (!empty($tType) && ($tType == 'SR')   && !empty($charges) && !empty($incOldBal) && (($incOldBal == 1) ||($incOldBal == 2)))
						{
							$totcharge = 0; $bal =0;
							foreach($charges as $key => $item)
							{
								$totcharge += $item['taxableAmount'];
							}

							if(!empty($totAmount) && !empty($totcharge))
							{
								$bal = $totcharge + $totAmount;
							}
								$bal =  formatAmount($bal, $currencyCode, '');
							?>
							<tr>
								<td class="ar dueamt title wrp" <?php echo $isExport ? '' : 'colspan="2"'; ?>>Balance</td>
								<td class="ar dueamt value wrp"><b><?php echo $bal;?></b></td>
							</tr>
							<?php
						}*/
						?>
						<?php 
						if(sal_mod_active(POINTS_MOD)  && !empty($points) && !empty($points['pOut_value'])){
							echo '<tr>';
							echo '<td colspan="2" class="ar dueamt title wrp" >(-) Redeem Points ('.$points['pOut'].')</td>';
							echo '<td class="ar dueamt title wrp" >'. formatAmount($points['pOut_value'], $currencyCode, '').'</td>';
							echo '</tr>';
							$bal =0;
							$bal = $totAmount-$points['pOut_value'];
							echo '<tr>';
							echo '<td  class="ar value vam wrp" style="border-top:1px solid black;border-bottom:1px solid black;" colspan="2"><big><b>Grand Total</b></big></td>';
							echo '<td style="border-top:1px solid black;border-bottom:1px solid black;" class="ar dueamt title wrp" ><big><b>'. formatAmount($bal, $currencyCode, '','',$currFraction).'</b></big></td>';
							echo '</tr>';
						}
						if(sal_mod_active(POINTS_MOD)  && !empty($available_points)){?>
							<tr>
								<td colspan ="3" class="ar dueamt title wrp" >
									<?php
										if(empty($available_points['pIn']) && !empty($availpoavailable_pointsints['pOpen'])) {
												echo mylang("AvailablePoints")." (Bal) : ".$available_points['pOpen'];
										}?>
										<?php if(!empty($available_points['pIn']) && empty($available_points['pOpen'])) {
												echo mylang("AvailablePoints")." (Added) : ".$available_points['pIn'];
										}?>
										<?php if(!empty($available_points['pOpen']) && !empty($available_points['pIn'])) {
											echo mylang("AvailablePoints")." (Bal : ".$available_points['pOpen']. " + Added : ".$available_points['pIn'] ." )  :  " .$availpoints['pOpen'];
										}?>
								</td>
							</tr>
					<?php }?>
					<?php
						if (!empty($dueAmount) && !empty($incOldBal) && (($incOldBal == 1)))
						{
							?><tr>
								<td class="ar dueamt title wrp" <?php echo $isExport ? '' : 'colspan="2"'; ?>>
<?php
								if(empty($fontname))
								{
									echo '<b>'.$dueAmount_text.'</b>';
								}
								else
								{
									echo '<span>'.$dueAmount_text.'</span>';
								}
								?></td><?php

							if ($isExport)
							{
								echo '<td colspan="2" class="ar forexDueAmount value wrp">';
								if ($f_forexDueAmount)
								{
									echo '<small>' . $expCurrencyCode . '</small>&nbsp;&nbsp;';
									echo '<b>' . $f_forexDueAmount . '</b>';
								}
								else
								{
									echo "-";
								}
								echo '</td>';
							}
							else
							{
								echo '<td class="ar dueamt value wrp"><b>';
								echo (!$isEstimate) ? formatAmount($dueAmount, $currencyCode, '','',$currFraction) : '-';
								echo '</b></td>';
							}
?>
							</tr><?php
						}

						if (!empty($outstanding) && !empty($incOldBal) && ($incOldBal == 2))
						{
							if (!empty($oldDue))
							{
							?><tr>
								<td class="ar title wrp" colspan="2"><?php echo mylang("ExistingBalance")?></td>
								<td class="ar value wrp"><?php echo $oldDue; ?></td>
							</tr><?php
							}

							if (!empty($newDue))
							{
							?><tr>
								<td class="ar title wrp" style="border-top:1px solid;" colspan="2"><?php echo mylang("TotalBalance")?></td>
								<td class="ar value wrp" style="border-top:1px solid;"><b><?php echo $newDue; ?></b></td>
							</tr><?php
							}
						}
						if (!empty($incOldBal) && ($incOldBal == 3))
						{
							/*All these are calculated based on transDate.
								Get opening balance value for transDate-1
								others-All transactions for this customer other than the current invoice & receipts.
								Receipts -Get Sum of all Receipts for this customer on same transdate*/
							//Total Balance : TransAmount + Opening Balance + Others - Receipts
							$daytot = 0;
							if (!empty($daybalance))
							{
									$daytot = ($isExport ?$forexTotAmount : $totAmount)+$daybalance['open'] + $daybalance['other'] - $daybalance['receipt']; 
									$daytot = !empty($daytot) ? formatAmount($daytot, $currencyCode,'','',$currFraction) :'';
									$sign =  !empty($daybalance['open']) &&  $daybalance['open'] > 0  ? '(+)' : '(-)';
									$othersign =  !empty($daybalance['other']) &&  $daybalance['other'] > 0  ? '(+)' : '(-)';
									$daybalance['open'] = !empty($daybalance['open']) ? formatAmount($daybalance['open'], $currencyCode,'','',$currFraction) :'';
									$daybalance['other'] = !empty($daybalance['other']) ? formatAmount($daybalance['other'], $currencyCode,'','',$currFraction) :'';
									$daybalance['receipt'] = !empty($daybalance['receipt']) ? formatAmount($daybalance['receipt'], $currencyCode,'','',$currFraction) :'';
									
							?>
								<?php if(!empty($daybalance['open'])){?>
								<tr>
									<td class="ar title wrp" colspan="2"><?php echo $sign .mylang("Opening Balance").' '.$tDate;?></td>
									<td class="ar value wrp"><?php echo $daybalance['open']; ?></td>
								</tr>
								<?php }  if(!empty($daybalance['other'])){?>
								<tr>
									<td class="ar title wrp" colspan="2"><?php echo $othersign.mylang("Other Transactions");?></td>
									<td class="ar value wrp"><?php echo $daybalance['other']; ?></td>
								</tr>
								<?php } if(!empty($daybalance['receipt'])){?>
								<tr>
									<td class="ar title wrp" colspan="2"><?php echo mylang("(-) Receipt");?></td>
									<td class="ar value wrp"><?php echo $daybalance['receipt']; ?></td>
								</tr>
								<?php } ?>
								<tr>
									<td class="ar title wrp" style="border: 1px solid black; border-left: none; border-right: none;" colspan="2"><b><?php echo "Total Balance as on ".$tDate;?></b></td>
									<td class="ar value wrp" style="border: 1px solid black; border-left: none; border-right: none;"><b><?php echo $daytot; ?></b></td>
								</tr>
								<?php
							}
						}

					if (!empty($chargesHtml["ASV"]))
					{
						echo $chargesHtml["ASV"];
					}
					
						/*
						// 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
						}
						*/
					?><tr>
						<td valign="top" colspan="3" class=" ar eoe nb">
							<p class="nm ar"><small><?php echo mylang("E&O.E")?></small></p>
						</td>
					</tr>
					</tbody>
				</table>
			</td>
		</tr>
	</tbody>
</table>
<!--<?php if($tType != 'PI' && !empty($isBankDetail) && !empty($bankAccId) && !empty($accType) && !empty($issimpletemp))
				{?>
				<table  class="noborder bank accInfo"  cellspacing="0" cellpadding="0" style="page-break-inside: avoid;width:100%;border-left: 1px solid black;border-right: 1px solid black"  autosize="1">
						<tbody>
						
							<tr>
								<td style="text-align: center;">
								
								<h3>
								<?php echo $accNumber; ?>&nbsp; / &nbsp;
								<?php echo $bankAccName; ?>&nbsp; / &nbsp;
								 <?php echo $branchName; ?>&nbsp; / &nbsp;
								<?php echo $ifscRouteCode; ?>&nbsp;
								
								</h3></td>
							</tr>
<?php
					if ($isExport)
					{
						if ($swiftCode) {
							?>
								<b><?php echo $swiftCode; ?></b>/
						<?php	
						}
						if (!empty($corrBank))
						{
							?>
								 <b><?php echo $corrBank; ?></b>/
							<?php
						}
						if ($adCode) {
							?>
								<b><?php echo $adCode; ?></b>/
							<?php
						}
					}
						?></tbody>
					</table>
				
				<?php }?>
-->

<?php
}
	// if (!empty($isFullPage) || !empty($isHsnBreakup)) {
	/*
	if (!empty($isHsnBreakup)) {
		echo '<p class="nm ar"><small>E & O.E</small></p>';
	}
	*/
	
	if (!empty($taxTypes) && !empty($isTaxPanel) && ($isTaxPanel == 1) && !empty($hsnBreakup))
	{
		$this->view("export/hsn");
	}
	else if (!empty($taxTypes) && !empty($isTaxPanel) && ($isTaxPanel == 2) && !empty($taxBreakup))
	{
		$this->view("export/taxwisebreakup");
	}

		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>E & O.E</small></p>';
	}
	*/
?>
<?php if(!empty($eInvoice) && !empty($isshowEinvDetails) && (!empty($S_IRN) || !empty($S_EWB))) { 
?>
<table class="eInvoInfo noborder nopadding nwrap" border="0" cellspacing="0" cellpadding="0" <?php echo empty($isvertical) ? 'style="width:100%;padding-left:5px;border:1px solid;border-top:0px;border-right:1px solid;page-break-inside: avoid;padding-top: 5px;padding-bottom: 5px;"' : 'style="width:100%;padding-left:5px;border-left: none !important;border-top:1px solid;border-right: none !important;page-break-inside: avoid;padding-bottom: 5px;"' ?> autosize="1">
						<colgroup>
							<col style="width:25%" />
							<col style="width:25%" />
							<col style="width:50%" />
						</colgroup>
						<tbody>
							<?php if (!empty($S_IRN)) {?>
							<tr>
								<td class="wrp vat" colspan="3">
									<p class="bank title nm">
									 <?php if(empty($fontname)){
												echo '<b>E-Invoice Details</b>';
											}else{
												echo '<span>E-Invoice Details</span>';
											}
									?>
								</td>
								<?php if($isPrint) { ?>
									<td rowspan="4" width="15%"><barcode code="<?php echo $S_IRN['SignedQRCode']; ?>" class="qr" size="1" text="0" disableborder="1" type="QR" /></td>
								<?php } ?>
							</tr>
							<tr>
								<td class="accNumber title wrp vat"  colspan="2">
									IRN No&nbsp;:
								 <?php /*if(empty($fontname)){
											echo '<b>'. $S_IRN['Irn'] .'</b>';
										}else{*/
											echo '<br><span>'.$S_IRN['Irn'] .'</span>';
										//}
								?>
								</td>
								<td>&nbsp;</td>
							</tr>
							<tr>
								<td class="accName title wrp vat">
									Ack No&nbsp;:
									<?php if(empty($fontname)){
												echo '<b>'. $S_IRN['AckNo'] .'</b>';
											}else{
												echo '<span>'. $S_IRN['AckNo'] .'</span>';
											}
									?>
								</td>
								<td class="accName title wrp vat">
									Ack Date&nbsp;:
									<?php if(empty($fontname)){
											echo '<b>'. $S_IRN['AckDt'] .'</b>';
										}else{
											echo '<span>'. $S_IRN['AckDt'] .'</span>';
										}
									?>
								</td>
								<td colspan></td>
							</tr>
							<?php } ?>
							<?php if (!empty($S_EWB)) {?>
								<?php if (empty($S_IRN)) { ?>
								<tr>
									<td class="wrp vat" colspan="3">
										<p class="bank title nm">
										<?php if(empty($fontname)){
													echo '<b>E-Way Bill Details</b>';
												}else{
													echo '<span>E-Way Bill Details</span>';
												}
										?>
									</td>
								</tr>
								<?php } ?>
								<tr>
									<td class="accName title wrp vat">
										EWB No&nbsp;:
										<?php if(empty($fontname)){
													echo '<b>'. $S_EWB['EwbNo'] .'</b>';
												}else{
													echo '<span>'. $S_EWB['EwbNo'] .'</span>';
												}
										?>
									</td>
									<td class="accName title wrp vat">
										EWB Valid Till&nbsp;:
										<?php if(empty($fontname)){
													echo '<b>'. $S_EWB['EwbValidTill'] .'</b>';
												}else{
													echo '<span>'. $S_EWB['EwbValidTill'] .'</span>';
												}
										?></span>
									</td>
									<td colspan="2"></td>
								</tr>
							<?php } ?>
							
<?php
				
						?></tbody>
					</table>
<?php } ?>
<?php if($tType != PURINV){ ?>
	
<table align="left" cellspacing="0" cellpadding="0" class="footTable nbt wpw" autosize="1" style="page-break-inside: avoid">
	<!--<col style="width:50%;">
	<col style="width:50%;">-->
	<tbody>
	<?php
	if ($terms)
	{
		?><tr>
			<td valign="bottom" colspan="2" class="vab terms" ><?php
				?><div class="noside " style="display:inline-block;"><span class="nm pretxt"><?php echo mylang("Terms")?> :<br><?php echo nl2br($terms); ?></span></div>
			</td>
		</tr><?php
	}	
		$isSign = isset($isSign) ? $isSign : 1;
		if ((!$is_email || !empty($company['invsign'] || !empty($is_pdf))) && !empty(trim(lang("For"))))
		{
			$clr = ($headColor == 'transparent') ? 'black' : $headColor;
		if(!empty($isSign)) { ?><tr>
			<td class="ar bgColor" colspan="<?php echo (!empty($transQr) && !empty($issimpletemp) && !empty($qrTransImg)) ? 3 : 2; ?>"  style="color:<?php echo $clr; ?>" ><?php echo mylang("ForcompanyName"); ?></td>
		</tr><?php } 
		}
		?>
		
		<?php if(!empty($isCustSign) || !empty($signOnPrint) || !empty($isSign)){?>
		<tr><?php
			$hgt = '';
			
			if(empty($isSign)) {
				$hgt = '100px';
			}
			echo '<td valign="bottom" class="vab nbr custsign bgColor" style="height: '.$hgt.'" >';
			if ((!$is_email  ||!empty($is_pdf)) && !empty($isCustSign))
			{ 
				$clr = ($headColor == 'transparent') ? 'black' : $headColor;
				echo '<span class="" style="margin-top:40px;color:'.$clr.'" >' . $tType == DELCHALLAN ? mylang("Received") :((!empty($pdf_type) && $pdf_type == 'Original for Buyer') ?  mylang("CustomerSignatureOriginal") : mylang("CustomerSignature")) . '</span>';
			}
			echo '</td>';
			if (!empty($transQr) && !empty($issimpletemp) && !empty($qrTransImg))
			{
				echo '<td style="border:0px;width: auto;" width ="25%">';
				?><img src="<?php echo $qrTransImg; ?>" style="width:4cm;height:4cm;" class="" /><?php
				echo '</td>';
			}
			echo '<td valign="bottom" class="vab ar authsign bgColor" style="color:'.$headColor.'" >';
			//echo $eOe;
			if ($tType != PURINV && !empty(trim(lang("For")))) {
				if (!empty($company['invsign']) && (!empty($signOnPrint)))// $isPrint
				{
					$clr = ($headColor == 'transparent') ? 'black' : $headColor;
					echo '<span class="sign"><img src="' . $company['invsign'] . '" width="" height="" style="margin-top:0px;color:'.$clr.'" /></span><br>';
					if(!empty($isSign)) {
						echo '<span style="color:'.$clr.'">'.mylang("AuthorizedSignature").'</span>';
					}
				}
				else if (!empty($isSign) && (!$is_email || !empty($company['invsign'] || !empty($is_pdf))))
				{
					$clr = ($headColor == 'transparent') ? 'black' : $headColor;
					echo '<br><br><br><span class="" style="margin-top:40px;float:right;color:'.$clr.'">'.mylang("AuthorizedSignature").'</span>';
				}
			}
			echo '</td>';
		?></tr>
		<?php } ?>
	</tbody>
</table><?php
}
//$email_color = empty($color) ? '#208ED3' : $color;
//$headColor = (empty($is_email) ? $bgColor : $email_color);
/*if(count(explode(",",$export_type)) > 1) {
		$headColor = $colorr;
	}*/

		if(!empty($isfooterimg) && !empty($footerImg))
		{
					if($paper == 'A5')
					{
						$img_height = '75px';
					}
					else
					{
						$img_height = '120px';
					}
					
					echo '<table align="left" cellspacing="0" cellpadding="0" class="footTable nbt wpw" autosize="1" style="page-break-inside: avoid"><tbody><tr><td colspan="2"  width="100%"><div class="" ><img style="height:auto; width: 100%;display: inline-block;" src="' . $footerImg . '" /></div></td></tr></tbody></table>';
		}
				
		if ( !empty($footerText) && !in_array($tType, array(PURINV, PURCRNOTE, PURDBNOTE, PURADVPMT, EXPRETAIL, PURPMT)))
		{
			
			if(strlen($footerText)< 1024){
				echo '<p class="footerTxt nm pretxt">' . nl2br($footerText) . '</p>';
			}
		}
/*
		if (!empty($isFullPage))
		{
			// echo '</page_footer></end_last_page>';
		}

		if (!$isQuote)
		{
			echo '<page_footer><p class="genby nm">' . lang('CMPUTER_GENERATED_DOCUMENT') . '</p></page_footer>';
		}
*/
		if (!empty($waterMark))
		{ 
		//	echo '<p class="watermark nm">' . $waterMark . '</p>';
		}
?>
<style>


.detailTable {
	width: 100%;
	display: inline-block;
	margin-top: 10px;
}
.accInfo {
	width: auto;
}
<?php if(!empty($isvertical) && $isvertical != '2' ) { ?>

.subtot td {
	
	border-top:1px solid black !important;
}
.inv_details tbody .tbody td:nth-child(odd) 
{
	background-color: #f2f2f2;
}
<?php } ?>
table, table td, table th {
	
	border-color:<?php echo 'black' ?>;/*$headColor == "transparent"?'#000000':$borderColor*/
}



<?php if(empty($isvertical)) { ?>
.subtot td {
	border-top: none;
	border-bottom: none;
		
}
<?php } ?>

table thead.bgcolor th {
	background-color: <?php echo $headColor; ?> !important;
	color: <?php echo $foreColor; ?> !important;
}
p.curr small {
	width: 50%;
	text-align: center;
	display: inline-block;
}
.tc {
	color: <?php echo $headColor; ?> !important;
}
.total {
	background-color: <?php echo $headColor; ?> !important;
	color: <?php echo $foreColor; ?>;
}
.vl {
 	border-left: 4px solid <?php echo $headColor; ?> !important;
	padding-left:5px !important;
}
.ft{
	border-top:1px solid black !important;
}

.as {
	color:black;
}
.disc{
	font-style: italic;
	color: grey;
	font-weight: bold;
	padding-right: 15px;
}
.bob {
	border-bottom:1px solid grey !important;
}
.wrp {	
	white-space: nowrap !important;
}
<?php
if(empty($isPrint)) {
	if (!empty($taxTypes) && !empty($isHsnBreakup)){
		echo '
		.hsntable{
			border-bottom: none !important;
		}';	
	}
}

if(empty($isPrint)) {
	if(empty($isvertical)) {
		echo '
.subTotal,.total {
	border-bottom:1px solid #000000 !important;
}';
	}

	if(empty($isvertical)) {
		echo '
.first {
	border-right:0.5px solid #000000;
	border-left:1px solid #000000;
}';
	}

}
if (empty($isPrint)) {
	echo '
.total {
	border-top:none !important;
}';
}

//if (empty($fontname)) {
	echo '
.bank.accInfo td.value {
	font-weight: bold;
}';
//}

?>
.bob {
	border-bottom:1px solid grey !important;
}
.tbecom tr td{
	white-space: nowrap !important;
}
td.tax.value, td.tax.title, tr.charges2 td {
	padding-top: 0px;
	padding-bottom: 0px;
}

td.ar.outofstock.qty {
    background-color: #ff000066;
}

.alterItems{
	padding: 5px;
	background: none #fff;
    color: #2185d0;
    border-color: #2185d0;
	display: inline-block;
    line-height: 1;
    vertical-align: baseline;
    margin: 0 3px;
    text-transform: none;
    border: 1px solid;
    border-radius: 5px;

}

.addonItem{
	padding: 5px;
	background: none #fff;
    border-color: #22242626 ;
	display: inline-block;
    line-height: 1;
    vertical-align: baseline;
    margin: 0 3px;
    text-transform: none;
    border: 1px solid;
    border-radius: 5px;

}
.pad-5{
	padding: 5px;
}
.pad-left-3 {
	padding-left: 3px;
}

td.subCode_Al{
	width: 45px;
}
td.subCode_OA{
	width: 85px;
}
.subItem {
	opacity: 0.7;
}
.subItem td table td {
	vertical-align: middle !important;
}
/* .subItemsItemDesc {} */
tr.subItemParent td.sNo,tr.subItemParent td.taxableAmount {
    border-bottom: none;
}
</style>

