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

// 'isLogo, color, isDueDate, isSlNoCol, isItemDesc, isHsnCol, isBankDetail, isCustSign, isPageNo, isFullPage, isPrintDate, footerText, copiesToPrint, printType, topMargin, rightMargin, bottomMargin, leftMargin'
	
	if (!empty($outstanding))
	{
		$oldDue = $outstanding - $dueAmount;
		$oldDue = ($oldDue > 0) ? formatAmount($oldDue, $currencyCode,'','',$currFraction) : '';
		$newDue = ($outstanding > 0) ? formatAmount($outstanding, $currencyCode,'','',$currFraction) : '';
	}

	
	$billing['fontname'] = !empty($fontname) ? $fontname : '';
	$shipping['fontname'] = !empty($fontname) ? $fontname : '';
	if($isPrint && $printcolor == 'transparent')
	{
		$foreColor = "#000000";
	}
	if (!empty($is_email) && $color != 'transparent')
	{
		$foreColor = "#ffffff";
	}
	if($bgColor == 'transparent')
	{
		$showVerticalLine= false;
	}
	else
	{
		$showVerticalLine = true;
	}
	$fontname = (!empty($fontname) && $fontname != 'null') ? $fontname : ""; 
	$this->view('export/css', array(
		"fontname" => $fontname
	));

	if (isset($download) && $download == -1)
	{
		echo '<bookmark title="'.$tNo.'" level="0" ></bookmark>';
	}
	if (!empty($isAllPageHeader))
	{
		echo '<htmlpageheader name="'.$pdf_type.'">';
	}
	if(!empty($isOriginal))
	{
		$printColors = '';
	}
	if(!empty($printColors))
	{
		$headColor = $printColors;
	}

	$_taxableAmount = 0;
	$_itemTotal = 0;

?>
	<div class="trans">
		<table border="1" cellspacing="0" cellpadding="0"  class="vat <?php echo !empty($isPrint) ? 'nopadding noborder' : ''; ?>">
			<tbody>
				<?php $colspan = '2' ?><?php
					if($isLogo == 2)
					{
						if($paper == 'A5')
						{
							$img_height = '150px';
						}
						else
						{
							$img_height = '150px';
						}
						
						echo '<tr><td colspan ='.$colspan.'   style="border: none;" width="100%"><div class="" ><img style="width: 100%;display: inline-block;height:'.$img_height.';" src="' . $company['fullHeaderImg'] . '" /></div></td></tr>';
					}
				?>
				<tr>
					<td style="border-right: none;">	
						<table <?php echo !empty($isPrint) ? 'style="border-top: 0.5px solid black;padding-top:5px;padding-bottom:5px;"': '' ?>  cellspacing="5" cellpadding="5" class="noborder vat">
								<tr>
									<td>பில் எண் : <?php echo $tNo;?></td>
									<td>தேதி : <?php echo $tDate;?></td>
								</tr>
								<tr>
									<td>பெயர் : 
										<?php $contact_name = !empty($contact['company']) ? $contact['company'] : (!empty($contact['contactPerson']) ? $contact['contactPerson'] : (!empty($conName) ? $conName : (!empty($contact['name']) ?($contact['name']) : "")));
											$billing['name'] = $contact_name;
											echo $contact_name;
											//$this->subview($addressView, $billing)
										?>
									</td>
								</tr>
						</table>
					</td>
				</tr>
				<tr> 
					<td style="width:100%;border:none;padding: 1px;">
						<table align='left' cellspacing="0" cellpadding="0" style="width:100%;border-collapse: collapse;" class="nobob inv_details wpw  bot ft nbb"  style="width:100%;">
							<thead>
								<tr>
									<td width="25%" style="text-align: center;border-left: none;">விலை</td>
									<td width="25%" style="text-align: center;">விபரம்</td>
									<td width="25%" style="text-align: center;">எடை</td>
									<td width="25%" style="text-align: center;border-right: none;">தொகை</td>
								</tr>
							</thead>
							<tbody>
