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

	$addressView = 'export/address/salinv';
	$detailsView = 'export/details/elite';

$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,
		"isvertical" => 1
	));

?><?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 ($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 noborder" 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 if($tType != 'PI')
					{
						if (!empty($company['logo']))
						{
							echo '<td class="vat" style="display:block;height:auto;" width="25%"><div class="imgDiv fltlt" ><img src="' . $company['logo'] . '" /></div></td>';
						}
					}?>
				<td <?php !empty($company['logo']) ? 'width="25%"' : 'width="50%"' ?> ><?php
					//$company['email'] = '';
					//$company['gstin'] = '';
					$company['name'] = '<b>'.lang("companyName").'</b>';
					$this->subview($addressView, $company); ?>
				</td>
				<td <?php echo ($isShipping) ? '' : 'rowspan ="2"'?> width="50%";>
					<table  cellspacing="5" cellpadding="0"  class="noborder invMeta" style="padding:0px;width: 100%">
						<tbody>
							<tr>
								<td  width="30%"; class="label"><?php echo mytranslang('No',$tNo_text); ?><br><b><?php echo $tNo; ?></b></td>
								<td  width="70%"; class="label"><?php  echo mytranslang('Date',$tDate_text);?><br><b><?php echo $tDate; ?></b></td>
							</tr>
							<?php if(!empty($pos) ||  !empty($billing)){?>
							<tr>
								<?php if(!empty($pos) && $tType!='PI'){?>
								<td class="label"><?php echo mylang("POS"); ?><br><b><?php echo $pos ?></b></td>	
								<?php } ?>
								<?php if(!empty($billing) && !empty($billing['city'])){?>
								<td class="label">Destination<br><b><?php echo $billing['city'];?></b></td>	
								<?php } ?>
							</tr>
							<?php } ?>
							<?php if(!empty($relNumber) ||  !empty($relDate)){?>
							<tr>
								<?php if (!empty($relNumber)){?>
								<td class="label"><?php echo $rel_tNo_text; ?><br><b><?php echo $relNumber; ?></b></td>
								<?php } ?>
								<?php if (!empty($relDate)){?>
								<td class="label"><?php echo $rel_tDate_text; ?><br><b><?php echo $relDate; ?></b></td>
								<?php } ?>
							</tr>
							<?php } ?>
							<?php if(!empty($dueDate) ||  !empty($ref)){?>
							<tr>
								<?php if (!empty($dueDate) && !empty($isDueDate))
								{?>
								<td class="label"><?php echo $dueDate_text ? $dueDate_text : 'Due Date'; ?><br><b><?php echo $dueDate; ?></b>
								</td>								
								<?php } ?>
								<?php if (!empty($ref)){?>
								<td class="label"><?php echo mylang("Reference"); ?><br><b><?php echo $ref; ?></b></td>		
								<?php } ?>
							</tr>
							<?php } ?>
							<?php if(!empty($tType == DELCHALLAN && $classCode) ||  !empty($sRepName)){?>
							<tr>
								<?php if ($tType == DELCHALLAN && $classCode && get_company('countryCode')=='IN')	{ ?>
								<td class="label"><?php echo mylang("ChallanType"); ?><br><b><?php echo $this->config->item($classCode); ?></b></td>
								<?php } ?>
								<?php if (!empty($sRepName)&& !empty($issalesrep)){ ?>
								<td class="label"><?php echo $srep_text; ?><br><b><?php echo $sRepName; ?></b></td>
								<?php } ?>
							</tr>
							<?php } ?>
							<?php if (!empty($sRepMobile)){?>
							<tr>
								<?php if (!empty($sRepMobile)&& !empty($issalesrep)){?>
								<td class="label"><?php echo $srep_mobile_text; ?><br><b><?php echo $sRepMobile; ?></b></td>
								<?php } ?>
								<td></td>
							</tr>
							<?php } ?>
							<?php if (!empty($isprojectname) && !empty($prjName)) {?>
							<tr>
								<td class="label"><?php  echo mylang("ProjectName"); ?><br><b><?php echo $prjName; ?></b></td>
								<td></td>
							</tr>
							<?php } ?>
								<?php 
									$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){?>
												<tr>
													<td  <?php echo empty($td[0]) ? 'colspan="2"' : '';?>><?php echo !empty($td[0]) ? $td[0] : ' '; ?></td>
													<?php if(!empty($td[1])){?>
													<td><?php echo !empty($td[1]) ? $td[1] : ' '; ?></td>
													<?php  } ?>
												</tr>
												<tr>
													<td <?php echo empty($td[3]) ? 'colspan="2"' : '';?>><?php echo !empty($td[2]) ? $td[2] : ' '; ?></td>
													<?php if(!empty($td[3])){?>
													<td ><?php echo !empty($td[3]) ? $td[3] : ' '; ?></td>
													<?php  } ?>
												</tr>
										<?php } ?>
						</tbody>
					</table>
				</td>
			</tr>
			<tr>
				<?php $width= !empty($company['logo']) ? 'width="25%"' : 'width="50%"'?>
				<?php if($isShipping) {
					$width='width="33.3%"'; 
				}
				?>
				<td class="nbr" <?php echo $width; ?>>
				<?php if(!empty($billing)){ ?>
					<span><?php echo ($tType == 'PI') ? "Supplier / Vendor" : mylang("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($tType=='PI')
						{
							?><p class="nm">SOS : <?php echo $pos; ?></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>';
					}
				?>
			</tr>
			<?php if (
						($tType == "SH" || $tType == "TD" || $tType =="GR" || $tType =="TR") &&
						!empty($contact) &&
						!empty($contact['csType']) &&
						($contact['csType'] == 'B' || $contact['csType'] == 'L')
					) {
						$colspan = 3;

						echo '<tr>';
						echo '<td colspan="' . $colspan . '" class="bot ac vam" style="border-bottom:0.5px solid #000000">';
						echo 'Stock Transfer / Branch Transfer - Not for Sale';
						echo '</td>';
						echo '</tr>';
					}?>
		</tbody>
	</table>
	<?php if (!empty($isAllPageHeader))
	{
	
	echo '</htmlpageheader><sethtmlpageheader name="'.$pdf_type.'" value="on" show-this-page="1" page="all" />';
	}?>
<?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>';
	}
	echo '<br>';
	$this->view($detailsView, array(
		"useSimpleTaxCol" => 1,
		"isNormal" => 1,
		"isShowFor" => 1,
		"showVerticalLine" => 1,
		"isvertical" => 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>
