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

if (!function_exists("custom_pdf_config"))
{
	function custom_pdf_config($pdfConfig)
	{
		$pdfConfig["margin_left"] = 0;
		$pdfConfig["margin_right"] = 0;
		$pdfConfig["margin_header"] = 0 * 25.4;
		$pdfConfig["margin_bottom"] = 2.5 * 25.4;
		$pdfConfig["margin_top"] = 4.15 * 25.4;

		return $pdfConfig;
	}
}

if (!function_exists("add_pdf_font"))
{
	function add_pdf_font(&$mpdf)
	{
/*
    margin-top: 3.9in;
    margin-header: 0in;
    margin-bottom: 2.5in;
*/
		$mpdf->fontdata["bolt"] = array(
			"R" => "bolt.ttf",
			"B" => "bolt-Bold.ttf",
			"I" => "bolt-Italic.ttf",
			"BI" => "bolt-BoldItalic.ttf"
		);
		$mpdf->available_unifonts[] = "bolt";
	}
}

	if (!isset($isCompact))
	{
		$isCompact = false;
	}

	$addressView = !empty($addressView) ? $addressView : 'export/address/hearing';
	$detailsView = !empty($detailsView) ? $detailsView : 'export/details/hearing';
	$custFieldsView = !empty($custFieldsView) ? $custFieldsView : 'export/customfields';
	$exportDetailsView = !empty($exportDetailsView) ? $exportDetailsView : 'export/exportdetails';

	$headColor = (empty($is_email) ? $bgColor : $color);

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

	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;
	}
	$pdff_type = $pdf_type;
	//For Normal Print clicks hide the pdf type
	if(!empty($isOriginal))
	{
		$pdff_type = '';
	}
	if($bgColor == 'transparent')
	{
		$showVerticalLine= false;
	}
	else
	{
		$showVerticalLine = true;
	}
	$this->view('export/css', array(
		"fontname" => "bolt"
	));

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

	if($dueDate == '0000-00-00')
	{
		$dueDate = '';
	}

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

	echo '<htmlpageheader name="' . $pdf_type . '">';

	if(!empty($isOriginal))
	{
		$printColors = '';
	}
	if(!empty($printColors))
	{
		$headColor = $printColors;
	}
	if(!empty($isSlip) && $pdf_type == 'Extra Copy') {
		$pdff_type = '';
	}

	// style="width: 20.6cm; height:27.8cm;"
?>
<div class="mainpage">
<div class="trans">
	<table border="0" cellspacing="0" cellpadding="0" class="noborder nopadding vat" style="table-layout:fixed;">
		<tbody>
			<tr>
				<td style="width:10.2cm;"></td>
				<td style="width:9.9cm;text-align: right;padding-top: 0.5cm;padding-right: 1.5cm;">
					<?php if ($tType == 'PI' || $tType=='PC' || $tType == 'PD'){
							if(!empty($conName))
							{
								$this->subview($addressView, $billing);
							}
							$isShowAddress = false;
							if($tType == 'PI')
							{
								if(!empty($conTaxNo))
								{
									echo '<p class="nm">'.lang("GSTIN").' : '. $conTaxNo.'</p>' ;
								}
								echo '<p class="nm">'.lang("SOS").' : '.$pos.'</p>' ;
							}
						}
						else if ($tType == 'PE')
						{
							echo $company["name"] . "<br>";

							if(!empty($company["city"]))
							{
								echo $company["city"];
								if($company["zip"])
								{
									echo ' - ' . $company["zip"];
								}
							}
						}
					else
					{
						unset($company["name"]);
						$this->subview($addressView, $company);
					}
					if (!empty($company["gstin"]))
					{
						echo lang("GSTIN") . " : " . $company["gstin"];
					}
					
					?>
				</td>
			</tr>
		<!--	<?php
				

				if (!empty($tType!='PI') && !empty($tType!='PC') && !empty($tType != 'PD'))
				{
					$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 if($tType == "SI" && (empty($classCode) || empty($classCodes[$classCode])) && $isComposition) {

						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];
					}
					 if($tType == "SI" && (empty($classCode) || empty($classCodes[$classCode])) && $isComposition) {
						echo "COMPOSITION TAXABLE PERSON, NOT ELIGIBLE TO COLLECT TAX ON SUPPLIES";
					 }
				?></td>
			</tr><?php
			}
		?>--></tbody>
		</table>
	</div><?php

