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

//Label declaration
//**********************

$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'] : (!empty($rel_tNo_text) ? $rel_tNo_text : '') ;
$rel_tDate_text =  (!empty($label) && !empty($label['OrderDate'])) ? $label['OrderDate'] :(!empty($rel_tDate_text) ? $rel_tDate_text : '');
//*****************


	$addressView = 'export/address/letterpad';
	$custFieldsView = !empty($custFieldsView) ? $custFieldsView : 'export/customfields';
	$detailsView = 'export/details/salinv';
	if($tType == 'SE'){
		$detailsView.="_est";
	}
	$headColor = (empty($is_email) ? $bgColor : $color);
	
	$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 = '';
	}
	$fontname = (!empty($fontname) && $fontname != 'null' )  ? $fontname : ""; 
	$this->view('export/css', array(
		"fontname" => $fontname
	));

	$company["name"] = "<big><big><big>" . $company["name"] . "</big></big></big>";
	$pdff_type = $pdf_type;
	if(!empty($isOriginal)) {
		$pdff_type = '';
	}

	if (isset($download) && $download==-1){
		echo '<bookmark title="'.$tNo.'" level="0" ></bookmark>';
	}

	if (!empty($isAllPageHeader)) {
		echo '<htmlpageheader name="' . $pdf_type . '">';
	}
	//print_R(count(explode(",",$export_type)));
	//print_R($export_type);exit;
	if(!empty($isOriginal)) {
		$printColors = '';
	}
	if(!empty($printColors)) {
		$headColor = $printColors;
	}
	if(!empty($headColor) && $tType == 'PI') {
		$billing['headColor'] = $headColor;
	}
	//print_R($headColor);
	//$borderColor = $colorr;
	//print_R($colorr);
	if(!empty($isSlip) && $pdf_type == 'Extra Copy') {
		$pdff_type = '';
	}
	
