<!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" />
<title><?php echo $this->lang->line('statFinPos')?> <?php echo isset($year)?'-'.$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/financialPosition_excel/<?php echo $selyear?>/<?php echo $selperiod?>";
	window.location.href = url;
}
/*
function do_printexcel(){
	var url = "<?php echo base_url()?>glreports/accountBalanceSummary_print";
		url = url + "<?php echo $add_month?>/EXCEL";
		window.location.href = url;
} */
</script>
<style>        
    .tots {
        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="4"><?php $this->load->view('layouts/report/header2'); ?></td>
                    </tr>
                    <tr>
                    	<td colspan="4" class="tac"><h4><?php echo $this->lang->line('asat').' : '.date("d-m-Y", strtotime($asat[0]->endDate)) ?></h4></td>
                    </tr>
                    <tr>
                    <?php $lastyear = $selyear - 1;?>
                        <th class="tal"><h4><?php //echo $this->lang->line('description') ?></h4></th>
                        <th width="20%" class="tar"><h4><?php echo $this->lang->line('thisyear').' ('.$selyear.')' ?></h4></th>
                        <th width="10px">&nbsp;</th>
                        <th width="20%" class="tar"><h4><?php echo $this->lang->line('lastyear').' (' . $lastyear . ')' ?></h4></th>
            		</tr>
        			</thead>
       				 <tbody>
			<?php 
				if($accountGroup){
				foreach($accountGroup as $datatbl):
							$total_thisyear = 0;
							$total_lastyear = 0;
                            $thisyear_amount = 0;
                            $lastyear_amount = 0;
                            $tyear_amount = 0;
                            $lyear_amount = 0;
				?>
  			<?php if ($datatbl->title == 1) {?>
           	<tr>
                	<td colspan="4"><h5><?php echo $this->lang->line($datatbl->acctGroupName)?></h5></td>
                </tr>
                <?php } ?>
                	<?php foreach($groupdetails as $rowdet):
									$rowdet_thisyeartotal = 0;
									$rowdet_lastyeartotal = 0;
							if($rowdet->parentID == $datatbl->ID){?>
  						<?php if ($rowdet->title == 1) {?>
            					<tr>
                					<td colspan="4">&nbsp;&nbsp;&nbsp;<strong><?php echo $this->lang->line($rowdet->acctGroupName)?></strong></td>
                				</tr>
                <?php } ?>
                				<?php foreach($groupdetails as $rowdet1):
									$rowdet1_thisyeartotal = 0;
									$rowdet1_lastyeartotal = 0;
										if($rowdet1->parentID == $rowdet->ID){?>
  											<?php if ($rowdet1->title == 1) {?>
            								<tr>
                								<td colspan="4">&nbsp;&nbsp;&nbsp;<strong><?php echo $this->lang->line($rowdet1->acctGroupName)?></strong></td>
                							</tr>
                <?php } ?>
                				<?php if($accountdetails){ ?>
                				<?php foreach($accountdetails as $row):
										if($row->acctGroupID == $rowdet1->ID){?>
                                       <?php	if($row->lastyeardebit == 0 && $row->lastyearcredit == 0 && $row->currentyeardebit == 0 && $row->currentyearcredit == 0){ }else{ ?>
                                       <?php $tyear_amount = ($row->lastyeardebit-$row->lastyearcredit)+($row->currentyeardebit - $row->currentyearcredit);?>
                                       <?php $lyear_amount = $row->lastyeardebit-$row->lastyearcredit;
                                              if(floatval($tyear_amount) == 0 && floatval($lyear_amount)==0) continue;?>
            								<tr>
                								<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo substr($row->acctCode,0, 4).'-'.substr($row->acctCode,4, 3).'-'.substr($row->acctCode,7, 2).' [ '.$row->acctName.' ]'?></td>
                                                <?php if($rowdet1->status == 1){?>
                									<td class="tar"><?php echo ($tyear_amount <= 0 )?number_format($tyear_amount * -1,2):'('.number_format($tyear_amount,2).')'?></td>
                                                	<td>&nbsp;</td>
                									<td class="tar"><?php echo ($lyear_amount <= 0 )?number_format($lyear_amount * -1,2):'('.number_format($lyear_amount,2).')'?></td>
                								<?php }else{?>
	                								<td class="tar"><?php echo ($tyear_amount >= 0 )?number_format($tyear_amount,2):'('.number_format($tyear_amount * -1,2).')'?></td>
                                                	<td>&nbsp;</td>
	                								<td class="tar"><?php echo ($lyear_amount >= 0 )?number_format($lyear_amount,2):'('.number_format($lyear_amount * -1,2).')'?></td>
                								<?php }?>
                							</tr>
                                            <?php $rowdet1_thisyeartotal = $rowdet1_thisyeartotal + 
												($row->lastyeardebit-$row->lastyearcredit)+($row->currentyeardebit - $row->currentyearcredit);?>
                                            <?php $rowdet1_lastyeartotal = $rowdet1_lastyeartotal + ($row->lastyeardebit-$row->lastyearcredit);?>
                                            <?php $rowdet_thisyeartotal = $rowdet_thisyeartotal + 
												($row->lastyeardebit-$row->lastyearcredit)+($row->currentyeardebit - $row->currentyearcredit);?>
                                            <?php $rowdet_lastyeartotal = $rowdet_lastyeartotal + ($row->lastyeardebit-$row->lastyearcredit);?>
                                            <?php $total_thisyear = $total_thisyear + ($row->lastyeardebit-$row->lastyearcredit)+($row->currentyeardebit - $row->currentyearcredit);?>
                                            <?php $total_lastyear = $total_lastyear + ($row->lastyeardebit-$row->lastyearcredit);?>
                                    <?php } ?>        
			            		<?php 	}
								endforeach;?>
                                <?php } ?>
            					<tr>
                					<td>&nbsp;&nbsp;&nbsp;<?php echo $this->lang->line('subtotal') ?> <?php echo $this->lang->line($rowdet1->acctGroupName)?> </td>
                                    <?php if($rowdet1->status == 1){?>
      									<td class="tar sep"><?php echo ($rowdet1_thisyeartotal <= 0 )?number_format($rowdet1_thisyeartotal * -1,2):'('.number_format($rowdet1_thisyeartotal,2).')'?></td>
                                       	<td>&nbsp;</td>
       									<td class="tar sep"><?php echo ($rowdet1_lastyeartotal <= 0 )?number_format($rowdet1_lastyeartotal * -1,2):'('.number_format($rowdet1_lastyeartotal,2).')'?></td>
       								<?php }else{?>
           								<td class="tar sep"><?php echo ($rowdet1_thisyeartotal >= 0 )?number_format($rowdet1_thisyeartotal,2):'('.number_format($rowdet1_thisyeartotal * -1,2).')'?></td>
                                       	<td>&nbsp;</td>
           								<td class="tar sep"><?php echo ($rowdet1_lastyeartotal >= 0 )?number_format($rowdet1_lastyeartotal,2):'('.number_format($rowdet1_lastyeartotal * -1,2).')'?></td>
       								<?php }?>
                				</tr>
                                <tr><td colspan="4">&nbsp;</td></tr>
			            		<?php 	}
								endforeach;?>
                				<?php if($accountdetails){ ?>
                				<?php foreach($accountdetails as $row):
										if($row->acctGroupID == $rowdet->ID){?>
                                <?php        	if($row->acctCode == '130000000') { ?>
                                <?php 			$thisyear_amount = $currentretained;?>
                                <?php 			$lastyear_amount = $lastyearretained; 
                                          if(floatval($thisyear_amount) == 0 && floatval($lastyear_amount)==0) continue;?>
            								<tr>
                								<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo  substr($row->acctCode,0, 4).'-'.substr($row->acctCode,4, 3).'-'.substr($row->acctCode,7, 2).' [ '.$row->acctName.' ]'?></td>
                                    <?php if($rowdet->status == 1){?>
      									<td class="tar"><?php echo ($thisyear_amount <= 0 )?number_format($thisyear_amount * -1,2):'('.number_format($thisyear_amount,2).')'?></td>
                                       	<td>&nbsp;</td>
       									<td class="tar"><?php echo ($lastyear_amount <= 0 )?number_format($lastyear_amount * -1,2):'('.number_format($lastyear_amount,2).')'?></td>
       								<?php }else{?>
           								<td class="tar"><?php echo ($thisyear_amount >= 0 )?number_format($thisyear_amount,2):'('.number_format($thisyear_amount * -1,2).')'?></td>
                                       	<td>&nbsp;</td>
           								<td class="tar"><?php echo ($lastyear_amount >= 0 )?number_format($lastyear_amount,2):'('.number_format($lastyear_amount * -1,2).')'?></td>
       								<?php }?>
                							</tr>
                                            <?php $total_thisyear = $total_thisyear + $thisyear_amount;?>
                                            <?php $total_lastyear = $total_lastyear + $lastyear_amount;?>
                                            <?php $rowdet_thisyeartotal = $rowdet_thisyeartotal + ($row->lastyeardebit-$row->lastyearcredit)+$thisyear_amount;?>
                                            <?php $rowdet_lastyeartotal = $rowdet_lastyeartotal + $lastyear_amount;?>
                                <?php }elseif($row->acctCode == '120000000') { ?>
                                <?php  $lastyear_amount = ($lastRetain); ?>
                                <?php  $thisyear_amount = ($currRetain); 
                                        if(floatval($thisyear_amount) == 0 && floatval($lastyear_amount)==0) continue;
                                ?>
                            <tr>
                                <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo  substr($row->acctCode,0, 4).'-'.substr($row->acctCode,4, 3).'-'.substr($row->acctCode,7, 2).' [ '.$row->acctName.' ]'?></td>
                                    <?php if($rowdet->status == 1){?>
                        <td class="tar"><?php echo ($thisyear_amount <= 0 )?number_format($thisyear_amount * -1,2):'('.number_format($thisyear_amount,2).')'?></td>
                                        <td>&nbsp;</td>
                        <td class="tar"><?php echo ($lastyear_amount <= 0 )?number_format($lastyear_amount * -1,2):'('.number_format($lastyear_amount,2).')'?></td>
                      <?php }else{?>
                          <td class="tar"><?php echo ($thisyear_amount >= 0 )?number_format($thisyear_amount,2):'('.number_format($thisyear_amount * -1,2).')'?></td>
                                        <td>&nbsp;</td>
                          <td class="tar"><?php echo ($lastyear_amount >= 0 )?number_format($lastyear_amount,2):'('.number_format($lastyear_amount * -1,2).')'?></td>
                      <?php }?>
                              </tr>
                                            <?php $total_thisyear = $total_thisyear + $thisyear_amount;?>
                                            <?php $total_lastyear = $total_lastyear + $lastyear_amount;?>
                                            <?php $rowdet_thisyeartotal = $rowdet_thisyeartotal + $thisyear_amount;?>
                                            <?php $rowdet_lastyeartotal = $rowdet_lastyeartotal + $lastyear_amount;?>
                                <?php     } ?>
                                       <?php	if($row->lastyeardebit == 0 && $row->lastyearcredit == 0 && $row->currentyeardebit == 0 && $row->currentyearcredit == 0){ }

                                       elseif($row->acctCode != '130000000' && $row->acctCode != '120000000'){ ?>
                                       <?php $tyear_amount = ($row->lastyeardebit-$row->lastyearcredit)+($row->currentyeardebit - $row->currentyearcredit);?>
                                       <?php $lyear_amount = $row->lastyeardebit-$row->lastyearcredit;
                                              if(floatval($tyear_amount) == 0 && floatval($lyear_amount)==0) continue;?>
            								<tr>
                								<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo substr($row->acctCode,0, 4).'-'.substr($row->acctCode,4, 3).'-'.substr($row->acctCode,7, 2).' [ '.$row->acctName.' ]'?></td>
                                    <?php if($rowdet->status == 1){?>
      									<td class="tar"><?php echo ($tyear_amount <= 0 )?number_format($tyear_amount * -1,2):'('.number_format($tyear_amount,2).')'?></td>
                                       	<td>&nbsp;</td>
       									<td class="tar"><?php echo ($lyear_amount <= 0 )?number_format($lyear_amount * -1,2):'('.number_format($lyear_amount,2).')'?></td>
       								<?php }else{?>
           								<td class="tar"><?php echo ($tyear_amount >= 0 )?number_format($tyear_amount,2):'('.number_format($tyear_amount * -1,2).')'?></td>
                                       	<td>&nbsp;</td>
           								<td class="tar"><?php echo ($lyear_amount >= 0 )?number_format($lyear_amount,2):'('.number_format($lyear_amount * -1,2).')'?></td>
       								<?php }?>
                							</tr>
                                            <?php $total_thisyear = $total_thisyear + ($row->lastyeardebit-$row->lastyearcredit)+($row->currentyeardebit - $row->currentyearcredit);?>
                                            <?php $total_lastyear = $total_lastyear + ($row->lastyeardebit-$row->lastyearcredit);?>
                                            <?php $rowdet_thisyeartotal = $rowdet_thisyeartotal + 
												($row->lastyeardebit-$row->lastyearcredit)+($row->currentyeardebit - $row->currentyearcredit);?>
                                            <?php $rowdet_lastyeartotal = $rowdet_lastyeartotal + ($row->lastyeardebit-$row->lastyearcredit);?>
                                     <?php } ?>
			            		<?php 	}
								endforeach;?>
                                    <?php } ?>        
            					<tr>
                                	<?php if($rowdet->ID == '39'){?>
                					<td>&nbsp;&nbsp;&nbsp;<strong><?php echo $this->lang->line($rowdet->acctGroupName)?></strong></td>
                                    <?php }else{ ?>
                					<td>&nbsp;&nbsp;&nbsp;<?php echo $this->lang->line('subtotal') ?> <?php echo $this->lang->line($rowdet->acctGroupName)?> </td>
                                    <?php } ?>
                                    <?php if($rowdet->status == 1){?>
      									<td class="tar sep"><?php echo ($rowdet_thisyeartotal <= 0 )?number_format($rowdet_thisyeartotal * -1,2):'('.number_format($rowdet_thisyeartotal,2).')'?></td>
                                       	<td>&nbsp;</td>
       									<td class="tar sep"><?php echo ($rowdet_lastyeartotal <= 0 )?number_format($rowdet_lastyeartotal * -1,2):'('.number_format($rowdet_lastyeartotal,2).')'?></td>
       								<?php }else{?>
           								<td class="tar sep"><?php echo ($rowdet_thisyeartotal >= 0 )?number_format($rowdet_thisyeartotal,2):'('.number_format($rowdet_thisyeartotal * -1,2).')'?></td>
                                       	<td>&nbsp;</td>
           								<td class="tar sep"><?php echo ($rowdet_lastyeartotal >= 0 )?number_format($rowdet_lastyeartotal,2):'('.number_format($rowdet_lastyeartotal * -1,2).')'?></td>
       								<?php }?>
                				</tr>
                                <tr><td colspan="4">&nbsp;</td></tr>
            		<?php 	}
							endforeach;?>
                				<?php foreach($accountdetails as $row):
										if($row->acctGroupID == $datatbl->ID){?>
                                <?php        	if($row->acctCode == '130000000') { ?>
                                <?php 			$thisyear_amount = $currentretained * -1;?>
                                <?php 			$lastyear_amount = $lastyearretained * -1; ?>
                                <?php 		}else{ ?>
                                <?php 			$thisyear_amount = ($row->lastyeardebit-$row->lastyearcredit)+($row->currentyeardebit - $row->currentyearcredit)?>
                                <?php 			$lastyear_amount = $row->lastyeardebit-$row->lastyearcredit?>
                                <?php 		} 
                                        if(floatval($thisyear_amount) == 0 && floatval($lastyear_amount)==0) continue;?>
            								<tr>
                								<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo  substr($row->acctCode,0, 4).'-'.substr($row->acctCode,4, 3).'-'.substr($row->acctCode,7, 2).' [ '.$row->acctName.' ]'?></td>
                                    <?php if($datatbl->status == 1){?>
      									<td class="tar"><?php echo ($thisyear_amount <= 0 )?number_format($thisyear_amount * -1,2):'('.number_format($thisyear_amount,2).')'?></td>
                                       	<td>&nbsp;</td>
       									<td class="tar"><?php echo ($lastyear_amount <= 0 )?number_format($lastyear_amount * -1,2):'('.number_format($lastyear_amount,2).')'?></td>
       								<?php }else{?>
           								<td class="tar"><?php echo ($thisyear_amount >= 0 )?number_format($thisyear_amount,2):'('.number_format($thisyear_amount * -1,2).')'?></td>
                                       	<td>&nbsp;</td>
           								<td class="tar"><?php echo ($lastyear_amount >= 0 )?number_format($lastyear_amount,2):'('.number_format($lastyear_amount * -1,2).')'?></td>
       								<?php }?>
                							</tr>
                                            <?php $total_thisyear = $total_thisyear + $thisyear_amount;?>
                                            <?php $total_lastyear = $total_lastyear + $lastyear_amount;?>
			            		<?php 	}
								endforeach;?>
            					<tr>
                					<td><h4><?php echo $this->lang->line('total') ?> <?php echo $this->lang->line($datatbl->acctGroupName)?> </h4></td>
                                    <?php if($datatbl->status == 1){?>
           								<td class="tar tots"><?php echo ($total_thisyear <= 0 )?number_format($total_thisyear * -1,2):'('.number_format($total_thisyear,2).')'?></td>
                                       	<td>&nbsp;</td>
           								<td class="tar tots"><?php echo ($total_lastyear <= 0 )?number_format($total_lastyear * -1,2):'('.number_format($total_lastyear,2).')'?></td>
       								<?php }else{?>
           								<td class="tar tots"><?php echo ($total_thisyear >= 0 )?number_format($total_thisyear,2):'('.number_format($total_thisyear * -1,2).')'?></td>
                                       	<td>&nbsp;</td>
           								<td class="tar tots"><?php echo ($total_lastyear >= 0 )?number_format($total_lastyear,2):'('.number_format($total_lastyear * -1,2).')'?></td>
       								<?php }?>
                				</tr>
                                <tr><td colspan="4">&nbsp;</td></tr>
            <?php endforeach; }?>
                     </tbody>
</div>
<div style="page-break-after:always"></div>
</html>