if (!empty($tType!='PI') && !empty($tType!='PC') && !empty($tType != 'PD') )
{
	?><div class="trans">
		<table border="0" cellspacing="0" cellpadding="0" class="noborder" style="table-layout:fixed">
			<tbody>
				<tr>
					<td style="width:9.7cm;">
						<?php echo str_repeat("<br/>", 10); ?>
						<div style="font-size: 22px;">
							<div class="width: 100%;display:block;"><?php echo str_repeat("&nbsp;", 25) . $tNo; ?></div>
							<div class="width: 100%;display:block;padding-top:0.5cm;"><?php echo str_repeat("&nbsp;", 25) . $tDate; ?></div>
						</div>
					</td>	
					<td style="width:9.9cm;text-align: right;padding-right: 1.5cm;"><?php
						if(!empty($billing['name']) || !empty($shipping['name']))
						{
						?><div><?php
							$contact_name = !empty($contact['company']) ? $contact['company'] : (!empty($contact['contactPerson']) ? $contact['contactPerson'] : (!empty($contact['name']) ? !empty($contact['name']) : ""));

						if($contact_name || !empty($conName))
						{
							?><p class="fw nm" style="font-size: 14px;"><?php
							echo ($tType == 'PI') ? 'Supplier / Vendor' : 'Invoice To';
							?></p><?php
						}

						/*
						if ($contact_name)
						{
							echo '<p class="fw nm" style="font-size: 18px;">' . $contact_name . '</p>';
						}
						else if (!empty($conName))
						{
							echo '<p class="fw nm" style="font-size: 18px;">' . $conName . '</p>';
						}
						*/

						if (!empty($contact['contactPersonMobile']))
						{
							$billing['mobile'] = $contact['contactPersonMobile'];
							if(empty($isShipping))
							{
								$shipping['mobile'] = $contact['contactPersonMobile'];
							}
						}

						$this->subview($addressView, $billing);

						if(!$expCurrencyCode)
						{
							if(!empty($conTaxNo) )
							{
								?><p class="nm"><?php echo lang("GSTIN"); ?> : <?php echo $conTaxNo; ?></p><?php
							}
							else if(!empty($contact['taxNo']))
							{
								?><p class="nm"><?php echo lang("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"><?php echo lang("POS")?> : <?php echo $pos; ?></p><?php
							}
							if($tType=='PI')
							{
								?><p class="nm"><?php echo lang("SOS")?> : <?php echo $pos; ?></p><?php
							}
							*/
						}
					}
?>			</td>
		</tr>
			</tbody>
		</table><?php
	} ?>
	</div>
	<!-- /page_header -->
	<?php
	echo '</htmlpageheader><sethtmlpageheader name="'.$pdf_type.'" value="on" show-this-page="1"></sethtmlpageheader>';

?><div class="trans"><?php
		if (!empty($export_details[0]['value']))
		{
			$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" => isset($useSimpleTaxCol) ? $useSimpleTaxCol : 1,
		'showVerticalLine' => 1,
		'isShowFor' => '1',
		'isSlNoCol' => false,
		'isSkuCol' => false,
		'isHsnCol' => false,
		'gridFields' => false,
		'mrpInPurSal' => false,
		'hasDiscount' => false,
		'showTax' => false,
		'isqty' => true
		// "hideAllAmount" => 1,
	));

	// 20.6cm 27.8cm
	/*
@page {
    background: url("assets/templates/salretail/hearing.jpg") no-repeat 0 0;
    background-size: 20.6cm 27.8cm;
    background-image-resize: 6;
}
	size: 20.6cm 27.8cm;
body {
	width: 20.6cm;
	height: 27.8cm;
    background: url("<?php echo base_url(); ?>assets/templates/salretail/hearing.jpg") no-repeat 0 0;
    background-size: 20.6cm 27.8cm;
    background-image-resize: 6;
}
	*/
?>
<style>
<?php if(!empty($isPrint)) { ?>
.invMeta td {
	padding:0px;
}
<?php } ?>
</style>
</div>
