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

	$addressView = 'export/address/salinv';
	$detailsView = 'export/details/salinv2';
	$custFieldsView = !empty($custFieldsView) ? $custFieldsView : 'export/customfields';
	$letterPadHeader = 'export/letterpadHeader';
	
	$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;
	$transType = !empty($arr[$tType]) ? $arr[$tType] : lang($tType);
	$transUrl = array(
		'SE' => 'estimate',
		'SO' => 'order',
		'JO' => 'joborder',
		'SI' => 'invoice',
		'SR' => 'invoice',
		'SH' => 'deliverychallan',
		'SC' => 'creditnote',
		'SD' => 'debitnote',
		'SP' => 'receipts',
		'AO' => 'opening',
		'PI' => 'bills',
		'JV' => 'journal',
		'PP' => 'payments',
		'PC' => 'creditnote',
		'PD' => 'debitnote',
		'PO' => 'estimate'

	);
	$headColor = (empty($is_email) ? $bgColor : $color);
	$isPrint = $export_type ? true : false;
	if(!empty($sigOnPrint)) {
		$isSign = 1;
	}
	$fontname = (!empty($fontname) && $fontname != 'null' )  ? $fontname : "";
	$this->view('export/css', array(
		"fontname" => $fontname
	));

	/*if (!empty($company['invsign']))
	{
		if ($isPrint && !$signOnPrint) {
			$company['invsign'] = null;
		}

		if ((!$isPrint || $is_email) && !$signMailPdf) {
			$company['invsign'] = null;
		}
	}*/
	$pdff_type = $pdf_type;
	
	if(!empty($isOriginal))
	{
		$pdff_type = '';
	}
	
	//print_R($billing);
?>
<page footer="page" pagegroup="new"><?php
	if (!empty($isPrint) && !empty($isPageNo))
	{
		?><page_footer><p><small>page [[page_cu]]/[[page_nb]]</small></p></page_footer><?php
	}

	if ($tType != 'SE' && $pdf_type && empty($is_email))
	{
		?><div class="ar"></div><?php
	}
	?>	
	<div><div class="ac">
	<?php if(!empty($isLogo) && $isLogo == '1' || $isLogo == '0') {
		
		 $this->view($letterPadHeader); 
	 } ?>
	<div class="trans">
	<?php if(!empty($isLogo) && $isLogo == 2) { ?>
		<table class="noborder vat" cellspacing="0" cellpadding="0" style="width:100%;">
			<tbody>
			
				<?php echo '<tr><td colspan="3" width="100%"><div class="" ><img style="height: 150px;
width: 100%;display: inline-block;" src="' . $company['fullHeaderImg'] . '" /></div></td></tr>';?>
			</tbody>
		</table>
	<?php } ?>
	
	<div class="highlght ac"><?php echo empty($titleText) ? 'RECEIPT' : strtoupper($titleText); ?></div>
	</div>
	</div>
	<!--<p class="">
		<span class="fltlt">Receipt No : <b><?php echo $tNo; ?></b></span>
		<span class="fltrt">Date : <b><?php echo $tDate; ?></b></span>
	</p>-->
	<table class="noborder vat" cellspacing="0" cellpadding="0">
		<tbody>
			<tr>
				<td class="dashed"><?php echo mylang("ReceiptNo");?> <b><?php echo $tNo; ?></b></td>
				<td class="ar dashed"><?php echo mylang("Date");?> <b><?php echo $tDate; ?></b></td>
			</tr>
		</tbody>
	</table>
	<div class="trans"><?php
		
		if(!empty($fields))
		{ 
			$this->view($custFieldsView);
		}
	?>
	</div>
