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

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

	 if( window.print()) {
		 if(printing=true){
			 
			  window.location.href = "../user/logout";

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

		 }
    }else {

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

		    // 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="redcolor" >
            		<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%;"  >

             <thead>
			  
				 <tr>
				  <th colspan="5"><center>
			 <?php  if(isset($configuration[0]['businessname'])) {echo   $configuration[0]['businessname']; }
			   $TIMEOFREPORT=date("d/m/Y H:i:s a");
			 ?>
</BR>
			 <B>TRIAL BALANCE 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>
    <th>Code</th>
     <th>Account Name</th>
	     <th>Debit</th>
<th>Credit</th>	


	   </tr>
             </thead><tbody>
<?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;
					}	
 if(!is_array($trialbalance)) 

 {


   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='1'>";
    
       echo '<div class="alert alert-warning text-center">There no records found..</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>
    
             <?php 
  $totaldebt=0;
    $totalcredit=0;
	
  	foreach ($trialbalance as $c): 
//var_dump($trialbalance);
	$accountss=$this->usermodel->populateallarray('glgroups','id', $c->accounttype);
	$myaccounttype=$accountss[0]['accounttype'];
$debitbalance=0;
$creditbalance=0;
             ?>



             <tr>
                
            <?php 
$id=$c->id;

	if(($myaccounttype=="1") || (	$myaccounttype=="5")){
		
		

			$debitbalance=$c->debit-$c->credit ;
						 // $totaldebt=$totaldebt+$c->debit;

			 //$totaldebt=$totaldebt+$debitbalance;
	}else{
			$creditbalance=$c->credit-$c->debit ;
    //$totalcredit= $totalcredit+$creditbalance;
   // $totalcredit= $totalcredit+$c->credit;

	}
	


?>

              
 <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><?php 
  
  $accountdata=$this->usermodel->populateallarray('glaccounts','number', $c->account);

echo$accountname=$accountdata[0]['accountname'];
		

  ?></td>
    <td><?php 
	
		if((	$myaccounttype=="1") || (	$myaccounttype=="5")){
		
		
		if($debitbalance > 0){
		 echo formatMoney($debitbalance, true);
		  	$totaldebt=$totaldebt+$debitbalance;

		}
		}
		if(!(	$myaccounttype=="1") || (	$myaccounttype=="5")){
		
		 //echo formatMoney($creditbalance, true);
		 
		 	if($creditbalance < 0){
		  echo  formatMoney(-1* $creditbalance, true);
		  $totaldebt=$totaldebt+$debitbalance;
		}

	}



	?></td>
	 <td><?php 


	if(!(	$myaccounttype=="1") || (	$myaccounttype=="5")){
		
		 
		 	if($creditbalance > 0){
		 echo  formatMoney($creditbalance, true);
		 	    //$totalcredit= $totalcredit+$c->credit;
		 	    $totalcredit= $totalcredit+$creditbalance;

		}

	}

	
		if((	$myaccounttype=="1") || (	$myaccounttype=="5")){
		
		
		if($debitbalance < 0){
		 echo formatMoney(-1*$debitbalance, true);
		 		 	   // $totalcredit= $totalcredit+$c->credit;
				 $totalcredit= $totalcredit+(-1*$debitbalance);


		}
		}
	




	 //echo formatMoney($balance, true);
	 
	 ?></td>
	 
 
 
             </tr>

	<?php endforeach;} ?>
 <tr>
    <th colspan="2"><CENTER>TOTAL BALANCE</CENTER></th>
	   <th> <h3><?php if(isset($totaldebt)) {echo formatMoney($totaldebt, true); }?></h3></th>
	   <th> <h3><?php if(isset($totalcredit)) {echo formatMoney($totalcredit, true); }?></h3></th>
    <th></th >
                 </tr>
         

       <tbody> </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/trialbalance' , 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>


















