
    	
<script>
	function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

    // document.body.innerHTML = printContents.fontsize(12);
     window.print();

	 if( window.print()) {
         window.location.href = "../user/balancesheet";
		alert(" printing...........");
    }else {

	
		      return      window.location.href = "../user/balancesheet";

		    // document.body.innerHTML = originalContents;

	}
}

 
	</script>
	
	
	 <style type="text/css">
  
  

    #printable { display: none; }
#print{  	


    background-repeat: no-repeat;
	font-size;20px;

    width:100%; height:50px;



}
#extratitle { font-size: 2em; }
.doted{
    border: dotted 3px #000000;
}
table { border-collapse: collapse; }
td { padding: 5px; }
tr { border-bottom:1px dashed #494949; }


table{
    border-collapse:collapse;/*This property collapses borders together*/
}

#sale{  	
background-image:url(images/add.png) ;

    background-repeat: no-repeat;
  
    width:100px; height:50px;


}
#alltitle{ font-size: 2.2em; }
	#mytitle { font-size: 1.5em; }
#myalltitle { font-size: 3em; }
    @media print
    {
		
    	#non-printable { display: none; }
    	#printableArea { display: block; font-size:18; width:100%; }
		  margin:0; 
		#receipt{
	font-style: normal;font-size: 2em;
	
	padding:0px;
	
}
    }
    </style>
 <div class="row">
  

   	<div class="col-md-12">

  
		<div class="panel panel-default" data-collapsed="0">
        	<div class="panel-heading">
            	<div class="panel-title" id="non-printable" >
            		<i class="entypo-plus-circled"></i>

 <a href="<?php echo base_url();?>user/startsales" class="btn btn-info">  Go back</a>	
 <a data-toggle='modal' data-target='#addreportModal' class="btn btn-info">View Customed Report  </a>



<div class="pull-right"  >

<form name="print" method="post" action="">
 <input type="submit" id="print"  accesskey="p" class="btn btn-primary"  name="print"onclick="printDiv('sortable_table')" value="Print Report" />
</form></div>
 
 

				
            	</div>
            </div>
			<div class="panel-body">

			
	<div class="widget-content nopadding table_holder table-responsive" ID="sortable_table">				
				<?PHP

//
								?>	
					<div class="row">
						<div class="col-md-12">
							
							<div class="panel-body">
	
									
  <table cellpadding="0" cellspacing="0" border="1" class="table  table-striped" id="example" style="border-color:#CCCCCC; width:100%;"  >

		
 
  <tr>
				  <th colspan="3"><center>
			 <?php  if(isset($configuration[0]['businessname'])) {echo   $configuration[0]['businessname']; }
			   $TIMEOFREPORT=date("d/m/Y H:i:s a");
			 ?>
</BR>
			 <B>BALANCE SHEET REPORT</B>
			 FROM  <?php  if(isset($startdate)) {echo   date("d/m/Y H:i:s", strtotime($startdate)); }?>  TO  <?php  if(isset($enddate)) {echo     date("d/m/Y H:i:s", strtotime($enddate));; }?>   </B><br>
			 Report was run on <?php echo  date("d/m/Y H:i:s");?>
									<br>Name----------------------Date--------------------Signature----------------</span>

			</th>
	
			 </center>
			 </tr>
 
 <tr>
    <td colspan="3"><CENTER>	ASSETS</CENTER></td>
  
                 </tr>
         <tr>
    <td><b>Code</b></td>
     <td><b><center>Account Name</center></b></td>
	 
<td align="right"><b>Total</b> </td>	

      	

	   </tr>
<?php
   function formatMoney($number, $fractional=false) {
						if ($fractional) {
							$number = sprintf('%.2f', $number);
						}
						while (true) {
							$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
							if ($replaced != $number) {
								$number = $replaced;
							} else {
								break;
							}
						}
						return $number;
					}	
					$accounts_array = array();

	   			        		$mainaccounts= $this->usermodel->populateall('glaccounts','companyid', $companyid);
	 if(is_array($mainaccounts)) 

 {
	foreach ($mainaccounts as $rowgl){
		
					$accounts_array[]=array(	
			'accounttype'=>$rowgl->accounttype,
						'id'=>$rowgl->id,

				'accountname'=>$rowgl->accountname,
							'bankname'=>$rowgl->bankname,
							'number'=>$rowgl->number,

		  	'description'=>$rowgl->description,
				 'companyid'=>$rowgl->companyid,

				 
			
								);	
		
	}
  	
 }	
 
 
 //var_dump($accounts_array);