?>
		<?php if($isLogo == 0 || $isLogo == 1) { ?>
	<table cellspacing="0" cellpadding="0" class="vat noborder">
		<tbody>
		
			<tr><?php
				if (!empty($company['logo']))
				{
					echo '<td class="vam" style="width:' . (empty($company['logo_width']) ? '130' : $company['logo_width'] + 20) . 'px;"><div class="imgDiv fltlt"><img src="' . $company['logo'] . '" /></div></td>';
				}
				?>
				<td class="vam <?php echo empty($company['logo']) ? 'ac' : 'ac'; ?>" colspan="<?php echo empty($company['logo']) ? 2 : 1; ?>" style="color:#000; padding-right:<?php echo empty($company['logo']) ? '' : '100px;'; ?>"><?php
					/*
					if (!empty($company['logo']))
					{
						echo '<div class="imgDiv fltlt"><img src="' . $company['logo'] . '" /></div>';
					}
					*/

					echo '<b><big>' . $company["name"] . '</big></b><br>';
					$addr = array();
					if (!empty($company["address1"]))
					{
						$addr[] = $company["address1"];
					}
					if (!empty($company["address2"]))
					{
						$addr[] = $company["address2"];
					}

					echo '<b>' . implode(", ", $addr) . '</b>';
					$addr = array();

					if (!empty($company["city"]))
					{
						$addr[] = $company["city"] . (!empty($company["zip"]) ? ' - ' . $company["zip"] : '');
					}
					if (!empty($company["stateName"]))
					{
						$addr[] = $company["stateName"];
					}
					else if (!empty($company["pos"]))
					{
						$addr[] = $company["pos"];
					}
					if (!empty($company["country"]))
					{
						$addr[] = $company["country"];
					}

					echo '<br>' . '<b>' . implode(", ", $addr) . '</b>';

					$addr = array();
					if (!empty($company["phone"]))
					{
						$addr[] =  mylang("Phone") .':' . $company["phone"];
					}
					if (!empty($company["mobile"]))
					{
						$addr[] = mylang("Mobile").':' . $company["mobile"];
					}
					if (!empty($addr))
					{
						// echo '<td class="vat ar npt npb" colspan="3">';
						echo '<br>' . implode(", ", $addr);
						// echo '</td>';
					}
					if(!empty($company["addInfo"]))
					{
						
						if ($headColor == "transparent") {
							$borderColor = '#FFFFFF';
						}
						else{	
							$borderColor = $headColor;
						}
	
						echo '<br/><p class="addInfo" style="background-color:'.$headColor.';
border-width: 2px 5px;border-style: solid;border-color: '.$borderColor.'" >' . nl2br($company["addInfo"]) . '</p>';
					}
				?></td>
			</tr>
		</tbody>
	</table>
	<table cellspacing="0" cellpadding="0" class="vat noborder">
		<tbody>
			<tr>
				<td class="vab al npt" style="width:50%"><?php echo
					!empty($company["gstin"]) ? mylang("GSTIN") ." : " . $company["gstin"] : '';
					/*
				?></td>
				<td class="vab ac npt" style="width:33.33%"><?php
					if(!empty($company["addInfo"]))
					{
						echo '<div class="addInfo">' . nl2br($company["addInfo"]) . '</div>';
					}
					*/
				?><br>
				<?php echo !empty($company["pan"]) ? mylang("PAN")." : " . $company["pan"] : '';?>
				</td>
				<td class="vab ar npt" style="width:50%"><?php
					if (!empty($company["email"]))
					{
						echo mylang("Email") .':' . $company["email"];
					}
				?></td>
			</tr>
<?php
			/*
			<tr>
			if (!empty($company['logo']))
			{
				?>
				<td width="20%">
					<div class="imgDiv fltlt"><img src="<?php echo $company['logo']; ?>" /></div>
				</td>
				<td width="80%"><?php
					$this->subview($addressView, $company);
				?></td>
				<?php
			}
			else
			{
				$company["address1"] = $company["address1"] . ", " . $company["address2"];
				unset($company["address2"]);
				?><td class="ac"><?php $this->subview($addressView, $company); ?></td><?php
			}
			*/
			/*
			?>
				<td width="20%;"><?php
				if($tType != 'PI') {
					if (!empty($company['logo']))
					{
						echo '<div class="imgDiv fltlt"><img src="' . $company['logo'] . '" /></div>';
					}
				}
				?>
				</td>
				<td class="ac" width="80%"><?php
					$this->subview($addressView, $company);

					if(!empty($company['gstin']))
					{
						echo '<div>GSTIN : ' . $company['gstin'] . '</div>';
					}

					if (!empty($company['addInfo']))
					{
						echo '<div><pre>' . $company['addInfo'] . '</pre></div>';
					}
				?></td>
				<td width="20%;">
					<div>
					</div>
				</td><?php
				</tr>
				*/
?>
		</tbody>
	</table>
	<?php } ?>
	<?php if($paper == 'A5'){
			$img_height = '75px';
	}else{
			$img_height = '150px';
	}?>
	<?php if($isLogo == '2') { echo '<table class="vat noBorder"><tr><td colspan="3" width="100%"><div class="" ><img style="height:auto;
width: 100%;display: inline-block;" src="' . $company['fullHeaderImg'] . '" /></div></td></tr></table>';?>
		
	<?php } ?>
			
	<!--<div style="width:100%;">
		<div style="padding-left:250px;" class="al"><span><b style="font-size:15px;"><?php echo strtoupper($titleText); ?></b></span></div>
		<?php if ($tType != 'SE' && $pdf_type) { ?><div style="padding-left:250px;" class="al"><span><?php echo $pdf_type?></span></div><?php } ?>
	</div>-->
	<table cellspacing="0" cellpadding="0" class="vat" style="border-bottom: none !important;border-left:none;"><?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>
			
				<td class="nbr" <?php echo empty($isShipping) ? 'style="width:60%;"' : 'style="width:30%;"'?>>
					<?php if($tType == 'SK'){
						if($sType == 'TL'){	
							?>
						<table cellspacing="0" cellpadding="0" style="width:100%;border-collapse: collapse;" class="inv_details wpw  bot ft">
							<thead class="bgcolor vam">
							   <tr>
									<?php if(!empty($fromLoc)){?>
								   <th><?php echo "From : ".$fromLoc ; ?></th>
								   <?php } ?>
								   <?php if(!empty($toLoc)){?>
								   <th><?php echo "To : ".$toLoc ; ?> </th>
								   <?php } ?>
							   </tr>
						   </thead>
						</table>
						<?php 
						}
						echo "<br>";
						if(!empty($stocktype)){
							echo "Type : ".$stocktype ;
							echo "<br>";
						}
						} ?> 
					

					<?php if($tType != 'PI' && $tType != 'SK') { ?>
					<span class="bgColor" style="color:<?php echo ($headColor != "transparent") ? $headColor  : 'black'; ?>;"> <?php echo ($tType == 'PI') ?  mylang("Supplier"):mylang("Issued"); ?></span>
					<?php } else {
						if($tType != 'SK'){ ?>
							<?php echo ($tType == 'PI') ? mylang("Supplier") : mylang("Issued");   ?>
						<?php } ?>
					<?php } ?>
					<?php

					if (!empty($billing))
					{
						$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, $billing);
					}

					if(!$expCurrencyCode)
					{
						if(!empty($conTaxNo))
						{
							?><p class="nm"><?php echo !empty($conTaxNo) ? mylang("GSTIN") : ''; ?> : <?php echo $conTaxNo; ?></p><?php
						}
						if(!empty($pos) && $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['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;
						}
						if($tType != 'PO') {
							echo '<td width="30%;" class="nbr">Shipping Address : <br>';
						}
						else {
							echo '<td width="30%;" class="nbr">Dispatch To : <br>';
						}
						$this->subview($addressView, $shipping);
						echo '</td>';
					}
				?><td class="vat nbr" style="width:40%;">
					<table class="noborder invMeta" style="width:100%;padding:0px;">
						<tbody>
							<tr>
								<td colspan="2" class="headtd2 bgColor"  style="color:<?php echo ($headColor != "transparent") ? $headColor  : 'black'; ?>"><?php
									echo $titleText;
									if ($pdf_type && empty($is_email))
									{
										echo '<br><small class="colorr" style="color:'.$headColor.'" >' . $pdff_type . '</small>';
									}
								?></td>
							</tr>
							<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; ?></td>
								<td>: <b><?php echo $dueDate; ?></b></td>
							</tr><?php
							}
							if ($paymentName && ($tType == 'PE' || $tType == 'SR'))
							{
							?><tr>
								<td class="label"><?php  echo mylang("PaymentMode"); ?></td>
								<td>: <b><?php echo $paymentName; ?></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($refName))
							{
							?>
							<tr>
								<td class="label"><?php echo  mylang("ReferredBy"); ?></td>
								<td>: <b><?php echo $refName; ?></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;border-top: 1px solid black; " width ="25%">';
							?><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')
				);
			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;border-right: none;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-bottom: 0.5px solid #000000;"';
						}
					?> 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" />';
	}

	if(!empty($fields))
	{
		$this->view($custFieldsView);
	}

	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 && !empty($isPageNo))
	{
		//echo '<page_footer><p><small class="">page [[page_cu]]/[[page_nb]]</small></p></page_footer>';
	}
	$params = array(
		"useSimpleTaxCol" => 1,
		"isNormal" => 1,
		"isShowFor" => 1,
		"showVerticalLine" => 1
	);
	
	// if ($tType == 'SK'){
	// 	$isAmount = ($isAmount === 'true' || $isAmount === '1') ? true : false;
	// 	if(!empty($istotqty)&& empty($isAmount)) {
	// 			$params["isclassictemp"] = 1;
	// 	}
	// }
	if ($tType === 'SK') {
		$isAmount = isset($isAmount) && ($isAmount === 'true' || $isAmount === '1');
		
		if (!empty($istotqty) && !$isAmount) {
		$params["isclassictemp"] = 1;
		}
		}
		

$this->view($detailsView, $params);

	?><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;
		}
		.addInfo, .extraCont {
			display: inline-block;
			margin: 0;
		}
<?php if ($headColor != "transparent") { ?>
		.addInfo, .extraCont {
			background: <?php echo $headColor; ?>;
			color: #FFFFFF;
			border-width: 2px 5px;
			border-style: solid;
			border-color: <?php echo $headColor; ?>;
		}
<?php } ?>

	</style>
</page>
