<?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';
	$detailsView = 'export/details/GSTinvoice';
	$headColor = (empty($is_email) ? $bgColor : $email_color);
	$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;
	}
	$this->view('export/css');

	if($tType == 'PC' || $tType == 'PD' || $tType == 'PE') { 
		$company['logo'] = '';
	}

	if (isset($download) && $download==-1){
		echo '<bookmark title="'.$tNo.'" level="0" ></bookmark>';
	} ?>
<htmlpageheader name="<?php echo $pdf_type; ?>">
	<div class="trans">
		<table width="50%" border="0" cellspacing="0" cellpadding="0" class=" vat"><?php
			/*if (!empty($company['logo']))
			{
				if (empty($isPrint))
				{	
					echo '<col style="width: 15%">';
				}
				else {
					echo '<col style="width: 25%">';
				}
				echo '<col style="width: 45%">';
			}
			else
			{
				echo '<col style="width: 70%">';
			}*/
			?><!--<col style="width: 30%">-->
			<tbody>
				<tr><?php
					if (!empty($company['logo']))
					{
						echo '<td class="vat" style="height:auto; border-right:none;" width="25%"><div class="imgDiv fltlt" ><img src="' . $company['logo'] . '" /></div></td>';
					}
					?><td style="border-right:none;" <?php echo !empty($company['logo']) ? 'width="50%"' : 'width="45%"' ?>><?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 {
							$company["name"] = strtoupper($company["name"]);
							$this->subview($addressView, $company); 
							if($gstin)
							{
								// echo '<br>';
								echo '<div style="padding-bottom:5px;">GSTIN : ' . $gstin . '</div>';
							} 
						}
					?></td>
					<td class="vat "  <?php echo !empty($isPrint) && ($tType == 'PC' ||  $tType == 'PD' || $tType == 'PE')? 'width="50%"' : 'width="45%"' ?>>
						<table class="noborder invMeta">
							<tbody>
								<tr><td colspan="2" <?php echo !empty($headcolor) ? 'style="padding:5px;"' : '' ?> class="headtd"><?php echo $titleText; ?></td></tr>
								<?php if ($pdf_type && empty($is_email)) { ?>
									<tr><td colspan="2" ><h4 class="nm dib"><?php echo $pdf_type; ?></h4></td></tr>
								<?php }?>
								<tr>
									<td class="label"><?php echo $tNo_text; ?></td>
									<td>: <b><?php echo $tNo; ?></b></td>
								</tr>
								<tr>
									<td class="label"><?php echo $tDate_text; ?></td>
									<td>: <b><?php echo $tDate; ?></b></td>
								</tr><?php

								if ($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">Reference No</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>
				</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')
						);
				?><?php 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-top:0.5px solid grey;border-bottom:0.5px solid grey"';
						}
						else
						{
							echo 'class="bot ac vam" style="border-bottom:0.5px solid grey"';
						}
					?> colspan="<?php echo !empty($company['logo']) ? 3 : 2; ?>"><?php
						if (!$isQuote && !empty($classCode) && !empty($classCodes[$classCode]))
						{
							echo $classCodes[$classCode];
						}
					?></td>
				</tr><?php } ?><?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']))
	{
		?><table border="0" cellspacing="0" cellpadding="0" class=" nopadding vat"><?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 width="50%" style="padding-left:5px;border-top:none;"  <?php echo !empty($showVerticalLine) ? 'style="padding:5px;border-left: 4px solid #000000 '.$headColor.'"' : '' ?>>
							
					
					<?php if(!empty($isShowAddress) && !empty($billing['countryCode'])) { ?>
						 <div><?php
							$addr = "Billing" . ($isAllServices || $isShipping || $isQuote ? '' : ' & Shipping') . " Address :";

							if ($tType == 'PO')
							{
								$addr = "Supplier";
							}

							echo '<span class="">' . $addr . '</span>';
							$this->subview($addressView, $billing);
						?></div><?php
						if ($isShipping && !$isAllServices)
						{
							echo '<br>Shipping Address : <br>';
							$this->subview($addressView, $shipping);
							
						}
					} ?><div><?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
								}
								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><br>

					</td>
					<td width="50%" style="border-top:none;" >
						<table class="nopadding " style="border-bottom:none;border-left:none;" ><tbody>
						<?php

											if (!empty($relNumber))
											{
											?><tr>
												<td width="50%" class="label" style="border-top:none;border-right:none;padding-left:5px;padding-bottom:10px;"><?php echo $rel_tNo_text; ?>: <br><b><?php echo $relNumber; ?></b></td>
												
											<?php
											}?><?php
										if (!empty($relDate))
											{
											?>
												<td width="50%" class="label" <?php echo !empty($isPrint) ? ' style="border-top:none;border-right:none;padding-left:77px;padding-bottom:10px;"':' style="border-top:none;border-right:none;padding-left:5px;padding-bottom:10px;"';?> ><?php echo $rel_tDate_text; ?>:<br> <b><?php echo $relDate; ?></b></td></tr>
												
												<?php
											}?>
						<tr>
						<?php if ((!empty($export_details[0]['value']))||(!empty($fields))){?>
						<td width="50%" colspan="<?php if(!empty($fields)) { echo 2; }?>" <?php echo !empty($isPrint) ? ' 							style="border-right:none;border-top:none; border-bottom:1px;"':' style="border-right:none;border-top:none; 							padding-left:5px;"';?>><?php
						if (!empty($export_details[0]['value']))
						{
							$this->view($exportDetailsView);
						}
						if(!empty($fields))
						{ 
							$this->view($custFieldsView,array('isTaxSheet' => 1));
						}
					?></td><?php } ?>
				</tr>
	
			</tbody></table></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" /><?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,'isShowFor' => '1',"isHsnBreakup" => 0,"showTaxBreakup" => 0));
?>
<style>
.invMeta {
	width: auto;
}
<?php if(!empty($isPrint)) { ?>
.invMeta td {
	padding:0px !important;
}
<?php } ?>
</style>