// exit;
 	
				 function getAccountName($id, $accounts_array) {
    $key = array_search($id, array_column($accounts_array, 'id'));
    if ($key !== FALSE) {
        return $accounts_array[$key]['accountname'];
    }
}
//$mainkey = array_search($c->mybankname, array_column($accounts_array, 'id'));
			//	$key2 = array_search($c->account, array_column($accounts_array, 'number'));

						 $MYLIABILTYEQUITY= 0;
						 $myliability=0;
						 $myequity=0;
						 $mynetprofit=0;
$totalassetdebt=0;
  $assetbalance=0;
    $totalassetcredit=0;

	
	
	$ttfixedssets=0;
	$balanceasset=0;
	$liabiltybalance=0;
	$ttlongtermliability=0;

		$totalequitybalance=0;

	$ttcurentliability=0;
	
		$ttownerequity=0;
		    				$ttcurrentassets=0;


 if(!is_array($asset)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='1'>";
    
    echo "</td>";
   echo "</tr>";
    }else {
?>
      <tr>
    <td colspan="3">
	    <b><center>Current Assets</center></b></td>
  
                 </tr>
             <?php 
  

  

  

  	foreach ($asset as $c){

		 		  $myaccounttype=$c->myaccounttype;


             ?>



            
                
            <?php 
			 if(($myaccounttype==1)|| ($myaccounttype==6)){


$id=$c->id;
//$asssetdiffrence=$c->debit-$c->credit;
  //$totalassetdebt=$totalassetdebt+$c->debit;
  
  //$totalassetcredit=$totalassetcredit+$c->credit;
			//$balanceasset=$totalassetdebt-$totalassetcredit;
			$MYttcurrentassets=($c->debit-$c->credit);
				$ttcurrentassets=$ttcurrentassets+$MYttcurrentassets;

?>
 <tr>
<td>
      
   			   	 	 <a   id="non-printable" target="_blank" class="btn-default" href="<?php echo base_url();?>user/viewaccount?bankname=<?php   {echo  $c->account ;}  ?>&startdate=<?php   {echo  $startdate ;}  ?>&enddate=<?php   {echo  $enddate ;}  ?>"><?php echo $c->account ; ?>  </a>
						 <span id="myprint"><?php  echo $c->account ; ?></span>
 
 </td>
  <td>
  
  			   	 	 <a  id="non-printable" target="_blank" class="btn-default" href="<?php echo base_url();?>user/viewaccount?bankname=<?php   {echo  $c->account ;}  ?>&startdate=<?php   {echo  $startdate ;}  ?>&enddate=<?php   {echo  $enddate ;}  ?>"><?php echo $c->myaccountname ; ?>  </a>

  						 <span id="myprint"><?php  echo $c->myaccountname  ; ?></span>

  
  
  </td>         

   
	 <td align="right">
	  <?php

	 echo   formatMoney($MYttcurrentassets, true);
	 
	 

		 ?>
	 </td>
	 
 <?php

	 
			 }}
	 

		 ?>
 
             </tr>
			 
			 
			<tr>
<td></td>
    <td><b>Total Current Assets</b></td>
	   <td align="right"><b> <?php if(isset($ttcurrentassets)) {echo formatMoney($ttcurrentassets, true); }?></b></td>
  
                 </tr> 
			 
			 
			 
			 
			 
			   <tr>
    <td colspan="3">
	    <b><center>Fixed Assets </center></b></td>
  
                 </tr>
				 <?php 
  
  	foreach ($asset as $fxdasset){

		 		  $accounttype=$fxdasset->myaccounttype;


             ?>



                
            <?php 
			 if($accounttype==7){
					$MYttfixedtassets=($fxdasset->debit-$fxdasset->credit);


				$ttfixedssets=$ttfixedssets+$MYttfixedtassets; 

						
  

?>
             <tr>


      <td>
   			   	 	 <a   target="_blank" class="btn-default" href="<?php echo base_url();?>user/viewaccount?bankname=<?php   {echo  $fxdasset->account ;}  ?>&startdate=<?php   {echo  $startdate ;}  ?>&enddate=<?php   {echo  $enddate ;}  ?>"><?php echo $fxdasset->account ; ?>  </a>

						 <span id="myprint"><?php echo $fxdasset->account; ?></span>
 
 </td>
  <td>
  
  			   	 	 <a id="non-printable"  target="_blank" class="btn-default" href="<?php echo base_url();?>user/viewaccount?bankname=<?php   {echo  $fxdasset->account ;}  ?>&startdate=<?php   {echo  $startdate ;}  ?>&enddate=<?php   {echo  $enddate ;}  ?>"><?php echo $fxdasset->myaccountname ; ?>  </a>
						 <span id="myprint"><?php echo $fxdasset->myaccountname; ?></span>

  
  
  
  </td>         

   
	 <td align="right"><?php 
			 
	 
	 echo   formatMoney($MYttfixedtassets, true);

		 ?>
	 
	 </td>
	 
 
 
            

	<?php
	}}
	?>
	
	
	 
			<tr>
<td></td>
    <td><b>Total 	Fixed Assets</b></td>
	   <td align="right"><b> <?php if(isset($ttfixedssets)) {echo formatMoney($ttfixedssets, true); }?></b></td>
  
                 </tr> 

	
	<?php
	}
	
	$balanceasset=$ttfixedssets+$ttcurrentassets;
	?>
	 </tr>
	    
 <tr>
    <td colspan="2"><b>Total Assets</b></td>
	   <td  align="right"><b> <?php if(isset($balanceasset)) {echo formatMoney($balanceasset, true); }?></b></td>
  
                 </tr>
				
				  <tr>
    <td colspan="3"><CENTER><b>		LIABILITIES</b></CENTER></td>
  
                 </tr>
				 <?PHP
				 
				//// var_dump($liability);
				// exit;
          if(!is_array($liability)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='1'>";
    
    echo "</td>";
   echo "</tr>";
    }else {
?>
<tr>
    <td colspan="3">
	    <b><center>Current Libilities </center></b>
		</td>
  
                 </tr>
				 
             <?php 
  

  	foreach ($liability as $cliability){
$libilityaccounttype=$cliability->myaccounttype;	

		 

             ?>



             <tr>
			
                       <?php 
			 if($libilityaccounttype==14){
				 
				 $currentliabilty=$cliability->credit-$cliability->debit;
$ttcurentliability=$ttcurentliability+$currentliabilty;


						
  

?>
    


              
 <td>
   			   	 	 <a  id="non-printable"  target="_blank" class="btn-default" href="<?php echo base_url();?>user/viewaccount?bankname=<?php   {echo  $cliability->account ;}  ?>&startdate=<?php   {echo  $startdate ;}  ?>&enddate=<?php   {echo  $enddate ;}  ?>"><?php echo $cliability->account ; ?>  </a>
   						 <span id="myprint"><?php  echo $cliability->account  ; ?></span>

 
 </td>
  <td>
  
  			   	 	 <a   id="non-printable" target="_blank" class="btn-default" href="<?php echo base_url();?>user/viewaccount?bankname=<?php   {echo  $cliability->account ;}  ?>&startdate=<?php   {echo  $startdate ;}  ?>&enddate=<?php   {echo  $enddate ;}  ?>"><?php echo $cliability->myaccountname ; ?>  </a>

     						 <span id="myprint"><?php  echo $cliability->myaccountname ; ?></span>

  
  
  </td>
  
   
	 <td align="right">
	 <?php echo   formatMoney($currentliabilty, true); ?>
	 </td>
	 
 
 
            

	<?php
	
	 }
	}
	?>
	
	 </tr>
	 <tr>
	 <td></td>
	     <td><b>Total Current Libilities</b></td>

	   <td  align="right"><b> <?php if(isset($ttcurentliability)) {echo formatMoney($ttcurentliability, true); }?></b></td>
  
                 </tr>
				 
				 <tr>
    <td colspan="3">
	    <b><center>Long term Libilities </center></b>
		</td>
  
                 </tr>
			 
             <?php 


  	foreach ($liability as $longtermliability){
$libilityaccounttype=$longtermliability->myaccounttype;	

		 

             ?>



             <tr>
			
                       <?php 
			 if($libilityaccounttype==15){
				 
				 $longtermliabilty=($longtermliability->credit-$longtermliability->debit);
$ttlongtermliability=$ttlongtermliability+$longtermliabilty;


						
  

?>
    


              
 <td>
   			   	 	 <a   id="non-printable" target="_blank" class="btn-default" href="<?php echo base_url();?>user/viewaccount?bankname=<?php   {echo  $longtermliability->account ;}  ?>&startdate=<?php   {echo  $startdate ;}  ?>&enddate=<?php   {echo  $enddate ;}  ?>"><?php echo $longtermliability->account ; ?>  </a>
     						 <span id="myprint"><?php  echo $longtermliability->account ; ?></span>

 
 </td>
  <td>
  
  			   	 	 <a   id="non-printable" target="_blank" class="btn-default" href="<?php echo base_url();?>user/viewaccount?bankname=<?php   {echo  $longtermliability->account ;}  ?>&startdate=<?php   {echo  $startdate ;}  ?>&enddate=<?php   {echo  $enddate ;}  ?>"><?php echo $longtermliability->myaccountname ; ?>  </a>
     						 <span id="myprint"><?php  echo  $longtermliability->myaccountname; ?></span>

  
  
  
  </td>
  
   
	 <td align="right">
	 <?php echo   formatMoney($longtermliabilty, true); ?>
	 </td>
	 
 
 
            

	<?php
	
	 }
	}
	?>
	
	 </tr>
	
	<tr>
	 <td></td>
	     <td><b>Total Long Term Libilities</b></td>

	   <td  align="right"><b> <?php if(isset($ttlongtermliability)) {echo formatMoney($ttlongtermliability, true); }?></b></td>
  
                 </tr>
	
	
		<?php
		

	} 
	$liabiltybalance=$ttlongtermliability+$ttcurentliability;
	
	?>
	
	
	
	
 <tr>
    <td colspan="2"><b>Total Libilities</b></td>
	   <td align="right"> <b><?php if(isset($liabiltybalance)) {echo formatMoney($liabiltybalance, true); }?></b></td>
  
                 </tr>
				 
				 
				  <tr>
    <td colspan="3"><CENTER>		EQUITY</CENTER></td>
  
                 </tr>
				 <?PHP

          if(!is_array($equity)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='1'>";
    
    echo "</td>";
   echo "</tr>";
    }else {
?>
     <tr>
    <td colspan="3">
	    <b><center>Owner's Equity </center></b>
		</td>
  
                 </tr>
             <?php 
  

  	foreach ($equity as $cequity): 

		 

             ?>



             <tr>
                
            <?php 

$totalownerequity=$cequity->credit-$cequity->debit;
$ttownerequity=$ttownerequity+$totalownerequity;
 
?>

              
    <td>
   			   	 	 <a  id="non-printable"  target="_blank" class="btn-default" href="<?php echo base_url();?>user/viewaccount?bankname=<?php   {echo  $cequity->account ;}  ?>&startdate=<?php   {echo  $startdate ;}  ?>&enddate=<?php   {echo  $enddate ;}  ?>"><?php echo $cequity->account ; ?>  </a>
     						 <span id="myprint"><?php  echo  $cequity->myaccountname; ?></span>

 
 </td>
  <td>
  
  			   	 	 <a   id="non-printable" target="_blank" class="btn-default" href="<?php echo base_url();?>user/viewaccount?bankname=<?php   {echo  $cequity->account ;}  ?>&startdate=<?php   {echo  $startdate ;}  ?>&enddate=<?php   {echo  $enddate ;}  ?>"><?php echo $cequity->myaccountname ; ?>  </a>
     						 <span id="myprint"><?php  echo  $cequity->myaccountname; ?></span>

  
  
  
  </td>         

   
	 <td align="right"><?php echo   formatMoney($totalownerequity, true);

	 ?></td>
	 
 
 
 
             </tr>

	<?php endforeach;} ?>







 <?PHP
    $totalprofitincome=0;
    $totalprofitexpense=0;
	
          if(!is_array($netprofit)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='1'>";
    
    echo "</td>";
   echo "</tr>";
    }else {
?>
    

             <?php 
  

  	foreach ($netprofit as $cnetprofit): 

		 $netprofittype=$cnetprofit->description;	

		 			 if($netprofittype==4){
						$totalprofitincome =(($totalprofitincome+($cnetprofit->credit)) -($totalprofitincome+($cnetprofit->debit)));
						
						
					 }
					  if($netprofittype==5){
					 $totalprofitexpense =(($totalprofitexpense+($cnetprofit->debit))-($totalprofitexpense+($cnetprofit->credit)));

					 }


             ?>

                <tr>
 <td> </td>
 
<!--
 <td colspan="2"><?PHP  echo $totalprofitincome.  "====".$totalprofitexpense;       ?> </td>
-->
 </tr>


	<?php endforeach;}

	$totalprofitbalance= $totalprofitincome-$totalprofitexpense;
	

