
<?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'

	$addressView = 'export/address/salinv';
	$detailsView = 'export/details/salinv';
	if($tType == 'SE'){
		$detailsView.="_est";
	}

	$custFieldsView = 'export/customfields';
	$exportDetailsView = 'export/exportdetails';

	$arr = array(
		'SE' => 'Quotation',
		'SO' => 'Sales Order',
		'SC' => 'Sales Credit note',
		'SD' => 'Sales Debit note',
		'SR' => 'Cash invoice',
		'SI' => 'Tax Invoice',
		'PI' => 'Purchase Bill'
	);

	$isQuote = false;
	if ($tType == 'SE')
	{
		$isQuote = true;
	}

	if (!empty($titleText) && ($tType == 'SI' || $isQuote))
	{
		$arr[$tType] = $titleText;
	}

	// if (!empty($conTaxScheme) && $conTaxScheme == 'C')
	if ($isComposition)
	{
		$arr['SI'] = 'Bill of Supply';
	}

	if($tType == 'SI' && in_array($classCode, array('EXPWP', 'EXPWOP', 'DEEM', 'EXPBO')))
	{
		$arr['SI'] = 'Export Invoice';
	}
	$transType = !empty($arr[$tType]) ? $arr[$tType] : lang($tType);

	if ($isPrint && $isExport) {
		$isEstimate = true;
	}

	$hasHSN = ($hasHSN && $isHsnCol) ? 1 : 0;

	if ($isShipping && $tType != 'PE' && (!$sameAsBill || empty($hidShipAdr)))
	{
		$isShipping = true;
	} else {
		$isShipping = false;
	}
	
	$this->view('export/css');
?><page footer="page" pagegroup="new">
<?php 
	if (isset($download) && $download==-1){
		echo '<bookmark title="'.$tNo.'" level="0" ></bookmark>';
	}
?>
<!-- page_header -->
	<table border="0" cellspacing="0" cellpadding="0" class="noborder nopadding vat"><?php
		if (!empty($company['logo']))
		{
			echo '<col style="width: 20%"><col style="width: 45%">';
		}
		else
		{
			echo '<col style="width: 65%">';
		}
		?><col style="width: 35%">
		<tbody>
			<tr><?php
				if (!empty($company['logo']))
				{
					echo '<td class="vat"><div class="imgDiv fltlt"><img src="' . $company['logo'] . '" /></div></td>';
				}
				?><td><?php
					$this->subview($addressView, $company);
					if($gstin)
					{
						// echo '<br>';
						echo '<div style="padding-bottom:5px;">'.mylang("GSTIN").' : ' . $gstin . '</div>';
					}
				?></td>
				<td class="vat ">
					<div class="headtxt"><h2 class="nm dib"><?php echo $transType; ?></h2></div><?php
					if ($pdf_type && empty($is_email)) {
						echo '<h3 class="nm dib">' . $pdf_type . '</h3>';
					}
					?>
					<table class="noborder invMeta">
						<tbody>
							<tr>
								<td class="label"><?php echo $tNo_text; ?></td>
								<td>: <b><?php echo $tNo; ?></b></td>
							</tr>
							<tr>
								<td class="label"><?php echo $tDate_text; ?></td>
								<td>: <b><?php echo $tDate; ?></b></td>
							</tr><?php
							if ($dueDate && !empty($isDueDate))
							{
							?><tr>
								<td class="label"><?php echo $dueDate_text ? $dueDate_text : 'Due Date'; ?></td>
								<td>: <b><?php echo $dueDate; ?></b></td>
							</tr><?php
							}

							if ($ref)
							{
							?><tr>
								<td class="label">Reference No</td>
								<td>: <b><?php echo $ref; ?></b></td>
							</tr><?php
							}
							
							if ($tType == DELCHALLAN && $classCode && get_company('countryCode')=='IN')
							{
							?><tr>
								<td class="label"><?php echo mylang("ChallanType");?></td>
								<td>: <b><?php echo $this->config->item($classCode); ?></b></td>
							</tr><?php
							}
							if ((!empty($source) && $source == 'P') && !empty($tableType) && !empty($tableName)) 
							{
							?><tr>
								<td class="label"><?php echo ($tableType == 'D' ? 'Table ' : 'Take Away '); ?></td>
								<td>: <span><?php echo $tableName; ?></span>									
								<?php if(!empty($kot_no)) { ?>
									<span>, KOT : <?php echo $kot_no; ?> </span>
								<?php  } ?>
							</td>
							</tr>
							<?php if(!empty($sRepName)) { ?>
								<tr>
									<td class="label"><?php echo 'Waiter '; ?></td>
									<td>: <span><?php echo $sRepName; ?></span></td>
								</tr>
							<?php }?>
							<?php }
						?></tbody>
					</table>
				</td>
			</tr>
			<tr class="vam">
				<td <?php if ($isExport && !$isQuote) { echo 'class="bot bob ac vam" style="padding:5px;"'; } else { echo 'class="bot ac vam"'; } ?> colspan="<?php echo !empty($company['logo']) ? 3 : 2; ?>"><?php
					if ($isExport && !$isQuote)
					{
						if ($classCode == 'EXPWOP')
						{
							// echo '<hr noshade="noshade" size="1" class="hr" />';
							echo lang('EXPWOP');
						}
						else if ($classCode == 'EXPWP')
						{
							// echo '<hr noshade="noshade" size="1" class="hr" />';
							echo lang('EXPWP');
						}
					}
				?></td>
			</tr>
		</tbody>
	</table>
