<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="<?php echo base_url()?>img/salihin_logo.png">
<title>Account Balance Summary For <?php echo $period.'dd'.$year ?></title>
<link rel="stylesheet" href="<?php echo base_url()?>css/stylesheets.css" type="text/css" />
<style media="print" type="text/css">
	/*body{FONT-SIZE: 14px;FONT-FAMILY: Arial;COLOR: #000000}*/
	.printButton { display: none; }
</style>
<script language="javascript" type="text/javascript">	
function do_print(){
	window.print();
}
function do_printexcel(){
	var url = "<?php echo base_url();?>glreports/accountBalanceSummary_excel/<?php echo $selyear?>/<?php echo $selperfrom?>/<?php echo $selper?>/<?php echo $acctNo?>";
	window.location.href = url;
}

</script>
<style>        
    .tots {
        border-top:1px solid black;
        border-bottom:double black;
    }
    .sep {
        border-bottom:1px solid black;
    }
    .sep {
        border-top:1px solid black;
    }
    .sep td {
        padding-bottom:5px;
    }
</style>
</head>
<div class="printButton" align="center">
<table width="100%" border="0" align="center" cellpadding="1" cellspacing="0">
    <tr>
        <td align="center" colspan="2">
        	<?php 
			$js = 'onClick="do_print()" class="btn-icon btn-success-form Print" title="Print"';
			echo form_button('Print','<span class="i-printer">',$js);?>&nbsp;&nbsp; <?php
			$js = 'onClick="do_printexcel()" class="btn-icon btn-warning-form EXCEL" title="Download"';
			echo form_button('EXCEL','<span class="i-download">',$js);?>&nbsp;&nbsp; <?php
			$js = 'onClick="javascript:window.close();" class="btn-icon btn-danger-form Close" title="Close"';
			echo form_button('Close','<span class="i-switch">',$js);?>
        </td>
    </tr>
