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

$arr = array(
	'SE' => 'Quote',
	'SC' => 'Sales Credit note',
	'SD' => 'Sales Debit note',
	'SR' => 'Cash invoice',
	'SI' => 'Tax Invoice'
);

if($tType == 'SI' && in_array($classCode, array('EXPWP', 'EXPWOP', 'DEEM', 'EXPBO')))
{
	$arr['SI'] = 'Export Invoice';
}
$transType = !empty($arr[$tType]) ? $arr[$tType] : lang($tType);

$all_zero = true;

if(!empty($details)) {
	foreach($details as $val) {
		if (!empty($val['discAmount'])) {
			$all_zero = false;
		}
	}
}

?>
<page footer="page">
	<div class="trans">
		<table border="0" cellspacing="0" cellpadding="0" style="width:100%;">
			<tr>
				<td align="left" style="vertical-align:top;"> 
					<span class="customer label text" style="font-size:17px;height:50px;">&nbsp;<?php echo $transType; ?>&nbsp;</span>
					<h2>{pdf_type}</h2>
				</td>
				<td style="width:25%;vertical-align:top">
					<table style="width:80%">
						<tr>
							<td class="label">{tNo_text}</td>
							<td>:&nbsp;&nbsp;<b>{tNo}</b></td>
						</tr>
						<tr>
							<td class="label">{tDate_text}</td>
							<td>:&nbsp;&nbsp;<b>{tDate}</b></td>
						</tr>
						<?php if ($dueDate) { ?>
							<tr>
								<td class="label">{dueDate_text}</td>
								<td>:&nbsp;&nbsp;<b>{dueDate}</b></td>
							</tr>
						<?php } ?>
						<?php if ($ref) { ?>
							<tr>
								<td class="label">Reference No</td>
								<td>:&nbsp;&nbsp;<b>{ref}</b></td>
							</tr>
						<?php } ?>
					</table>
				</td>
				<td align="right" style="width:33%;vertical-align:top;margin-left:30px;">
					<span  style="font-size:13px;">{company_addr}</span>
				</td>
			</tr>
			<tr>
				<td style="padding:20px 0pc 20px 0px;" colspan="3">
					<div style="border-bottom:1px solid #b7b7b7;"></div>
				</td>
			</tr>
			<tr>
				<td style="width:33%;" valign="top">	
					<span style="font-size:12.5px;"><?php echo lang("Issued"); ?> </span>		
					<h4 class="label" style="font-size:17px"><?php echo !empty($contact['name']) ?$contact['name']:'' ;?></h4>
					<?php if(!$expCurrencyCode) { ?>	
					<table border="0" cellspacing="0" cellpadding="0" style="width:100%;">
						<tbody>
							<?php if(!empty($contact['taxNo'])) { ?>
							<tr>
								<td style="width:25%" class="label-14"><?php echo lang("GSTIN"); ?></td>
								<td class="label-14" >:&nbsp;&nbsp;<b><?php echo !empty($contact['taxNo'])?$contact['taxNo']:'-'; ?></b></td>
							</tr>
							<?php } ?>
							<tr>
								<td class="label-14"><?php echo lang("POS"); ?></td>
								<td class="label-14">:&nbsp;&nbsp;<b><?php echo !empty($pos)?$pos:'-'; ?></b></td>
							</tr>
						</tbody>
					</table>
					<?php } ?>
				</td>
				<td style="width:33%;">
					<span class="label" style="font-size:12.5px;"><?php echo lang("Billing Address"); ?></span><br>
					<span class="label" style="font-weight:normal;font-size:13px">{billing_addr}</span>
				</td>
				<td style="width:33%;">
					<span class="label" style="font-size:12.5px;"><?php echo lang("Shipping Address"); ?></span><br>
					<span class="label" style="font-weight:normal"> {shipping_addr}</span>
				</td>			
			</tr>
			<?php if (!empty($export_details)) { ?>
				<tr>
					<td style="padding:20px 0pc 20px 0px;" colspan="3">
						<div style="border-bottom:1px solid #b7b7b7;"></div>
					</td>
				</tr>
				<tr>
					<?php
						$td_1 = $td_2 = $td_3 = '';
						$i=0;
						foreach ($export_details as $row) { 
							if ($row['value']) {
								$i++;
								${'td_'.$i}.= '<tr><td>'.$row['label'].'</td><td>'.$row['value'].'</td></tr>';
							}
							if ($i==3) {
								$i=0;
							}
						}
					 ?>
					<td style="width:33%;vertical-align: top;">
						<table><tbody class="label"><?php echo $td_1;?></tbody></table>
					</td>
					<td style="width:33%;vertical-align: top;">
						<table ><tbody class="label"><?php echo $td_2;?></tbody></table>
					</td>
					<td style="width:33%;vertical-align: top;">
						<table ><tbody class="label"><?php echo $td_3;?></tbody></table>
					</td>
				</tr>				 
			<?php } ?>
			<?php if ($fields) { ?>
				<tr>
					<td style="padding:20px 0pc 20px 0px;" colspan="3">
						<div style="border-bottom:1px solid #b7b7b7;"></div>
					</td>
				</tr>
				<?php
					$td_1 = $td_2 = $td_3 = '';
					$i=0;
					foreach ($fields as $row) { 
						if ($row['fValue']) {
							$i++;
							${'td_'.$i}.= '<tr><td>'.$row['fName'].': </td></tr><tr><td>&nbsp;</td></tr><tr><td><b>'.$row['fValue'].'</b></td></tr>';
			
						}
						if ($i==3) {
							$i=0;
						}
					}  ?>
					<tr>
						<td style="width:33%;vertical-align: top;">
							<table><tbody class="label"><?php echo $td_1;?></tbody></table><br>
						</td>
						<td style="width:33%;vertical-align: top;">
							<table><tbody class="label"><?php echo $td_2;?></tbody></table>
						</td>
						<td style="width:33%;vertical-align: top;">
							<table><tbody class="label"><?php echo $td_3;?></tbody></table><br>
						</td>
					</tr>				 
			<?php } ?>
			<tr>
				<td style="padding:20px 0pc 20px 0px;" colspan="3">
					<div style="border-bottom:1px solid #b7b7b7;"></div>
				</td>
			</tr>
			<tr>
				<td colspan="3" >
					<!--<div class="middlecol"> -->
						<table border="0" align='left' cellspacing="0" cellpadding="0" style="border-color:#b7b7b7;" class="middlecol">
							<thead class="label-13">
								<tr>
								<th style="width:40%;border-left:1px solid #b7b7b7;font-weight: normal;"><?php echo lang("ItemDescription"); ?></th>
								<th style="width:10%;font-weight: normal;"><?php echo lang("Tax"); ?></th>
								<th style="width:10%;font-weight: normal;"><?php echo lang("HSN/SAC"); ?></th>
								<th style="width:10%;font-weight: normal;"><?php echo lang("Qty"); ?></th>
								<th style="width:10%;font-weight: normal;"><?php echo lang("Rate"); ?></th>
								<?php if(!$all_zero) { ?>								
								<th style="width:10%;font-weight: normal;"><?php echo lang("Discount"); ?></th><?php } ?>
								<th style="width:10%;font-weight: normal;"><?php echo lang("Amount"); ?></th>
								</tr>
							</thead>
							<tbody>
								{details}
									<tr class="label">
										<td style="border-left:1px solid #b7b7b7;">{itemName}</td>
										<td>{taxName}</td>
										<td>{itemHS}</td>
										<td style="text-align:right">{qty}<span style="font-size:8.1px">{unit}</span></td>
										<td style="text-align:right">{rate}</td>
										<?php if(!$all_zero) { ?><td style="text-align:right">{discAmount}</td><?php } ?>
										<td style="text-align:right">{taxableAmount}</td>
									</tr>
								{/details}
								<tr class="label">
									<?php if($all_zero) { ?><td colspan="1" style="border-left:1px solid #b7b7b7;border-bottom:none !important;"></td><?php } ?>
									<?php if(!$all_zero) { ?><td colspan="2" style="border-left:1px solid #b7b7b7;border-bottom:none !important;"></td><?php } ?>
									<td class="label-13" colspan="4" style="text-align:right;"><b><?php echo lang("Sub Total"); ?></B></td>
									<td  class="label-13" style="text-align:right"><b>{taxableAmount}</b></td>
								</tr>
								<?php if (!empty($charges)) { ?>
									{charges}
										<tr class="label">
											<?php if($all_zero) { ?><td colspan="1" style="border-left:1px solid #b7b7b7;border-bottom:none !important;"></td><?php } ?>
											<?php if(!$all_zero) { ?><td colspan="2" style="border-left:1px solid #b7b7b7;border-bottom:none !important;"></td><?php } ?>
											<td style="border-left:1px solid #e5e5e5;" colspan="3">{itemName}</td>
											<td>{taxName}</td>
											<td style="text-align:right">{taxableAmount}</td>
										</tr>
									{/charges}
								<?php } ?>
								<?php if (!empty($tax)) { ?>
									{tax}
										<tr class="label-13">
											<?php if($all_zero) { ?><td colspan="1" style="border-left:1px solid #b7b7b7;border-bottom:none !important;"></td><?php } ?>
											<?php if(!$all_zero) { ?><td colspan="2" style="border-bottom:none !important;border-left:1px solid #b7b7b7;"></td><?php } ?>										<?php if(empty($isReverse)) { ?>
											<td colspan="4" style="text-align:right;border-bottom:none !important;" class="label-13">{taxTypeCode} @ <b>{taxRate}%</b> on {taxableAmt}</td>
											<td style="text-align:right;border-bottom:none !important;"><b>{taxValue}</b></td>
											<?php } ?>
											<?php if(!empty($isReverse)) { ?>
											<td colspan="4" style="text-align:right;border-left:none ! important;border-bottom:none !important;background:#FFFFE0;color:black;" class="label-13">{taxTypeCode} @ <b>{taxRate}%</b> on {taxableAmt}</td>
											<td style="text-align:right;border-bottom:none !important;background:#FFFFE0;color:black"><b>{taxValue}</b></td>
											<?php } ?>
										
										</tr>
									{/tax}
								<?php } ?>
								<?php if(!empty($roundAmount)) { ?>
									<tr class="label">
										<?php if($all_zero) { ?><td colspan="1" style="border-left:1px solid #b7b7b7;border-bottom:none !important;"></td><?php } ?>
										<?php if(!$all_zero) { ?><td colspan="2" style="border-left:1px solid #b7b7b7;border-bottom:none !important;"></td><?php } ?>
										<td class="label-13" colspan="4" style="text-align:right;"><?php echo lang("Round Off"); ?> </td>
										<td class="label-13" style="text-align:right"><b>{roundAmount}</b></td>
									</tr>
								<?php } ?>
								
								<?php if(!empty($tdsPercentage) && $tdsPercentage!=0) { ?>
									<tr class="label">
										<?php if($all_zero) { ?><td colspan="1" style="border-left:1px solid #b7b7b7;border-bottom:none !important;"></td><?php } ?>
										<?php if(!$all_zero) { ?><td colspan="2" style="border-left:1px solid #b7b7b7;border-bottom:none !important;"></td><?php } ?>
										<td class="label-13" colspan="4" style="text-align:right;">TDS @ <b>{tdsPercentage}%</b></td>
										<td class="label-13" style="text-align:right"><b>{tdsAmount}</b></td>
									</tr>
								<?php } ?>
								
								<?php if (!empty($trans_payment)) { ?>
									{trans_payment}
										<tr class="label">
											<?php if($all_zero) { ?><td colspan="1" style="border-left:1px solid #b7b7b7;border-bottom:none !important;"></td><?php } ?>
											<?php if(!$all_zero) { ?><td colspan="2" style="border-left:1px solid #b7b7b7;border-bottom:none !important;"></td><?php } ?>
											<td colspan="4" style="text-align:right;">{payment_type} #{tNo}</td>
											<td style="text-align:right;"><b>{allotAmt}</b></td>
										</tr>
									{/trans_payment}
								<?php } ?>
								<tr class="label">
									<?php if($all_zero) { ?><td colspan="1" style="border-left:1px solid #b7b7b7;"></td><?php } ?>
									<?php if(!$all_zero) { ?><td colspan="2" style="border-left:1px solid #b7b7b7;"></td><?php } ?>
									<td class="label-13" colspan="4" style="text-align:right;"><b>Total</b></td>
									<td style="text-align:right;font-size:15px"><b>{totAmount}</b></td>
								</tr>		
								<?php if (!empty($dueAmount)) { ?>
									<tr class="label">
										<?php if($all_zero) { ?><td colspan="1" style="border-left:1px solid #b7b7b7;border-bottom:1px solid #b7b7b7;"></td><?php } ?>
										<?php if(!$all_zero) { ?><td colspan="2" style="border-left:1px solid #b7b7b7;border-bottom:1px solid #b7b7b7;"></td><?php } ?>
										<td class="label-13" colspan="4" style="text-align:right;"><?php echo $dueAmount_text; ?> </td>
										<td class="label-13" style="text-align:right"><b>{dueAmount}</b></td>
									</tr>	
								<?php } ?>	
							</tbody>
						</table>
					<!-- </div> -->
				</td>
			</tr>
			<tr>
				<td valign="bottom" colspan="3"><span><b></b></span><br>
					<span style="margin-left:30px;"></span>
				 </td>
			</tr>
			<tr>
				<td valign="bottom" colspan="3"><span><b>Amount (in words)</b></span><br>
					<span style="margin-left:30px;"><?php if($paise) { echo $amt_str . "Rupees and"."&nbsp;" . $paise.'&nbsp;'."only"; } 
						  else {echo $amt_str. "Rupees only";
					}?></span>
				 </td>
			</tr>
		</table>
	</div>
	<div class="bank" style="margin-top:100px;">
		<?php if ($bankAccId && $accType!='R') {?>
			<div class="text label-13">Company's Bank Details</div>
		<?php } ?>
		<table align="left" border="0" cellspacing="0" cellpadding="0" style="padding-left: 10px;padding-top: 5px;width:100%;" >
			<?php if ($bankAccId && $accType!='R') {?>
				<tr class="label-12">
					<td style="width:11.5%">Account No</td>
					<td style="width:23.5%"> : <b>  {accNumber}</b></td>
					<td style="width:11.5%">Bank Name</td>
					<td style="width:23%"> : <b>  {bankName}</b></td>
				</tr>
			<?php } ?>
			<tr class="label-12">
				<?php if ($bankAccId && $accType!='R') {?>
					<td style="width:11.5%">IFSC Code</td>
					<td> : <b>  {ifscRouteCode}</b></td>
					<td style="width:11.5%">Branch</td>
					<td style="width:33%"> : <b>  {branchName}</b></td>
					<td></td>
				<?php } ?>
				<?php if (!$bankAccId || $accType=='R') {?>
					<td style="width:72%"></td>
				<?php } ?>
				<td align="right" style="text-align:right;" class="label-13">Authorized Signature</td>
			</tr>
		</table>
	</div>
	<div class="notes" style="margin-top:70px;">
		<?php if ($notes) {?>
			<div class="text label-13"><?php echo lang("Notes");?></div>
			<div class="label-12" style="padding-left: 10px;padding-top: 5px;padding-bottom: 12px;width: 100%;">{notes}</div>
		<?php } ?>
		<div class="text label-13"><?php echo lang("Terms");?></div>
		<div class="label-12" style="padding-left: 10px;padding-top: 5px;width: 100%;">{terms} <?php echo lang("E & O.E");?>.</div>
	</div>
	<page_footer>
	</page_footer>

