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

	$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 (!isset($isCompact))
	{
		$isCompact = false;
	}

	if (empty($shipping))
	{
		$shipping = array("name" => "");
	}

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

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

	$flag1 = false;

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

	$fontname = (!empty($fontname) && $fontname != 'null' )  ? $fontname : "";
	$this->view('export/css', array(
		"fontname" => $fontname
	));
	$billing['isAddTo'] = true;
	$pdff_type = $pdf_type;
	if (!empty($isAllPageHeader))
	{
		echo '<htmlpageheader name="'.$pdf_type.'">';
	}
?><page footer="page" pagegroup="new" class="whole"><div class="whole"><?php 
	if (isset($download) && $download==-1){
		echo '<bookmark title="'.$tNo.'" level="0" ></bookmark>';
	}
	
	$this->subview($addressView, $company);
	?><table cellspacing="0" cellpadding="0" class="vat" style="border-bottom: none !important;">
		<tbody>
			<tr>
				<td style="width:33.333%;"><?php
					if(!empty($contact))
					{
						?><!--<span><b>To</b><!--<br/><?php
						if (!empty($contact["name"])) {
							echo "M/s " . $contact["name"];
						}
						?></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;
					if($tType != 'PO')
					{
						//Edited shipping name directly in grid
						if ($shipping["name"] != $contact_name)
						{
							$contact_name  = $shipping["name"];
						}
						$shipping["name"] =  !empty($contact_name) ? $contact_name : $conName;
					}
					
					
					if (!empty($billing))
					{
						$tempAddress = $this->subview($addressView2, $billing, true);
						if ($tempAddress)
						{
							if (!$sameAsBill)
							{
								echo '<span>'.mylang('BillingAddress').'</span><br>';
							}
							echo $tempAddress . '<br>';
						}
					}

					if (!$sameAsBill && !empty($shipping))
					{
						$tempAddress = $this->subview($addressView2, $shipping, true);
						if ($tempAddress)
						{
							$caption = $tType != 'PO' ? mylang('ShippingAddress') : mylang('Dispatch To');
							echo '<span>'.$caption.'</span><br>' . $tempAddress . '<br>';
						}
					}

					if(!empty($conTaxNo) )
					{
						?><p class="nm"><?php echo mylang("GSTIN")?> : <?php echo $conTaxNo; ?></p><?php
					}
					else if(!empty($contact) && !empty($contact['taxNo']))
					{
						?><span><?php echo mylang("GSTIN") ?>: <?php echo $contact['taxNo']; ?></span><br><?php
					}
					else if(!empty($contact) && !empty($contact['perTax']))
					{
						?><p class="nm"><?php echo mylang("PAN")?> : <?php echo $contact['perTax']; ?></p><?php
					}
?>				</td>
				<td class="ac vam" style="width:33.333%;">
					<h3 class="nm"><?php echo empty($titleText) ? 'Cash Invoice' : $titleText; ?></h3>
				</td>
				<td class="" style="width:33.333%;">
					<span><?php  echo mytranslang('No',$tNo_text) . ' : <b>' . $tNo . '</b>'; ?></span><br>
					<span><?php echo mytranslang('Date',$tDate_text). ' : <b>' . $tDate . '</b>'; ?></span><br>
					<?php 
					if(!empty($paymentName) && $paymentName != 'Other'){
					?>
					<span><?php echo mylang("Paymentmode");?> : <b><?php echo $paymentName; if(!empty ($ref)) {
							echo "-".$ref;
						} ?></b></span><br>
					<?php
					} else {
						if(!empty ($ref)) {
					?>
					<span><?php echo mylang("Reference"); ?> : <b><?php echo $ref;?></b></span><br>
					<?php 
						}
					}?>
					<?php if(!empty($sRepName) && (empty($source) || $source != 'P')) {?>
					<span><?php echo $srep_text . ' : <b>' . $sRepName . '</b>'; ?></span><br>
					<?php } ?>
					<?php if(!empty($refName)) {?>
					<span><?php echo mylang("ReferredBy") . ' : <b>' . $refName . '</b>'; ?></span><br>
					<?php } ?>		
					<?php if(!empty($isprojectname) && !empty($prjName)) {?>
					<span><?php echo mylang("ProjectName") . ' : <b>' . $prjName . '</b>'; ?></span><br>
					<?php } ?>		
					<?php if((!empty($source) && $source == 'P') && !empty($tableType) && !empty($tableName)) {?>
					<span><?php echo ($tableType == 'D' ? 'Table: ' : 'Take Away: ') . ' : <span>' . $tableName . '</span>'.(!empty($kot_no) ? '<span style="white-space: nowrap !important;">,  KOT: '. $kot_no . '</span>' : '' ) ; ?></span><br>
					<?php if(!empty($sRepName)) { ?>
						<span><?php echo ('Waiter: ') . ' : <span>' . $sRepName . '</span>'; ?></span><br>
					<?php } ?>
					<?php } ?>		
				</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')
				);
			if(!empty($classCode) && !empty($classCodes[$classCode])){
				?><tr class="vam">
					<td <?php
						if (!$isQuote && $tType != DELCHALLAN && !empty($classCode) && !empty($classCodes[$classCode]))
						{
							echo 'class="bot ac vam bob" style="padding:5px"';
						} else if($tType == "SI" && (empty($classCode) || empty($classCodes[$classCode])) && $isComposition) {

							echo 'class="bot ac vam bob" style="padding:5px"';
						}
					?> colspan="3"><?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";
						}
					?></td>
				</tr><?php
				}else{
					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>';
					}
					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" />';
	}?>
	<?php
		if(!empty($fields))
		{ 
			$this->view($custFieldsView);
		}
		if(!empty($export_details) && ($isExport && $currencyCode != $expCurrencyCode))
		{ 
			$this->view($exportDetailsView);
		}
		$this->view($detailsView,array('isFullPge' => false));
?></page>
<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 } ?>
	}
</style>