<?php 
								foreach($details as $key => $val)
								{
									if (!empty($val['qtys']) && count($val['qtys']) > 1)
									{
										$val['itemDesc'] .= " [ " . implode(" + ", $val['qtys']) . " ]";
									}

									$val['rate'] = formatAmount(!empty($val['rate']) ? $val['rate'] : 0, $isExport ? $expCurrencyCode : $currencyCode, "-", true, $rateFraction);
									$val['qty'] = !empty($val['qty']) && $val['qty'] > 0 ? floatval($val['qty']) : 0;
									$val['taxableAmount'] = formatAmount($val['taxableAmount'], $currencyCode, "-", true,$currFraction);
?>
									<tr>
										<td style="text-align: right;"><?php echo $val['rate']; ?></td>
										<td  style="text-align: left;"><?php
											echo $val['printName'] ? trim($val['printName']) : trim($val['itemName']);
											if (!empty($val['itemDesc']))
											{
												echo '<br><small>' . $val['itemDesc'] . '</small>';
											}
										?></td>
										<td  style="text-align: right;"><?php echo $val['qty']; ?></td>
										<td  style="text-align: right;border-right: none;"><?php echo $val['taxableAmount']; ?></td>
									</tr>	
								<?php } ?>
								<tr>
									<td style="border-bottom: none;">&nbsp;</td>
									<td style="border-bottom: none;text-align: right;" colspan="2">தொகை</td>
									<td style="border-bottom: none;text-align: right;border-right: none;"><?php 
									$_taxableAmount =  !empty($_taxableAmount) ? formatAmount($_taxableAmount, $currencyCode,'','',$currFraction) :'';
									echo ($includeTax) ? $_itemTotal : $_taxableAmount ;?></td>
								</tr>
								<?php if(!empty($charges)){
									foreach($charges as $key => $itm){
										$itm['_taxableAmount'] = formatAmount($itm['_taxableAmount'], $currencyCode, "-", true,$currFraction);?>
										<tr>
											<td style="border-bottom: none;">&nbsp;</td>
											<td style="border-bottom: none;text-align: right;" colspan="2"><?php echo $itm['itemName'];?></td>
											<td style="border-bottom: none;text-align: right;border-right: none;"><?php echo ($includeTax) ? $itm['_itemTotal'] : $itm['_taxableAmount'] ;?></td>
										</tr>	
								<?php	
										}
									}?>
								<tr>
									<td style="border-bottom: none;">&nbsp;</td>
									<td style="border-bottom: none;text-align: right;" colspan="2">பில் தொகை</td>
									<td style="border-bottom: none;text-align: right;border-right: none;border-top: 1px solid black;"><b><?php echo formatAmount($totAmount, $isExport ? $expCurrencyCode : $currencyCode, "-", $isExport ? true : false,$currFraction);?></b></td>
								</tr>
					<?php if(!empty($daybalance)){
								$daytot = $tot=  0;
								$daytot = ($isExport ?$forexTotAmount : $totAmount)+$daybalance['open'] + $daybalance['other'] - $daybalance['receipt']; 
								$tot = ($isExport ?$forexTotAmount : $totAmount)+$daybalance['open'];
								$tot = !empty($tot) ? formatAmount($tot, $currencyCode,'','',$currFraction) :'';
								$daytot = !empty($daytot) ? formatAmount($daytot, $currencyCode,'','',$currFraction) :'';
								$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) :'';
								if(!empty($daybalance['open'])){
									?>
								<tr>
									<td style="border-bottom: none;">&nbsp;</td>
									<td style="border-bottom: none;text-align: right;" colspan="2">முந்தைய தேதி வரை உள்ள முன்பாக்கி</td>
									<td style="border-bottom: none;text-align: right;border-right: none;"><?php echo $daybalance['open'] ;?></td>
								</tr>
								<tr>
									<td style="border-bottom: none;">&nbsp;</td>
									<td style="border-bottom: none;text-align: right;" colspan="2">மொத்தம்</td>
									<td style="border-bottom: none;text-align: right;border-right: none;border-top: 1px solid black;"><b><?php echo $tot;?></b></td>
								</tr>
								<?php } ?>
								<?php if(!empty($daybalance['other'])){?>
								<tr>
									<td style="border-bottom: none;">&nbsp;</td>
									<td style="border-bottom: none;text-align: right;" colspan="2">இதர பரிவர்த்தனைகள்</td>
									<td style="border-bottom: none;text-align: right;border-right: none;"><?php echo $daybalance['other'] ;?></td>
								</tr>
								<?php } ?>
								<?php if(!empty($daybalance['receipt'])){?>
								<tr>
									<td style="border-bottom: none;">&nbsp;</td>
									<td style="border-bottom: none;text-align: right;" colspan="2">இன்றைய மொத்த வரவு தொகை</td>
									<td style="border-bottom: none;text-align: right;border-right: none;"><?php echo $daybalance['receipt'] ;?></td>
								</tr>
								<?php } ?>
								<tr>
									<td style="border-bottom: none;">&nbsp;</td>
									<td style="border-bottom: none;text-align: right;" colspan="2"><?php echo $tDate." தேதி வரை வரவு நீக்கி பற்று"?></td>
									<td style="border-bottom: none;text-align: right;border-right: none;border-top: 1px solid black;"><b><?php echo $daytot ;?></b></td>
								</tr>
					<?php } ?>
							</tbody>
						</table>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
<style>
@page {
<?php
	if(!empty($isWatermark))
	{
		echo 'background: url("' . $waterImg . '") no-repeat 0 0;';
		if ($isWatermark && $isWatermark == 1)
		{
			echo 'background-position: top;';
		}
		if ($isWatermark && $isWatermark == 2)
		{
			echo 'background-position: center;';
		}
		if ($isWatermark && $isWatermark == 3)
		{
			echo 'background-position: bottom;';
		}
		if (!empty($isAllPageHeader))
		{
			echo 'header: html_'.$pdf_type.'';
		}
	}
?>
}
table.nobob {
	border-left: none;
	border-right: 0px !important;
}
html, html body, table tr td {
	font-size : 16px !important;
}
.nbb{
	padding-bottom: none !important;
}
.invMeta {
	width: auto;
}
.inv_details table th, table td:last-child  {
   
    border-right: none;
}
<?php
	if(!empty($isPrint))
	{
?>
.invMeta td {
	padding:0px !important;
	/*white-space: nowrap;*/
}
<?php
	}
?>
</style>
