<?php $ci = get_instance();?>
<div id="div_print" style="page-break-after: always;">
<style type="text/css">
	.img-valign {
	  vertical-align: middle;
	  margin-bottom: 0.75em;
	}
	.title{
		font-size: 20px;
		font-weight: bold;
		text-align: center;
	}
	.chinese{
		font-family: "KaiTi";
		font-size: 24px;
		font-weight: bold;
		text-align: center;
	}
	.chinese_small{
		font-family: "KaiTi";
		font-size: 14px;
		text-align: center;
	}
	.title_small{
		font-size: 12px;
		text-align: center;
	}
	.small{
		font-size: 10px;
	}

</style>

<div class="title">
	<table style="width:100%; margin-left: auto; margin-right: auto; font-size: 20px;" align="center" border="0">
		<tr>
		    <td style="width: 25%;"><center><img class="img-valign" src="<?php echo base_url("assets/img/logo.png");?>" style="width: 80px; padding-right: 0px; padding-top: 10px;">
		    </td>
	    	<td style="padding-left: 0px;"><center><span class="chinese"><?php echo $company->CNAME;?></span><br/><span class="title"><?php echo $ci->fm->decrypt($this->company_name);?></span>
		    </center></td>
		    <td style="text-align: right; font-weight: bold; width: 25%;"></td>
	  	</tr>
	</table>
	<table style="font-size: 12px; width: 100%;" border="0">
		<tr>
			<td class="" style="white-space: nowrap; text-align: left;">Printed By: <?php echo "[".$userid."] ".$username;?></td>
			<td></td>
		</tr>
		<tr>
			<td colspan="2" style="white-space: nowrap; text-align: left;">Print Date: <?php echo date("d M Y h:i A");?></td>
		</tr>
		<tr>
			<td style="text-align: left;">
				<?php if(isset($Date)) echo "Date: ".$Date;?><?php if ($condition1 != "") echo "<br/>";?>
				<?php if ($condition1 != "") echo $condition1;?>
			</td>
			<td style="text-align: right; font-weight: bold; font-size: 18px;">Trade In - Details Report</td>
		</tr>
	</table>
</div>
<?php if(count($list) > 0):?>
<?php foreach($list as $refno=>$r):?>
<div class="report_table_content print_font border">
	<div style="padding-bottom: 30px; padding-top: 10px;">
		<table class="" style="width: 100%;" border="1">
			<thead>
			 	<tr style="" class="report_table_content">
			 		<th class="" style="white-space: nowrap; text-align: right; padding: 2px 10px; width: 2px;">
			 		</th>
			 		<th class="" style="white-space: nowrap; text-align: center; padding: 2px 10px; width: 2px;">
			 			<span class="title_small">Invoice<br/>Ref.No</span>
			 		</th>
			 		<th class="" style="white-space: nowrap; text-align: center; padding: 2px 10px; width: 2px;">
			 			<span class="title_small">Trade In<br/>Ref.No</span>
			 		</th>
			 		<th class="" style="white-space: nowrap; text-align: center; padding: 2px 10px; width: 2px;">
			 			<span class="title_small">Gold</span>
			 		</th>
			 		<th class="" style="white-space: nowrap; text-align: center; padding: 2px 10px; width: 2px;">
			 			<span class="title_small">Description</span>
			 		</th>
			 		<th class="" style="white-space: nowrap; text-align: right; padding: 2px 10px; width: 50px;">
			 			<span class="title_small">Weight (gm)</span>
			 		</th>
			 		<th class="" style="text-align: right; padding: 2px 10px; width: 50px;">
			 			<span class="title_small">Rate</span>
			 		</th>
			 		<th class="" style="text-align: right; padding: 2px 10px; width: 50px;">
			 			<span class="title_small">Total Weight</span>
			 		</th>
			 	</tr>
			</thead>
			<tbody>
				<?php $no=1; $total_weight = 0;?>
				<?php foreach($r as $l):?>
					<?php foreach($l as $x):?>
					<tr class="tr_data" style="font-size: 12px;">
						<td class="" style="white-space: nowrap; text-align: center; padding: 2px 10px;"><?php echo $no;?></td>
						<td class="" style="white-space: nowrap; text-align: center; padding: 2px 10px;"><?php echo $x->RECEIPT;?></td>
						<td class="" style="white-space: nowrap; text-align: center; padding: 2px 10px;"><?php echo $x->REFNO;?></td>
						<td class="" style="white-space: nowrap; text-align: center; padding: 2px 10px;"><?php echo $x->TRADEITEM_GOLD;?></td>
						<td class="" style="white-space: nowrap; text-align: center; padding: 2px 10px;"><?php echo $x->TRADEITEM_DESCRIPT;?></td>
						<td class="" style="white-space: nowrap; text-align: right; padding: 2px 10px;"><?php echo $x->TRADEITEM_WEIGHT;?></td>
						<td class="" style="white-space: nowrap; text-align: right; padding: 2px 10px;"><?php echo $x->TRADEITEM_RATE;?></td>
						<td class="" style="white-space: nowrap; text-align: right; padding: 2px 10px;"><?php echo $x->TRADEITEM_GOLDPRICE;?></td>
					</tr>
					<?php $no++;?>
					<?php 
						$total_weight += $x->TRADEITEM_GOLDPRICE;
					;?>
					<?php endforeach;?>
				<?php endforeach;?>
			</tbody>
			<thead>
				<tr>
					<th colspan="7" style="text-align: right; padding: 2px 10px;">Total</th>
					<th style="text-align: right; padding: 2px 10px;"><?php echo number_format((float)$total_weight, 2, '.', '');?></th>
				</tr>
			</thead>
		</table>
	</div>
</div>
<?php endforeach;?>
<?php else:?>
<?php endif;?>
</div>

<script>
	$(document).ready(function(){
		<?php if(isset($list)):?>
		$(".btn_print").show();
		$(".btn_excel").show();	
		<?php endif;?>	
	});

</script>