<?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';
	$headColor = (empty($is_email) ? $bgColor : $email_color);

	$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;
	if(empty($isShopNameFirst)) {
		$detailsView = 'export/details/salinv';
		if($tType == 'SE'){
			$detailsView.="_est";
		}
	}
	else {
		$detailsView = 'export/details/jpegmedia';
	}

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

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

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

	if($isPrint && $printcolor == 'transparent')
	{
		$foreColor = "#000000";
	}
	if (!empty($is_email) && $color != 'transparent') {
		$foreColor = "#ffffff";
	}
	
	$hasHSN = ($hasHSN && $isHsnCol) ? 1 : 0;

	if ($isShipping && $tType != 'PE' && (!$sameAsBill || empty($hidShipAdr)))
	{
		$isShipping = true;
	}
	else
	{
		$isShipping = false;
	}
	
	if($bgColor == 'transparent') {
		$showVerticalLine= false;
	}
	else {
		$showVerticalLine = true;
	}
	
	if($tType == 'PC' || $tType == 'PD' || $tType == 'PE') {
		$company['logo'] = '';
	}
	if($dueDate=='0000-00-00') {
		$dueDate = '';
	}
	$this->view('export/css');

	if (isset($download) && $download==-1){
		echo '<bookmark title="'.$tNo.'" level="0" ></bookmark>';
	} ?>
<htmlpageheader name="<?php echo $pdf_type; ?>">
	<div class="trans">
		<table border="0" cellspacing="0" cellpadding="0" class="noborder nopadding vat"><?php
			/*if (empty($company['logo']))
			{
				echo '<col style="width: 70%">';
			}
			else
			{
				echo '<col style="width: 45%">';
				if (empty($isPrint))
				{	
					echo '<col style="width: 15%">';
				}
				else {
					echo '<col style="width: 25%">';
				}	
			}*/
			?><!--<col style="width: 30%">*/-->
			<tbody>
				<tr>
					<td class="vat" <?php  echo !empty($company['logo']) ?'width="30%"' : 'width="30%"'; ?>>
						<table class="noborder invMeta">
							<tbody>
								<tr><td colspan="2" <?php echo $headColor == "transparent" ? "" : "style='padding:10px !important'"; ?> class="headtd"><?php echo $headColor == "transparent" ? "" : "&nbsp;"; ?><?php echo $titleText; ?></td></tr>
								<?php if ($tType != 'SE' && $pdf_type && empty($is_email)) { ?>
									<tr><td colspan="2" ><h3 class="nm dib"><?php echo $pdf_type; ?></h3></td></tr>
								<?php }?>
								<tr>
									<td class="label"><?php  mytranslang('No',$tNo_text); ?></td>
									<td>: <b><?php echo $tNo; ?></b></td>
								</tr>
								<tr>
									<td class="label"><?php echo  mytranslang('No',$tNo_text);; ?></td>
									<td>: <b><?php echo $tDate; ?></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 (!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 ($ref)
								{
								?><tr>
									<td class="label"><?php echo mylang("Reference"); ?></td>
									<td>: <b><?php echo $ref; ?></b></td>
								</tr><?php
								}
								
								if ($tType == DELCHALLAN && $classCode)
								{
								?><tr>
									<td class="label">Challan Type</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 }
								/*
								if ($isPrint)
								{
							?><tr>
								<td>Page</td>
								<td>: <b>[[page_cu]] / [[page_nb]]</b></td>
							</tr><?php
								}
								*/
							?></tbody>
						</table>
					</td>
					<td style="text-align:right" <?php  echo !empty($company['logo']) ?'width="45%"' : 'width="30%"'; ?>><?php
						if ($tType == 'PI' || $tType=='PC' || $tType == 'PD' || $tType == 'PE')
						{ 
							if(!empty($conName))
							{
								$this->subview($addressView, $billing);
							}
							$isShowAddress = false;
							if($tType == 'PI')
							{
								echo '<p class="nm">SOS : '.$pos.'</p>' ;
							}
						}
						else { 
							$this->subview($addressView, $company); 
							if($gstin)
							{
								// echo '<br>';
								echo '<div style="padding-bottom:5px;">GSTIN : ' . $gstin . '</div>';
							} 
						}
					?></td>
					<?php
					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>';
					}
					?>
				</tr>
				<?php
					if (!empty($tType!='PI') && !empty($tType!='PC') && !empty($tType != 'PD') && !empty($tType != 'PE'))
					{
						$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-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];
						}
					?></td>
				</tr><?php
				}
			?></tbody>
		</table>
	</div><?php

