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

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

$dueDate_text = (!empty($label) && !empty($label['ValidTill'])) ? $label['ValidTill'] :(!empty($dueDate_text)? $dueDate_text : "DueDate") ;
$rel_tNo_text =  (!empty($label) && !empty($label['OrderNo'])) ? $label['OrderNo'] :$rel_tNo_text;
$rel_tDate_text =  (!empty($label) && !empty($label['OrderDate'])) ? $label['OrderDate'] :$rel_tDate_text;
	$flag1 = false;

	if ($isShipping && $tType != 'PE' && (!$sameAsBill || empty($hidShipAdr)))
	{
		$isShipping = true;
	}
	else
	{
		$isShipping = false;
	}
	if($tType == 'PC' || $tType == 'PD' || $tType == 'PE') { //print_R('called');
		$company['logo'] = '';
	}
	if($dueDate=='0000-00-00') {
		$dueDate = '';
	}
	$pdff_type = $pdf_type;
	if(!empty($isOriginal)) {
		$pdff_type = '';
	}
	$fontname = (!empty($fontname) && $fontname != 'null' )  ? $fontname : ""; 
	$this->view('export/css', array(
		"fontname" => $fontname
	));

?><?php
	if (isset($download) && $download==-1){
		echo '<bookmark title="'.$tNo.'" level="0" ></bookmark>';
	}