?>





  <tr>
 <td></td>

 <td>Retained Earnings</td>
	 <td colspan="2" align="right"><?php echo   formatMoney($totalprofitbalance, true); ?></td>
  
                 </tr>











 <tr>
    <td colspan="2"><b>Total Equity and Retained Earnings</b></td>
	   <td align="right"> <b><?php 
$eqtyearnings=$ttownerequity+$totalprofitbalance;


if(isset($eqtyearnings)) {echo formatMoney($eqtyearnings, true); }?></b></td>
  
                 </tr>
				 
				 
				 
				 
				 
				 
				 
				 
				 
				 
				 
				 
<tr>
    <td colspan="2"><b>Total  Libilities and Equity</b></td>
	   <td align="right"> <b><?php 
	   
	$MYLIABILTYEQUITY=  $liabiltybalance+$eqtyearnings;
	   if(isset($MYLIABILTYEQUITY)) { echo formatMoney(  $MYLIABILTYEQUITY, true); }?></b></td>
  
                 </tr>
    </table>
	   
   
			
	</div>
						
									
							</div>
						</div>
				

			
			</div>
		</div>
  
  </div>
			<div id="addreportModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">View customed Report</h4>
      </div>
      <div class="modal-body">
      
	  	

				<?PHP
//$session_data = $this->session->userdata('logged_in');

  $finalstartdate=date("Y-m-01 00:00:00");
  $finalendate=date("Y-m-30 23:59:59");


				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/balancesheet' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>

  <div class="form-group">
    <label for="inputbranchname" class="col-sm-2 control-label">Counter</label>
    <div class="col-sm-10">
	<select class="form-control" name="branchname"  id="branchname" required>
	
	
	<option value=""  >---Select Branch/Counter Name--</option>

					<option value="all"  >All branches/Counters</option>
		
	
	<?php 
					 
					 		$maincategory = $this->usermodel->populateall('branch','companyid',$companyid);


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

   //echo $courserow->coursename;
    ?>
					<option selected="selected" value="<?=  $maincategoryrow->id;   ?>"><?=  $maincategoryrow->name; ?></option>



	<?php

}} else {
    echo 'No main counter available.';
}
	