if (!empty($tType!='PI') && !empty($tType!='PC') && !empty($tType != 'PD') && !empty($tType != 'PE'))
{
	?><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" style="padding-top:5px;padding-bottom:5px;"><?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 <?php echo !empty($showVerticalLine) ? 'style="padding:2px;border-left: 4px solid '.$headColor.'"' : '' ?>>
						<div><?php
							if(!empty($contact['name']) || !empty($conName))
							{
								?><p class="fw nm"><?php
								echo ($tType == 'PI') ? mylang('Supplier') : mylang("Issued");
								?></p><?php
							}
						if (!empty($contact['name']))
						{
							?><b class="fw nm <?php echo !empty($showVerticalLine) ? 'tc' :'as'; ?>"><?php echo $contact['name']; ?></b><?php
						}
						else if (!empty($conName))
						{
							?><b class="fw nm <?php echo !empty($showVerticalLine) ? 'tc' :'as'; ?>"><?php echo $conName; ?></b><?php
						}

						if(!$expCurrencyCode)
						{
							if(!empty($conTaxNo))
							{
								?><p class="nm">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 lang("PAN")?> : <?php echo $contact['perTax']; ?></p><?php
							}

							if(!empty($pos) && $tType!='PE' && $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
							}
						}

						if (!empty($contact['contactPersonMobile']))
						{
							$billing['mobile'] = $contact['contactPersonMobile'];
							$shipping['mobile'] = $contact['contactPersonMobile'];
						}
					?></div>
				</td>
				<?php if(!empty($isShowAddress) && !empty($billing['countryCode'])) { ?>
					<td <?php echo !empty($showVerticalLine) ? 'style="padding:2px;border-left: 4px solid '.$headColor.'"' : '' ?>><div><?php
						echo '<span class="">'.'Billing' . ($isAllServices || $isShipping || $isQuote ? '' : ' & Shipping') . ' Address :</span>';
						$this->subview($addressView, $billing);
					?></div></td><?php
					if ($isShipping && !$isAllServices)
					{
						echo '<td>Shipping Address : <br>';
						$this->subview($addressView, $shipping);
						echo '</td>';
					}
				} ?></tr>
			</tbody>
		</table><?php
	} ?>
	</div>
	<!-- /page_header -->
	<?php
}
else
{
	// echo '</page_header>';
}
?>
</htmlpageheader><sethtmlpageheader name="<?php echo $pdf_type; ?>" value="on" show-this-page="1" />
<div class="trans"><?php
		if (!empty($export_details[0]['value']) && ($isExport && $currencyCode != $expCurrencyCode))
		{
			$this->view($exportDetailsView);
		}
		if(!empty($fields))
		{ 
			$this->view($custFieldsView);
		}
	?>
	</div><?php
	if ($isPrint)
	{
		// For Print Date : [[date_d]]/[[date_m]]/[[date_y]] [[date_h]]:[[date_i]]:[[date_s]]
		// <small class="ar">[[date_d]]/[[date_m]]/[[date_y]] [[date_h]]:[[date_i]]:[[date_s]]</small>
		//echo '<page_footer><p><small class="al">page [[page_cu]]/[[page_nb]]</small></p></page_footer>';
	}
	$this->view($detailsView, array("useSimpleTaxCol" => 1,'showVerticalLine' => 1,'isHsnBreakup' => true,'isShowFor' => true));
?>
<style>
.invMeta {
	width: auto;
}
.invMeta td {
	padding:0px !important;
}
</style>
</page>

