<script>
function printPage(){
window.print();
}
</script>
<div id="exportPrintTable">
<div class="wrapper">
	<p><a href="<?php echo $this->webroot; ?>"><img src="<?php echo CDN_URL; ?><?php echo __('LBL_LOGO_PDF');?>" width="270" height="72"  alt=""/></a> </p>
    <div class="description">
        <p><strong> ExpenseCount "<?php echo $expense["title"];?>"</strong></p>
        <?php if(isset($expense["description"])){ ?>
        <p><?php echo $expense["description"];?></p>
        <?php } ?>
        <p><?php echo __("LBL_CREATED_BY"); ?> <?php echo $createdBy;?>, <?php echo __('LBL_ON'); ?> <?php echo $createdDate;?></p>
    </div>
    <div class="print">
		<?php echo __("LBL_PRINTED_BY"); ?> <?php echo $printedBy;?> <span><?php echo date("d/m/Y - H:i");?></span>
    </div>
    <p><?php echo $printedBy;?> <?php echo __("LBL_SHOULD_VERIFY"); ?></p>
    
    <table class="printTable table" id="exportTable">
		<thead>
			<tr>
				<th><?php echo __("LBL_WHO_PAID"); ?></th>
				<th><?php echo __("LBL_HOW_MUCH"); ?>?</th>
				<th><?php echo __("LBL_FOR_WHAT_REASONS"); ?></th>
				<th><?php echo __("LBL_WHEN"); ?></th>
				<th><?php echo __("LBL_INVOLVES"); ?></th>
				<th ><?php echo __("LBL_FOR"); ?> <?php echo $printedBy;?>?</th>
			</tr>
		</thead>
        <tbody>
        <?php
        $total_expense = 0;
        $personal_total_expense = 0;
	    foreach($expenseList as $key=>$value){
	    ?>
	    	<tr>
	        	<td><?php echo $value["paidBy"];?></td>
	            <td><?php
	            $total_expense = $total_expense + $value["amount"];
	            echo $value["amount"];?><?php echo " ".$expense["currency"];?></td>
	            <td><?php echo $value["expenseName"];?></td>
	            <td><?php echo $value["expenseDate"];?></td>
	            <td><?php echo $value["involves"];?></td>
	            <td><?php
	            $personal_total_expense = $personal_total_expense + $value["forYou"];
	            echo $value["forYou"];?><?php echo " ".$expense["currency"];?></td>
        	</tr>
	        
	    <?php
	    }
	    ?>
		</tbody>
		<tfoot>
			<tr style="background: #fff;">
				<td align="right" style="font-weight: bold;border: 0px;"><?php echo __("LBL_TOTAL"); ?> : </td>
				<td align="left" style="border: 0px;"><?php echo $total_expense." ".$expense["currency"]; ?></td>
				<td style="border: 0px;"></td>
				<td style="border: 0px;"></td>
				<td align="right" style="font-weight: bold;border: 0px;"><?php echo __("LBL_TOTAL"); ?> : </td>
				<td align="left" style="border: 0px;"><?php echo number_format($personal_total_expense, 2)." ".$expense["currency"]; ?></td>
			</tr>
		</tfoot>
    </table>
    
    <div class="description">
    	<p><strong><u>ExpenseCount <?php echo __("LBL_SOLUTION"); ?>:</u></strong></p>
     	<table style="font-size:12px;">
    	<?php
    		
    		foreach($balanceArray as $key=>$value){
    		 if(trim($value) != ""){
    		   $valueArray = explode("|",$value);
    		
    		?>
    		 <tr><td><b><?php echo $valueArray[0];?></b> <?php echo __("LBL_SHOULD_PAY"); ?> <b><?php echo $valueArray[1];?></b></td><td>&nbsp;&nbsp;&nbsp; <?php echo $valueArray[2];?><?php echo " ".$expense["currency"];?></td></p></tr>
    		
    		
    		<?php
    		}
    	  }
    	
    	?>
	 </table>
    </div>
    <div class="footerText"><?php echo __('LBL_ADD_MODIFY_DELETE_MEAL_NECESSARY'); ?><br/>
		<?php echo __("LBL_CLICK"); ?> <a href="#" style="cursor:pointer" onclick="printPage()"> <?php echo __("LBL_HERE"); ?></a> <?php echo __("LBL_TO_PRINT_THE_PAGE"); ?>.</div>
	<div class="footer-pdf-print-link hidden-print">
		<a href="#" onclick="printPage()" class="btn btn-info"><?php echo __("LBL_PRINT"); ?></a>
		<form action="<?php echo $this->Html->url(array('controller'=>'Expense','action'=>'generatePdf'));?>" class="form-inline" method="post" id="generatePdf">
			<input type="hidden" name="whole_content" id="wholeContent">
			<div class="form-group">
				<button type="submit" class="btn btn-info" id="generatePdfBtn"><?php echo __("LBL_DOWNLOAD"); ?></button>
			</div>
		</form>
	</div>
</div>
</div>

<script>
    $(document).ready(function(){
        $('#exportTable').DataTable({
            "paging":   false,
            "searching": false,
            "info":     false
        });
        $("#generatePdfBtn").on('click', function () {
            var Content = $('#exportPrintTable').html();
            var ContentWrap = "<!doctype html><html><body>"+Content+"</body></html>";
            var currentHtml = $("#wholeContent").val(ContentWrap);
            // alert($("#wholeContent").val());
            $("form#generatePdf").submit();
        })
    });
</script>