<?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;">Invoice/Cashbill - 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;">
			 			<span class="title_small">No.</span>
			 		</th>
			 		<th class="" style="white-space: nowrap; text-align: center; padding: 2px 10px; width: 50px;">
			 			<span class="title_small">Ref. No.</span>
			 		</th>
			 		<th class="" style="text-align: center; padding: 2px 10px; width: 20px;">
			 			<span class="title_small">Date</span>
			 		</th>
			 		<th class="" style="text-align: left; padding: 2px 10px; width: 50px;">
			 			<span class="title_small">Debtor</span>
			 		</th>
			 		<th class="" style="text-align: left; padding: 2px 10px; width: 50px;">
			 			<span class="title_small">Item</span>
			 		</th>
			 		<th class="" style="text-align: left; padding: 2px 10px; width: 150px;">
			 			<span class="title_small">Description</span>
			 		</th>
			 		<th class="" style="text-align: right; padding: 2px 10px; width: 50px;">
			 			<span class="title_small">Inch</span>
			 		</th>
			 		<th class="" style="text-align: right; padding: 2px 10px; width: 50px;">
			 			<span class="title_small">Pcs</span>
			 		</th>
			 		<th class="" style="text-align: right; padding: 2px 10px; width: 50px;">
			 			<span class="title_small">Qty</span>
			 		</th>
			 		<th class="" style="text-align: left; padding: 2px 10px; width: 50px;">
			 			<span class="title_small">Unit</span>
			 		</th>
			 		<th class="" style="text-align: right; padding: 2px 10px; width: 50px;">
			 			<span class="title_small">Price Per<br/> Piece</span>
			 		</th>
			 		<th class="" style="text-align: right; padding: 2px 10px; width: 50px;">
			 			<span class="title_small">Total/Labour<br/>Charges</span>
			 		</th>
			 		<th class="" style="text-align: right; padding: 2px 10px; width: 50px;">
			 			<span class="title_small">TaxAmt</span>
			 		</th>
			 		<th class="" style="text-align: right; padding: 2px 10px; width: 50px;">
			 			<span class="title_small">Total</span>
			 		</th>
			 	</tr>
			</thead>
			<tbody>
				<?php $no=1; $total_labour = 0; $total_gst = 0; $total_amt = 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: right; padding: 2px 10px;"><?php echo $no;?></td>
							<td class="" style="white-space: nowrap; text-align: center; padding: 2px 10px; font-weight: bold;"><?php echo $x->REFNO;?></td>
							<td class="" style="white-space: nowrap; text-align: center; padding: 2px 10px;"><?php echo date("Y-m-d", strtotime($x->DATE));?></td>
							<td class="" style="white-space: nowrap; text-align: left; padding: 2px 10px;"><?php echo $x->DEBTOR;?></td>
							<td class="" style="white-space: nowrap; text-align: left; padding: 2px 10px;"><?php echo $x->INVITEM_ITEM;?></td>
							<td class="" style="white-space: nowrap; text-align: left; padding: 2px 10px;"><?php echo $x->INVITEM_DESCRIPT;?></td>
							<td class="" style="white-space: nowrap; text-align: right; padding: 2px 10px;"><?php echo $x->INVITEM_INCH;?></td>
							<td class="" style="white-space: nowrap; text-align: right; padding: 2px 10px;"><?php echo $x->INVITEM_PCS;?></td>
							<td class="" style="white-space: nowrap; text-align: right; padding: 2px 10px;"><?php echo $x->INVITEM_QTY;?></td>
							<td class="" style="white-space: nowrap; text-align: left; padding: 2px 10px;"><?php echo $x->INVITEM_UNIT;?></td>
							<td class="" style="white-space: nowrap; text-align: right; padding: 2px 10px;"><?php echo $x->INVITEM_PRICE;?></td>
							<td class="" style="white-space: nowrap; text-align: right; padding: 2px 10px;"><?php echo $x->INVITEM_LABOUR;?></td>
							<td class="" style="white-space: nowrap; text-align: right; padding: 2px 10px;"><?php echo $x->INVITEM_GST;?></td>
							<td class="" style="white-space: nowrap; text-align: right; padding: 2px 10px;"><?php echo $x->INVITEM_AMT;?></td>
						</tr>
					<?php $no++;?>
					<?php 
						$total_labour += $x->INVITEM_LABOUR;
						$total_gst += $x->INVITEM_GST;
						$total_amt += $x->INVITEM_AMT;
					;?>
					<?php endforeach;?>
				<?php endforeach;?>
			</tbody>
			<thead>
				<tr>
					<th colspan="11" style="text-align: right; padding: 2px 10px;">Sub Total</th>
					<th style="text-align: right; padding: 2px 10px;"><?php echo number_format((float)$total_labour, 2, '.', '');?></th>
					<th style="text-align: right; padding: 2px 10px;"><?php echo number_format((float)$total_gst, 2, '.', '');?></th>
					<th style="text-align: right; padding: 2px 10px;"><?php echo number_format((float)$total_amt, 2, '.', '');?></th>
				</tr>
			</thead>
			<thead>
			 	<tr style="" class="report_table_content">
			 		<th class="" colspan="2" 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">Gold</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="" colspan="2" style="text-align: right; padding: 2px 10px; width: 20px;">
			 			<span class="title_small">Pure Gold (gm)</span>
			 		</th>
			 		<th class="" colspan="2" style="text-align: right; padding: 2px 10px; width: 50px;">
			 			<span class="title_small">Trade In Gold (gm)</span>
			 		</th>
			 		<th class="" colspan="2" style="text-align: right; padding: 2px 10px; width: 50px;">
			 			<span class="title_small">Total (Gold Rate)</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">Gold Price</span>
			 		</th>
			 		<th class="" style="text-align: right; padding: 2px 10px; width: 50px;">
			 			<span class="title_small">TaxAmt</span>
			 		</th>
			 		<th class="" style="text-align: right; padding: 2px 10px; width: 50px;">
			 			<span class="title_small">Total</span>
			 		</th>
			 	</tr>
			</thead>
			<tbody>
				<tr class="tr_data" style="font-size: 12px;">
					<td class="" colspan="2" style="white-space: nowrap; text-align: center; padding: 2px 10px;"></td>
					<td class="" style="white-space: nowrap; text-align: center; padding: 2px 10px;"><?php echo $x->GOLD;?></td>
					<td class="" style="white-space: nowrap; text-align: right; padding: 2px 10px;"><?php echo $x->WEIGHT;?></td>
					<td class="" colspan="2" style="white-space: nowrap; text-align: right; padding: 2px 10px;"><?php echo $x->PUREGOLD;?></td>
					<td class="" colspan="2" style="white-space: nowrap; text-align: right; padding: 2px 10px;"><?php echo $x->TRADEIN_W;?></td>
					<td class="" colspan="2" style="white-space: nowrap; text-align: right; padding: 2px 10px;"><?php echo $x->TOTAL_RATE;?></td>
					<td class="" style="white-space: nowrap; text-align: right; padding: 2px 10px;"><?php echo $x->RATE;?></td>
					<td class="" style="white-space: nowrap; text-align: right; padding: 2px 10px;"><?php echo $x->GOLDPRICE;?></td>
					<td class="" style="white-space: nowrap; text-align: right; padding: 2px 10px;"><?php echo $x->GST;?></td>
					<td class="" style="white-space: nowrap; text-align: right; padding: 2px 10px;"><?php echo (($x->GOLDPRICE)+($x->GST));?></td>
				</tr>
			</tbody>
			<thead>
				<tr>
					<th colspan="13" style="text-align: right; padding: 2px 10px;">Total</th>
					<th style="text-align: right; padding: 2px 10px;"><?php echo $x->AMOUNT;?></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>