?>
	<?php if (!empty($isAllPageHeader))
	{
		echo '<htmlpageheader name="'.$pdf_type.'">';
	}?>
	<div style="width:100%;">
		<div class="ac"><big><b><?php echo strtoupper($titleText); ?></b></big></div>
		<?php if ($pdf_type && empty($is_email)) { ?><div class="ar"><?php echo $pdff_type; ?></div><?php } ?>
	</div>
	<table cellspacing="0" cellpadding="0" class="vat nbl" style="border-bottom: none !important;"><?php
	/*if ($isShipping){
		?><col style="width: 33.33%">
		<col style="width: 33.33%">
		<col style="width: 33.33%"><?php
	} else {
		?><col style="width: 50%">
		<col style="width: 50%"><?php
	}*/
		?><tbody>
			<tr>
				<?php $width='width="50%"'; 
				if($isShipping || !empty($transQr)) {
					$width='width="33.3%"'; 
				}
				?>
				<td class="nbr" <?php echo $width; ?>>
					<span><?php echo ($tType == 'PI') ? "Supplier / Vendor" : lang("Issued"); ?></span><?php
					$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;
					$this->subview($addressView, !empty($billing) ? $billing : array());
					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">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!='PI')
						{
							?><p class="nm">POS : <?php echo $pos; ?></p><?php
						}
						if($tType=='PI')
						{
							?><p class="nm">SOS : <?php echo $pos; ?></p><?php
						}
						if(!empty($contact['config']) && !empty($contact['config']['isRegisteredMSME']))
						{
							?><p class="nm"><?php echo mylang("MSME") .' '. $contact['config']['msmet'] ;?> : <?php echo $contact['config']['msmen']; ?></p><?php
						}
					}
				?></td><?php
					if ($isShipping)
					{
						if($tType != 'PO'){
						$contact_name = !empty($contact['company']) ? $contact['company'] : (!empty($contact['contactPerson']) ? $contact['contactPerson'] : (!empty($conName) ? $conName : (!empty($contact['name']) ?($contact['name']) : "")));
						//Edited shipping name directly in grid
						if($shipping["name"] != $contact_name){
							$contact_name  = $shipping["name"];
						}
						$shipping["name"] = !empty($contact_name) ? $contact_name : $conName;
						}
						echo '<td class="nbr" '.$width.'>Shipping Address : <br>';
						$this->subview($addressView, $shipping);
						echo '</td>';
					}
				?><td class="nbr" <?php echo $width; ?>>
					<table class="noborder invMeta" style="padding:0px;">
						<tbody>
							<tr>
								<td class="label"><?php echo mytranslang('No',$tNo_text); ?></td>
								<td>: <b><?php echo $tNo; ?></b></td>
							</tr>
							<tr>
								<td class="label"><?php  echo mytranslang('Date',$tDate_text);?></td>
								<td>: <b><?php echo $tDate; ?></b></td>
							</tr><?php

							if (!empty($relNumber))
							{
							?><tr>
								<td class="label"><?php echo $rel_tNo_text; ?></td>
								<td>: <b><?php echo $relNumber; ?></b></td>
							</tr><?php
							}

							if (!empty($relDate))
							{
							?><tr>
								<td class="label"><?php echo $rel_tDate_text; ?></td>
								<td>: <b><?php echo $relDate; ?></b></td>
							</tr><?php
							}

							if (!empty($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"><?php echo mylang("Reference"); ?></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($sRepName)&& !empty($issalesrep)) && (empty($source) || $source != 'P'))
							{
							?><tr>
								<td class="label"><?php echo $srep_text; ?></td>
								<td>: <b><?php echo $sRepName; ?></b></td>
							</tr>
							<?php
							}
							if ((!empty($sRepMobile)&& !empty($issalesrep)) && (empty($source) || $source != 'P'))
							{
							?>
							<tr>
								<td class="label"><?php echo $srep_mobile_text; ?></td>
								<td>: <b><?php echo $sRepMobile; ?></b></td>
							</tr>
							<?php
							}
							if (!empty($isprojectname) && !empty($prjName))
							{
							?>
							<tr>
								<td class="label"><?php  echo mylang("ProjectName") ?></td>
								<td>: <b><?php echo $prjName; ?></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 }
							/*
							if ($isPrint)
							{
						?><tr>
							<td>Page</td>
							<td>: <b>[[page_cu]] / [[page_nb]]</b></td>
						</tr><?php
							}
							*/
						?></tbody>
					</table>
				</td>
				<?php
				if (!empty($transQr) && !empty($qrTransImg))
				{
					echo '<td style="border:0px;width: auto;">';
					?><img src="<?php echo $qrTransImg; ?>" style="width:4cm;height:4cm;" class="" /><?php
					echo '</td>';
				}
				?>
			</tr>
			<?php if (!empty($tType!='PI') && !empty($tType!='PC') && !empty($tType != 'PD') && !empty($company['countryCode'])  && $company['countryCode'] == 'IN')
				{
					$classCodes = array(
						'EXPWOP' => lang('EXPWOP'),
						'EXPWP' => lang('EXPWP'),
						'SEZWP' => lang('SEZWP'),
						'SEZWOP' => lang('SEZWOP')
					);
			?><tr class="vam">
				<td <?php
					if (!$isQuote && $tType != DELCHALLAN && !empty($classCode) && !empty($classCodes[$classCode]))
					{
						echo 'class="bot ac vam bob" style="padding:5px;border-right: none;border-top:0.5px solid #000000;border-bottom:0.5px solid #000000;"';
					} else if($tType == "SI" && (empty($classCode) || empty($classCodes[$classCode])) && $isComposition) {

						echo 'class="bot ac vam bob" style="padding:5px;border-right: none;border-top:0.5px solid #000000;border-bottom:0.5px solid #000000;"';
					}
					else
					{
						echo 'class="bot ac vam" style="border-bottom:0.5px solid #000000"';
					}
				?> colspan="<?php echo !empty($company['logo']) ? 3 : 2; ?>"><?php
					if (!$isQuote && !empty($classCode) && !empty($classCodes[$classCode]))
					{
						echo $classCodes[$classCode];
					}
					 if(($tType == "SI"|| $tType == "SR") && (empty($classCode) || empty($classCodes[$classCode])) && $isComposition) {
						echo "COMPOSITION TAXABLE PERSON, NOT ELIGIBLE TO COLLECT TAX ON SUPPLIES";
					 }
					 //For delivery challan with internal branch transfer
					if(($tType =="SH" || $tType =="TD" || $tType =="GR" || $tType =="TR") &&   !empty($contact) && !empty($contact['csType']) && ($contact['csType'] == 'B'|| $contact['csType'] == 'L')) {
						echo "Stock Transfer / Branch Transfer - Not for Sale";
					}
				?></td>
			</tr><?php
			}else{
				if(!empty($tType =='PO')){
					echo '<tr>';
					?><td colspan="<?php echo !empty($company['logo']) ? 3 : 2; ?>" class="bot ac vam" style="border-bottom:0.5px solid #000000">';
					<?php echo '</td></tr>';
				}
			}
		?>
		</tbody>
	</table>
<?php
	if (!empty($isAllPageHeader))
	{
		echo '</htmlpageheader><sethtmlpageheader name="'.$pdf_type.'" value="on" show-this-page="1" page="all" />';
	}

	$flag1 = false;
	$wrap = true;
	
	if (empty($custFieldsCols))
	{
		$custFieldsCols = 3;
	}
	if ($fields)
	{
		$td = array();
		$i = 0;
		$custFieldsCols = in_array(count($fields), array(1, 2, 4)) ? 2 : 3;
	
		if (count($fields) > 6)
		{
			// $wrap = false;
		}
	
		foreach ($fields as $row)
		{
			if (!empty($row['isGrid']))
			{
				continue;
			}
	
			if ($row['fValue'])
			{
				$flag1 = true;
				if (empty($td[$i]))
				{
					$td[$i] = "";
				}
	
				if (!$wrap || $custFieldsCols == 2)
				{
					$td[$i] .= '<p class="nm"><span>' . $row['fName'] . ': <b>' . $row['fValue'] . '</b></span></p>';
				}
				else
				{
					$td[$i] .= '<p class="nm">' . $row['fName'] . ':</p>';
					$td[$i] .= '<p class="nm" style="padding-bottom:3px;"><b>' . $row['fValue'] . '</b></p>';
				}
	
				$i++;
			}
	
			if ($i == $custFieldsCols)
			{
				$i = 0;
			}
		}
	}

	if($flag1)
	{
		?><table border="0" cellspacing="0" cellpadding="0" class="noborder nopadding invMeta vat" style="width:100%;border-top:1px solid #000000">
			<tr class="custFields">
				<td style="width: 25%"><?php echo !empty($td[0]) ? $td[0] : ' '; ?></td>
				<td style="width: 25%"><?php echo !empty($td[1]) ? $td[1] : ' '; ?></td>
				<td style="width: 25%"><?php echo !empty($td[2]) ? $td[2] : ' '; ?></td>
				<td style="width: 25%"><?php echo !empty($td[3]) ? $td[3] : ' '; ?></td>
			</tr>
		</table><br><?php
	}
	if (!empty($export_details) && ($isExport && $currencyCode != $expCurrencyCode))
	{
	?><table border="0" cellspacing="0" cellpadding="0" class="noborder nopadding vat"><?php
			$td_1 = $td_2 =  '';
			$i=0;
			foreach ($export_details as $row)
			{
				if ($row['value'])
				{
					$i++;
					${'td_'.$i} .= '<tr><td>' . mylang($row['label']) . '</td><td>: <b>' . $row['value'] . '</b></td></tr>';
				}
				if ($i==2)
				{
					$i=0;
				}
			}
		?>
		<tr>
			<td class="" style="width:50%">
				<table class="noborder nopadding auto"><tbody class="label"><?php echo $td_1;?></tbody></table>
			</td>
			<td class="" style="width:50%">
				<table class="noborder nopadding auto"><tbody class="label"><?php echo $td_2;?></tbody></table>
			</td>
		</tr>
	</table><br><?php
	}

	if ($isPrint && $isPageNo)
	{
		//echo '<page_footer><p><small class="">page [[page_cu]]/[[page_nb]]</small></p></page_footer>';
	}

	$this->view($detailsView, array(
		"useSimpleTaxCol" => 1,
		"isNormal" => 1,
		"isShowFor" => 1,
		"showVerticalLine" => 1
	));

	?><style>
	body {
<?php if(!empty($isWatermark)) { ?>
		  background: url('<?php echo $waterImg; ?>') no-repeat 0 0;
		<?php if($isWatermark && $isWatermark == 1){?>
		  background-position: top;
		<?php } ?>
		<?php if($isWatermark && $isWatermark == 2){?>
		  background-position: center;
		<?php } ?>
		<?php if($isWatermark && $isWatermark == 3){?>
		  background-position: bottom;
		<?php } ?>
<?php } ?>
}
		.headtxt, .invMeta {
			width: auto;
		}
		
.invMeta td {
	padding:0px !important;
}

	</style>
</page>