?>
</select>
		

		
	</div>
  </div>
	
	
	
	
	
	
	
	
	
  <div class="form-group">
    <label for="inputstartdate" class="col-sm-2 control-label">From Date </label>
    <div class="col-sm-10">
	
		  		<input type="date" name="startdate" value="<?php echo set_value('fromdate',$finalstartdate); ?>" class="form-control" required placeholder="Enter start date">
		 
				
		<span class="text-danger"> <?php echo form_error('startdate'); ?>
		
		</span>
	</div>
  </div>
  
  	<div class="form-group">
    <label for="inputenddate" class="col-sm-2 control-label">	To Date </label>
    <div class="col-sm-10">
	
		  		<input type="date" name="enddate" value="<?php echo set_value('enddate',$finalendate); ?>" class="form-control" required placeholder="Enter  close date">
		 
				
		<span class="text-danger"> <?php echo form_error('todate'); ?>
		
		</span>
	</div>
  </div>
  
    


	

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="report" name="btn_report" class="btn btn-primary"> View Report  </button>

    </div>
  </div>
  					<?php echo form_close();?>
			</div>							   
				
									
							
								
			<div class="modal-footer">

    

				</div>

		</div>
	    </div>
    </div>
	
	
			
			
			
			
		
		
  

 
</div>


