<?php
	if(!empty($details) && count($details) > 1){?>
	<br>
		<table cellspacing="0" cellpadding="0" style="width:80%;" class="det" align="center" >
			<thead>
				<tr>
					<th class="al"><?php echo mylang("Name"); ?></th>
					<th class="al"><?php echo mylang("Contact"); ?></th>
					<th class="ar"><?php echo mylang("Amount"); ?></th>
				</tr>
			</thead>
			<tbody>
			<?php foreach ($details as $key => $val)
			{ ?>
					<tr>
						<td class="al"><?php echo !empty($val['conName']) ? $val['conName'] : $val['itemName']; ?></td>
						<td class="al"><?php echo $val['conName']; ?></td>
						<td class="ar"><?php  echo $val['itemTotal']; ?></td>
					</tr>
		<?php } ?>
			</tbody>
		</table>
	<?php } ?>
	<table class="paymentTable noborder vat" cellspacing="0" cellpadding="0" align="center" >
		<tbody>
			<?php
				if(!empty($details) && count($details) == 1){?>
				<tr>
					<td><?php echo mylang("Name");?></td>
					<td><?php echo !empty($details[0]['conName']) ? $details[0]['conName']: $details[0]['itemName'];?></td>
				</tr>
			<?php } ?>
			<?php if (!empty($billing)) { ?>
			<tr>
				<td><?php echo mylang("AmountReceivedfrom");?></td>
				<td><?php
					// $conTaxNo
					if(!empty($conTaxNo))
					{
						$billing["gstin"] = $conTaxNo;
					}
					else if(!empty($contact['taxNo']))
					{
						$billing["gstin"] = $contact['taxNo'];
					}

					$this->subview($addressView, $billing);
				?></td>
			</tr>
			<?php } ?>
			<?php if($isExport)  { ?>
			<tr>
				<td><?php echo mylang("AmountReceived")?> (<?php echo $expCurrencyCode ?>)</td>
				<td><b><?php echo $totForexAmt ?></b> (<?php echo $exp_amt_str . " only"; ?>)</td>
			</tr>
			<?php } ?>
			<?php if(!$isExport || !$is_email)  { ?>
				<tr>
					<td><?php echo mylang("AmountReceived")?> (<?php echo $currencyCode; ?>)</td>
					<td><b><?php echo $totAmountCurr; ?></b></td>
				</tr>
			<?php } ?>
			<?php if(!$isExport || !$is_email)  { ?>
				<tr>
					<td><?php echo mylang("AmountReceivedinwords")?></td>
					<td><?php echo $amt_str . " only"; ?></td>
				</tr>
			<?php } ?>
			<?php 
				if((!$isExport || !$is_email) && !empty($isrcptbalance) && !empty($balance) && $balance >0) {
					$balance = formatAmount($balance, $currencyCode,'','', $currFraction);
			 ?>
				<tr>
					<td><?php echo mylang("OutstandingBalance")?></td>
					<td><?php echo $balance; ?></td>
				</tr>
			<?php } ?>
			<?php 
			if(!empty($payModes)){
			$payment_count = count($payModes); 
			if($payment_count == 1){
				 foreach ($payModes as $val){ ?>
				 	<?php if(!empty($val['pAccName'])){?>
					<tr>
						<td><?php echo mylang("DepositA/C")?></td>
						<td><?php
							if(!empty($val["pConName"])) {
								echo $val['pConName'].' (';
							}
							echo $val['pAccName']; 
							if(!empty($val["pConName"])) {
								echo ')';
							}
						?></td>
					</tr>
					<?php } ?>
					<?php if(!empty($val['pModeName'])){?>
					<tr>
						<td><?php echo mylang("PaymentMode")?></td>
						<td><?php echo $val['pModeName']; ?></td>
					</tr>
					<?php }?>
					<?php 	if(!empty($val['pRef'])){?>				
					<tr>
						<td><?php echo mylang("Reference")?></td>
						<td><?php echo $val['pRef']; ?></td>
					</tr>
					<?php }?>
				<?php
				} 
			} 
			if($payment_count > 1){?>
			<tr>
				<td colspan="2" width="100%">
				<table width= "100%" class="vat payment" cellspacing="0" cellpadding="0">
					<thead>
						<tr>
							<th><?php echo mylang("DepositA/C")?></th>
							<th><?php echo mylang("PaymentMode")?></th>
							<th><?php echo mylang("Reference")?></th>
							<th><?php echo mylang("AmtReceived")?></th>
						</tr>
					</thead>
					<tbody>
					<?php foreach ($payModes as $val)
					{
						if(!empty($val['pRefName'])){
							$val['pRef'] = $val['pRefName'];
						}
						$val['pAmount'] = formatAmount(!empty($val['pAmount']) ? $val['pAmount'] : 0, $isExport ? $expCurrencyCode : $currencyCode, "-", true,$currFraction);
		                        ?>
					<tr>
						<td><?php 
							if(!empty($val["pConName"])) {
								echo $val['pConName'].' (';
							}
							echo $val['pAccName']; 
							if(!empty($val["pConName"])) {
								echo ')';
							} ?></td>
						<td><?php echo $val['pModeName']; ?></td>
						<td><?php echo $val['pRef']; ?></td>
						<td class="ar"><?php echo $val['pAmount']; ?></td>
					</tr>
					<?php }
					 ?>	
					</tbody>
				</table>
				</td>
			</tr>
			<?php } 
			}
			 ?>
			<!--<?php if (!empty($ref)){ ?>
			<tr>
				<td><?php echo mylang("Reference");?></td>
				<td><?php echo $ref; ?></td>
			</tr><?php } ?>-->
			<?php if (!empty($notes)){ ?>
			<tr>
				<td><?php echo mylang("Remarks");?></td>
				<td> <?php echo $notes; ?></td>
			</tr><?php } ?>
			<?php 
			if (!empty($payments) && ( $tType == 'SP' || empty($isPrint) || $isPrint != 1) ){ ?>
			<tr>
				<td><?php echo mylang("Paymentfor");?></td>
				<td> <?php $linkednotes = "<span>";
					$i = 0;$breakcount =6;
					foreach ($payments as $val)
					{
						$addcomma = '';
						if($i < count($payments)-1) {
							$addcomma = '<span>,</span>';
						}
						$linkednotes.= '<a style="color:'.(!empty($bgColor) && $bgColor != 'transparent' ? $bgColor : '#4183c4').';text-decoration: none;padding: 2px 2px;" href="'.base_url().'index.php/'.(($val['tType'] == 'PI'|| $val['tType'] == 'PP'|| $val['tType'] == 'PC'|| $val['tType'] == 'PD'|| $val['tType'] == 'PO') ? 'purchase/' : 'sales/') .$transUrl[$val['tType']].'/'.$val['allotTransId'].'" target="_blank"><b>'. $val['tNo'].'</b></a>'.$addcomma;
						if($i == $breakcount){
							$linkednotes.= '<br>';
							$breakcount = $i +6;
						}
						$i++;
					}
					$linkednotes .= "</span>";
					echo $linkednotes; ?></td>
			</tr><?php } ?>
			<tr>
			<?php if(!empty($sRepName))  { ?>
				<td><?php echo $srep_text; ?></td>
				<td> <?php echo $sRepName; ?></td>
			<?php } ?>
			</tr>
			<tr>
			<?php if (!empty($isprojectname) && !empty($prjName))  { ?>
				<td><?php echo mylang("ProjectName"); ?></td>
				<td> <?php echo $prjName; ?></td>
			<?php } ?>
			</tr>
			<tr>
				<td class="ac bot" colspan="2" width="100%"><?php echo mylang("Thanks");?></td>
			</tr>
			
		</tbody>
	</table><br>
	<table align="left" cellspacing="0" cellpadding="0" class="footTable vat noBorder dotted" autosize="1" style="page-break-inside: avoid">
	<!--<col style="width:50%;">
	<col style="width:50%;">-->
	<tbody><?php
	if ($terms)
	{
		?><tr>
			<td valign="bottom" colspan="2" class="vab terms" ><?php
				?><div class="noside " style="display:inline-block;"><span class="nm pretxt"><?php echo mylang("Terms")?> :<br><?php echo nl2br($terms); ?></span></div>
			</td>
		</tr><?php
	}

		if ((!$is_email || !empty($company['invsign'] || !empty($is_pdf))) && !empty(trim(lang("For"))))
		{
			$clr = ($headColor == 'transparent') ? 'black' : $headColor;
		if(!empty($isSign)) { ?><tr>
			<td class="ar bgColor" colspan="2" style="color:<?php echo $clr; ?>" ><?php echo mylang("ForcompanyName"); ?></td>
		</tr><?php } 
		}
		?><tr><?php
			$wid = '';
			if($paper == 'A5') {
				$wid = '20mm';
			}
			$hgt = '';
			if(empty($isSign)) {
				$hgt = '100px';
			}
			echo '<td valign="bottom" class="vab nbr custsign bgColor" style="height:'.$hgt.'">';
			if ((!$is_email  ||!empty($is_pdf)) && !empty($isCustSign))
			{
				$clr = ($headColor == 'transparent') ? 'black' : $headColor;
				echo '<span class="" style="margin-top:40px;color:'.$clr.'" >' . ($tType == DELCHALLAN ? mylang("Received") : mylang("CustomerSignature")) . '</span>';
			}
			echo '</td>';
			
			echo '<td valign="bottom" class="vab ar authsign bgColor" style="color:'.$headColor.'" >';
			//echo $eOe;
			if ($tType != PURINV && !empty(trim(lang("For")))) {
				if (!empty($company['invsign']) && (!empty($signOnPrint)))// $isPrint
				{
					$clr = ($headColor == 'transparent') ? 'black' : $headColor;
					echo '<span class="sign"><img src="' . $company['invsign'] . '" width="'.$wid.'" height="" /style="margin-top:0px;color:'.$clr.'" /></span><br>';
					if(!empty($isSign)) {
						echo '<span style="color:'.$clr.'">'.mylang("AuthorizedSignature").'</span>';
					}
				}
				else if (!empty($isSign) && (!$is_email || !empty($company['invsign'] || !empty($is_pdf))))
				{
					$clr = ($headColor == 'transparent') ? 'black' : $headColor;
					echo '<br><br><br><span class="" style="margin-top:40px;float:right;color:'.$clr.'">'.mylang("AuthorizedSignature").'</span>';
				}
			}
			echo '</td>';
		?></tr>
	</tbody>
</table>
	</div>
<?php
	if (!empty($footerText))
	{
		echo '<p class="footerTxt nm">' . $footerText . '</p>';
	}
	if (!empty($waterMark))
	{
		echo '<p class="watermark nm">' . $waterMark . '</p>';
	}	
?>
</page>
<style>
	table.paymentTable {
		width: 80%;
		min-width: 500px;
		/*border: 0.1px solid <?php echo $borderColor; ?>;*/
	}
	.dotted{
		border-top: 0.1px solid black !important;
	}
	table tr td.dashed {
		border-bottom: 0.1px solid black !important;
	}
	.authSign {
		margin-top: 60px;
	}
	table.payment th ,table.payment td{
		border-right: 0.1px solid black !important;
		border-top: 0.1px solid black !important;
	}
	.highlght {
		background-color: <?php echo $bgColor; ?>;
		color: <?php echo $foreColor; ?>;
    		padding: 6px;
		padding-top:<?php echo !empty($isPrint) ? '3px' : ''; ?>;
	    	font-weight: bold;
	    	font-size: 19px;
	}
	
</style>