</table>
</div>
<div>
	<table border="0" cellpadding="1" cellspacing="0" width="100%">
		<thead>
                    <tr>
                    	<td colspan="8"><?php $this->load->view('layouts/report/header2'); ?></td>
                    </tr>
        <?php
			if($acctNo<>''){
				if($datatbls){
					foreach($datatbls as $datatbl){ 
						echo"<tr>
							<th colspan='8' class='tal'>".substr($datatbl->acctCode,0, 4).'-'.substr($datatbl->acctCode,4, 3).'-'.substr($datatbl->acctCode,7, 2) ?>&nbsp;&nbsp;&nbsp;&nbsp;
						<?php echo $datatbl->acctName."</th>
						</tr>";
					}
				}
			}
		?>
		<tr class="sep">
			<th class="tac">#</th>
			<th><?php echo $this->lang->line('date') ?></th>
      <th><?php echo $this->lang->line('journalno') ?></th>
			<th><?php echo $this->lang->line('refNo') ?></th>
			<th><?php echo $this->lang->line('description') ?></th>
			<th><?php echo $this->lang->line('monthdebit') ?></th>
			<th><?php echo $this->lang->line('monthcredit') ?></th>                
			<th><?php echo $this->lang->line('balance') ?></th>                
		</tr>
		</thead>
		<tbody>
	<?php $bil = 0; 
		$totalcredit = 0;
		$totaldebit = 0;
		
		if($datatbls){
			foreach($datatbls as $datatbl):
					$bil++?>
            		<tr>
                		<td align="center" bordercolor="#000000"><?php echo $bil; ?></td>
						<?php 
							if($acctNo==''){
								echo "<td colspan='5'>&nbsp;&nbsp;".substr($datatbl->acctCode,0, 4).'-'.substr($datatbl->acctCode,4, 3).'-'.substr($datatbl->acctCode,7, 2)."&nbsp;&nbsp;&nbsp;&nbsp;".$datatbl->acctName; 
						"</td>";}
						?>
                	</tr>
                 	<?php 
			        if($datatbl->acctTypeID != '3' && $datatbl->acctTypeID != '4'){
                  if($datatbl->acctCode == '120000000'){
                      $openbal = ($currRetain)*-1;
                  }else{
                      $openbal = ($datatbl->lastyeardebit+$datatbl->oDebit) - ($datatbl->lastyearcredit+$datatbl->oCredit);
                  }
              }else{                                                
                  $openbal = ($datatbl->lastyeardebit+$datatbl->oDebitPNL) - ($datatbl->lastyearcredit+$datatbl->oCreditPNL);
              }

							$monthdebit = 0;
							$monthcredit = 0;
						if($datatbls1){ ?>
                        <tr>
                        	<td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td>&nbsp;&nbsp;<?php echo $this->lang->line('openbalance') ?></td>
                            <td></td>
                            <td></td>
                            <td class="tar">&nbsp;&nbsp;<?php echo number_format($openbal,2) ?></td>
                        </tr>
										<?php
										$controlHead = 0; 
										$monthdebit = 0;
										$monthcredit = 0;?>
						<?php
							$controlHead = 0; 
							foreach($datatbls1 as $row):
								if($row->acctCode == $datatbl->ID){
									if($controlHead == 0){ ?>
												<?php 
												$controlHead = 1;
												} 
												$monthcredit = $monthcredit - $row->amount_cr;
												$monthdebit = $monthdebit + $row->amount_dr;
												$openbal = $openbal + $row->amount_dr;
												$openbal = $openbal - $row->amount_cr;
												?>
                                    <tr>
                                       	<td></td>
                                       	<td>&nbsp;&nbsp;<?php echo date("d-m-Y", strtotime($row->effective_date)) ?></td>
                                       	<td class="tac" width="10%"><?php echo $row->journalID ?></td>
                                        <td>&nbsp;&nbsp;<?php echo $row->refNo ?></td>
                                       	<td>&nbsp;&nbsp;<?php echo $row->description ?></td>
                                       	<td class="tar" width="10%"><?php echo number_format($row->amount_dr,2) ?>&nbsp;&nbsp;</td>
                                       	<td class="tar" width="10%"><?php echo number_format($row->amount_cr,2) ?>&nbsp;&nbsp;</td>
                                       	<td class="tar" width="10%"><?php echo number_format($openbal,2) ?></td>
                                    </tr>
                               <?php		}
							endforeach; ?>
                            	<tr>
                                   	<td></td>
                                   	<td></td>
                                    <td></td>
                                   	<td></td>
                                	   <td>&nbsp;&nbsp;<?php echo $this->lang->line('total') ?></td>
                                   	<td class="tar sep"><?php echo number_format($monthdebit,2) ?>&nbsp;&nbsp;</td>
                                   	<td class="tar sep"><?php echo number_format(abs($monthcredit),2) ?>&nbsp;&nbsp;</td>
                                   	<td class="tar">&nbsp;&nbsp;</td>
                                 </tr>
					  <?php  
						}else{ ?>
                        	<tr>
                            	<td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td>&nbsp;&nbsp;<?php echo $this->lang->line('openbalance') ?></td>
                                <td class="tar">&nbsp;&nbsp;</td>
                                <td class="tar">&nbsp;&nbsp;</td>
                                <td class="tar">&nbsp;&nbsp;<?php echo number_format($openbal,2) ?></td>
                            </tr> 
                        	<tr>
                            	<td></td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td>&nbsp;&nbsp;<?php echo $this->lang->line('total') ?></td>
                                <td class="tar sep"><?php echo number_format($monthdebit,2) ?>&nbsp;&nbsp;</td>
                                <td class="tar sep"><?php echo number_format($monthcredit,2) ?>&nbsp;&nbsp;</td>
                                <td class="tar">&nbsp;&nbsp;</td>
                            </tr>
                  <?php }
            	endforeach; 
			}
	?>
                        	<!--<tr>
                            	<td></td>
                                <td></td>
                                <td></td>
                                <td>&nbsp;&nbsp;<?php //echo $this->lang->line('total') ?></td>
                                <td class="tar tots"><?php //echo number_format($totaldebit,2) ?>&nbsp;&nbsp;</td>
                                <td class="tar tots"><?php //echo number_format($totalcredit*-1,2) ?>&nbsp;&nbsp;</td>
                                <td></td>
                            </tr>-->
		</tbody>
	</table>                                         
</div>
<div style="page-break-after:always"></div>
</html>