<style>
* {
	font-family: Arial,Helvetica,sans-serif;
	font-size: 13px;
	line-height:1.5;
}
page {
	width: 100%;
	display: inline-block;
	height: auto;
}
.trans
{
	color:#666666;
	font-size:13px;
	min-height: 30%;
	margin: 0px;
}
table td {
	color:#000000;
}

.label {
	/*color:#000000;
	font-weight:bold;*/
	font-size:13px;
}
.text {
	color:grey;
	font-weight:bold;
	font-size:13px;
}

table td h4, table td h5 {
	color:#000000;
	margin-top:0px;
	margin-bottom:5px;
}
table th{
	font-weight:normal;
}
.customer {
	width:40%; 
	height: 15px;
	background:#BADA86;
	color:black;
	font-weight: bold;
	padding: 10px 10px 7px 7px;
	text-align: center;
	margin-left: -10px;
}
.label-15 {
	font-size:15px;
}
.label-13 {
	font-size:13px;
}
.label-12 {
	font-size:12px;
}
table.middlecol tr th, table.middlecol tr td {
	border-right:1px solid #b7b7b7;
	border-bottom:1px solid #b7b7b7;
}
.middlecol{
	color:#666666;
	width: 100%;
	height: 60%;
}
.middlecol th{
	background:#BADA86;
	text-align:center;
	color:black;
	font-weight:bold;
	vertical-align: middle;
	padding: 5px;
}
.middlecol tr.odd{
	background:#EAEAEA;
}
.middlecol tr.even{
	background:#FFFFFF;
}
.middlecol td{
	padding-right:10px;
	padding: 8px;
}
.tax_disable{
	display:none;
}
.notes{
	font-size: 16px;
	color: #000000;
    width: 100%;
}


</style>
</page>

