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

	$letterPadHeader = 'export/letterpadHeader';
	$addressView = 'export/address/salinv';
	$detailsView = !empty($detailsView) ? $detailsView : 'export/details/salinv';

	if($tType == 'SE')
	{
		$detailsView.="_est";
	}

	// $this->subview($letterPadHeader);
	$tDate = format_date($tDate);
	$this->view('export/css');

?>
<div>
	<div style="width:100%" class="ac">
		<b><big class="nm"><?php echo $company['name']; ?></big></b>
		<p class="nm"><?php echo $company['address1']; ?></p>
		<p class="nm"><?php echo $company['address2']; ?></p>
		<p class="nm"><?php echo $company['city']." - ".$company['zip']; ?></p>
		<p class="nm"><?php echo $company['stateName'].", ".$company['country']; ?></p>
		<p class="nm"><?php echo "Phone : ".$company['phone']; ?></p>
	</div>
	<table class="noborder vat nopadding" cellspacing="0" cellpadding="0" style="width:80%" align="center">
		<tbody>
			<tr>
				<td width="35%">Email : <?php echo $company['email']; ?></td>
				<td width="35%"></td>
				<td><?php if(!empty($company['gstin'])) { ?>GSTIN : <?php echo $company['gstin']; ?><?php } ?></td>
			</tr>
		</tbody>
	</table><br>
	<table class="noborder vat nopadding" cellspacing="0" cellpadding="0" style="width:80%" align="center">
		<tbody>
			<tr>
				<td style="text-align:left" width="35%">Billing Address : <?php
					$this->subview($addressView, $address[0]);
				?></td>
				<td style="text-align:left" width="35%">Shipping Address : <?php
					$this->subview($addressView, !empty($address[1])?$address[1]:$address[0]);
				?></td>
				<td style="text-align:left" width="30%"><?php
					if (!empty($tDate))
					{
						echo lang("Payment Date");
				?><b><?php echo $tDate; ?></b><?php
					}

					if (!empty($info['payment']['paymentTitle']))
					{
						?><br><span><?php echo lang("Payment Mode")?> : <b><?php echo $info['payment']['paymentTitle']; ?></b></span><?php } ?>
					<?php if(!empty($info['shipping']['shipTitle'])) { ?><br><span style=" width: 200px; word-break: break-all;white-space: normal;"><?php echo "Shipping Method"?> : <b><?php echo $info['shipping']['shipTitle']; ?></b></span><?php } ?>
					<?php if(!empty($resdet['info']['payment_id'])) { ?><br><span style=" width: 200px; word-break: break-all;white-space: normal;"><?php echo "Payment Reference"?> : <?php echo $resdet['info']['payment_id']; ?></span><?php } ?></td>
			</tr>
		</tbody>
	</table>
	<br>
	<table class="vat"  style="width:80%" align="center">
		
		<thead>
			<colgroup>
				<col width="5%">
				<col width="auto">
				<col width="10%">
				<col width="10%">
				<col width="10%">
				<?php if(!empty($trans_tax )) { ?>
					<col width="12%">					
				<?php } ?>			
				<col width="10%">	
			</colgroup>
			<tr>
				<th class="al">S.No</th>
				<th>Item Image</th>
				<th>Item Description</th>
				<th>Qty</th>
				<th  class="ar">Rate</th>
				<th>Discount</th>
				<?php if(!empty($trans_tax )) { ?>
					<th class="ar">Tax</th>					
				<?php } ?>				
				<th class="ar">Amount</th>
			</tr>
		</thead>
		<tbody><?php

			$currFraction = !empty(get_company("salSettings")['currFraction']) ? get_company("salSettings")['currFraction'] : 2;
			$currencyCode = !empty(get_company('currency')) ? get_company('currency') : 'INR';

			foreach($details as $key => $val)
			{
				$imgName=str_replace(' ', '_', $val['itemName']);
				$imgName = str_replace('/', '_', $imgName);
				$val['rate'] = formatAmount($val['rate'], $currencyCode, "0.00", true, $currFraction);
				$val['taxableAmount'] = formatAmount($val['taxableAmount'], $currencyCode, "0.00", true,$currFraction);

				if ($key === "tax")
				{
			?><tr>
				<td colspan="<?= !empty($trans_tax) ? 5 : 4; ?>" class="ar"><?php echo $val['itemName']; ?></td>
				<td><?php echo $val['taxName']; ?></td>
				<td class="ar"><?php echo $val['taxableAmount']; ?></td>
			</tr><?php
				}
				else
				{ 
			?><tr>
				<td><?php echo $key+1; ?></td>
				<td>
				<?php $baseUrl = rtrim($ecomUrl, '/') . '/'; ?>
				<img src="<?= $baseUrl . 'index.php/i/' . $val['imageId'] . '_small/' . $imgName . $val['imgFileExt'] ?>"
     onerror="imageError(this)">
				<td><?php
					 
					echo $val['itemName'];

					if ($val['isPackUnit'])
					{
						echo '&nbsp;<b>' . $val['unit'] . '</b>';
					}
					if (!empty($val['attrs']))
					{
						echo '<p class="desc nm pretxt"><small>'. $val['attrs'] .'</small></p>';
					}
					echo (!empty($val['itemDesc']) ? '<br><br><small>' . $val['itemDesc'] . '</small>' : '');

				?></td>
				<td class="ac"><?php
					echo $val['qty'];
					echo '&nbsp;<small>' . ((!$val['isPackUnit']) ? $val['unit'] : 'Nos') . '</small></td>';
				?></td>
				<td class="ar"><?php echo !empty($val['rate']) ? $val['rate'] : '-'; ?></td>
				<td class="ar"><?php echo !empty($val['discAmount']) ?  $val['discAmount'] : '-'; ?></td>
				<?php if(!empty($trans_tax )) { ?>
					<td class="ar"><?php echo $val['taxName']; ?></td>					
				<?php } ?>	
				<td class="ar"><?php echo $val['taxableAmount']; ?></td>
			</tr>
			<?php
					}
				} 
			?><tr>
				<td colspan="<?= !empty($trans_tax) ? 7 : 6; ?>" class="ar"><b>Sub Total</b></td>
				<td class="ar"><b><?php echo round($taxableAmount, 2); ?></b></td>
			</tr>
		</tbody>
	</table>
	<table class="vat noborder" style="width:80%" align="center">
		<tbody>
			<colgroup>
				<col width="5%">
				<col width="10%">
				<col width="auto">
				<col width="10%">
				<col width="10%">
				<col width="10%">
				<col width="12%">
				<col width="10%">
			</colgroup>
		<?php
			if(!empty($trans_tax ))
			{
				foreach($trans_tax as $key => $val)
				{
					$val['taxValue'] = formatAmount($val['taxValue'], $currencyCode, "0.00", true, 2);
					$val['totalamt'] = formatAmount($val['totalamt']-$val['taxValue'], $currencyCode, "0.00", true, 2);
			?>
			<tr>
				<td colspan="7" class="ar"><?php
					echo $key . " on " . $val['totalamt'];
				?></td>
				<td class="ar"><?php
					echo $val['taxValue'];
				?></td>
			</tr><?php 
				}
			?><tr>
				<td colspan="7" class="ar bg"><b>Total</b></td>
				<td class="ar bg"><b><?php
					echo formatAmount($totAmount, $currencyCode, "0.00", true, 2);
				?></b></td>
			</tr><?php
			}
		?></tbody>
	</table>
</div>
<style>
	table {
	border-collapse: collapse;
	}
	.bg {
		    background: #f9f9f9;
	}
</style>