<!-- /page_header -->
	<?php if ($isPrint && $isPageNo) { ?><page_footer><p><small>page [[page_cu]]/[[page_nb]]</small></p></page_footer><?php } ?>
	<div class="trans">
		<?php if(!empty($billing['name']) || !empty($shipping['name'])) {
			  $contact_name = !empty($contact['company']) ? $contact['company'] : (!empty($contact['contactPerson']) ? $contact['contactPerson'] : (!empty($conName) ? $conName : (!empty($contact['name']) ? ($contact['name']) : "")));
			  $billing["name"] = !empty($contact_name) ? $contact_name : $conName;
			  //Edited shipping name directly in grid
			if($shipping["name"] != $contact_name){
				$contact_name  = $shipping["name"];
			}
			$shipping["name"] = !empty($contact_name) ? $contact_name : $conName;
		 ?>
		
		<table border="0" cellspacing="0" cellpadding="0" class="noborder vat"><?php
		if ($isShipping) {
			?><col style="width: 25%">
			<col style="width: 35%">
			<col style="width: 40%"><?php
		} else {
			?><col style="width: 50%">
			<col style="width: 50%"><?php
		}
			?><tbody>
				<tr>
					<td>
						<div class=<?php echo !empty($showVerticalLine) ? 'vl' :''; ?> >
						<p  class="fw nm"><?php if (!empty($tType=='PI')) { ?><?php echo mylang("Supplier");?><?php } ?>
						<?php if (!empty($tType!='PI')) { ?><?php echo mylang("Issued");?><?php } ?></p><?php
						if (!empty($contact['name']))
						{
							?><b class="fw nm <?php echo !empty($showVerticalLine) ? 'tc' :''; ?>"><?php echo $contact['name']; ?></b><?php
						}
						else if (!empty($conName))
						{
							?><b class="fw nm <?php echo !empty($showVerticalLine) ? 'tc' :''; ?>"><?php echo $conName; ?></b><?php
						}

						if(!$expCurrencyCode)
						{
							if(!empty($conTaxNo))
							{
								?><p class="nm"><?php echo mylang("GSTIN")?>: <?php echo $conTaxNo; ?></p><?php
							}
							else if(!empty($contact['taxNo']))
							{
								?><p class="nm"><?php echo mylang("GSTIN")?> : <?php echo $contact['taxNo']; ?></p><?php
							}
							else if(!empty($contact['perTax']))
							{
								?><p class="nm"><?php echo mylang("PAN")?> : <?php echo $contact['perTax']; ?></p><?php
							}

							if(!empty($pos) && $tType!='PE' && $tType!='PI')
							{
								?><p class="nm"><?php echo mylang("POS")?> : <?php echo $pos; ?></p><?php
							}
							if($tType=='PI')
							{
								?><p class="nm"><?php echo mylang("SOS")?> : <?php echo $pos; ?></p><?php
							}
						}

						if (!empty($contact['contactPersonMobile']))
						{
							$billing['mobile'] = $contact['contactPersonMobile'];
							$shipping['mobile'] = $contact['contactPersonMobile'];
						}
					?></div></td>
					<?php if(!empty($isShowAddress)) { ?>
					<td><div class=<?php echo !empty($showVerticalLine) ? 'vl' :''; ?> ><?php
						echo '<span class="">'.'Billing' . ($isShipping ? '' : ' & Shipping') . ' Address :</span>';
						$this->subview($addressView, $billing);
					?></div></td><?php
					if ($isShipping)
					{
						echo '<td>Shipping Address : <br>';
						$this->subview($addressView, $shipping);
						echo '</td>';
					}
				?><?php } ?></tr>
			</tbody>
		</table><?php } ?><?php

		if (!empty($export_details[0]['value']) && ($isExport && $currencyCode != $expCurrencyCode))
		{
			$this->view($exportDetailsView);
		}
		$this->view($custFieldsView);
	?>
	</div><?php
		$this->view($detailsView, array("useSimpleTaxCol" => 1, 'isShowFor' => '1'));
?>
<style>
.headtxt {
	width:<?php echo !empty($isPrint && $showVerticalLine) ? '225px' : ((!$isPrint && $showVerticalLine) ? '300px;' : 'auto;') ?>;
}
.invMeta {
	width: auto;
}
</style>
</page>

