   	
<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/generalledger";
		alert(" printing...........");
    }else {

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

		    // document.body.innerHTML = originalContents;

	}
}
 $(document).on("click", "#managebtndelete", function()
        {
          var itemid1 = $(this).data('id');
		  $("#itemid1").val(itemid1); 
 
 
		   
        });
 
	</script>
 
 <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 data-toggle='modal' data-target='#addreportModal' class="btn btn-info">View Customed Report  </a>
-->
 <a href="<?php echo base_url();?>user/viewbanktransfer" class="btn btn-info">  Go Back</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">
	<div class="col-md-12" id="non-printable">
        <?php 
		 echo $this->session->flashdata('msg'); 
        $attr = array("class" => "form-horizontal", "role" => "form", "id" => "search", "name" => "search");
        echo form_open("user/searchJE", $attr);?>
            <div class="form-group">
			
                <div class="col-md-5">
                    <input class="form-control" id="searchterm" name="searchterm" placeholder="Search for journal entries by code, name, invoice etc.." type="text" value="<?php echo set_value('searchterm'); ?>" />
                </div>
                <div class="col-md-4">
                    <input id="btn_search" name="btn_search" type="submit" class="btn btn-success" value="Search" />
                    <a href="<?php echo base_url(). "user/generalledger"; ?>" class="btn btn-primary">Refresh</a>
                </div>
				 
            </div>
        <?php echo form_close(); ?>
        </div>
		
									
  <table cellpadding="0" cellspacing="0" border="1" class="table  table-striped" id="example" style="border-color:#CCCCCC; width:100%;"  >

             <thead>
			     <tr>
    <th colspan="7"><CENTER>	GENERAL  LEDGER
	
	
	
	
	<?php if(isset($searchterm)) {echo "REF. ".$searchterm; }?>
	
	
	</CENTER></th>
  
                 </tr>
         <tr>
    <th>Code</th>
     <th>Account Name</th>
	     <th>Debit</th>
<th>Credit</th>	
<th>Date</th>
<th>Description</th>	
		      <th>Code/Chq. No.</th>
		      <th>Customer</th>
			  		      <th>Item Code</th>

   <th>Branch</th>		

<th>More</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($generalledger)) 

 {


   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 ($generalledger as $c): 

		 

             ?>



             <tr>
                
            <?php 
$id=$c->id;
  $totaldebt=$totaldebt+$c->debit;
    $totalcredit= $totalcredit+$c->credit;

?>

            
			                

 <td>
   			   	 	 <a  target="_blank" class="btn-default" href="<?php echo base_url();?>user/viewaccount?bankname=<?php   {echo  $c->account ;}  ?>&startdate=<?php    if(isset($startdate)) {echo $startdate ; }  ?>&enddate=<?php  if(isset($enddate)) {echo $enddate ; }  ?>"><?php  $c->account ; ?>  </a>
	<a  id="more"  target="_blank"  href="<?php echo base_url();?>user/searchJE?searchterm=<?php   {echo  $c->code;}  ?> ">
			 <?php  echo $c->code; ?>
                </a>
 </td>
  <td><?php 
  
  $accountdata=$this->usermodel->populateallarray('glaccounts','number', $c->account);

echo$accountname=$accountdata[0]['accountname'];
		
  
  ?></td>
    <td><?php  echo formatMoney($c->debit, true);  ?></td>
	 <td><?php  echo formatMoney($c->credit, true); ?></td>
	 
	 
 	 <td><?php echo $c->crateddate ; ?></td>
 	 <td><?php echo $c->description ; ?></td>
         <td><?php echo $c->transactioncode ; ?></td>
 	       <td><?php 
		   if($c->supplier !=""){
		     $sales1=$this->usermodel->populateallarray('people','id', $c->supplier);
	  if($sales1[0]['company']!=""){
		 $finalcustomer= $sales1[0]['company']; 
	  }else{
		  $finalcustomer= $sales1[0]['firstname'];
	  }
	  
		   
		   
		   echo $finalcustomer ;

		   }
		   ?>
		   
		   
		   
		   </td>
		    	 <td><?php 
				 
				 $myproducts=$this->usermodel->populateallarray('products','code', $c->refno);


			echo$myproducts[0]['name']."(". $c->refno .")";
				 
				 ?></td>

		   <td><?php  $mybranchid=$c->branch ;

$mybranch=$this->usermodel->populateallarray('branch','id', $mybranchid);


			echo$myname=$mybranch[0]['name'];

 ?></td>	

 <td id="non-printable"> 

 
 
					<div class="btn-group">
                                    <button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown">
                                        More <span class="caret"></span>
                                    </button>
									
									
				
								
                                    <ul class="dropdown-menu dropdown-primary pull-right" role="menu">
                                        
                                        <!-- teacher EDITING LINK -->
                                      
											<?php
										if($usertype=="admin"){
											
											?>
                                        
                                     	  <li> 

	  	  	  	 <a  id="more" class="btn btn-info" target="_blank" href="<?php echo base_url();?>user/editjournalentry?randomitemidentifier=<?php   {echo  $id;}  ?>">

                                                <i class="glyphicon glyphicon-pencil"></i>
																Reconcile/Update
                                                </a>
                                                        </li>
										   <li class="divider"></li>

											  <li> 
										 <a class="btn btn-danger managebtn" id="managebtndelete"		 data-id='<?php echo  $c->id;?>'    data-toggle='modal' data-target='#deleteModel<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Delete
                                                </a>
                                                        </li>
														
									
										<?php
										}
										?>
                                     
                                        
                                    </ul>
										
                                </div>
</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>
    <th></th>
    <th></th>

                 </tr>
         

       <tbody> </table>
	   
        <div class="col-md-12 text-center">    <?php echo $links; ?>
					   		<span style="color:red; font-size:20px"><?php  echo $total_rows. "   Loggs. " ;?>   </span>

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

			
			</div>
		</div>
  
  </div>
  
  
	<div id="accountModal" 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">Account report</h4>
      </div>
      <div class="modal-body">
      
	  	

				<?PHP
//$session_data = $this->session->userdata('logged_in');
 //$mydate=date("Y-m-d");
 					 // $mydate=date("Y-m-d H:i:s");
 $fromdate=date("Y-m-d 00:00:00");


				$month= Date('Y-m');
			$fromdate=$month."-01";
				$date=$month."-30";
				
				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/viewaccount' , 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="branchid"  id="branchid" required>
	
	
	<option value=""  >---Select Branch/Counter Name--</option>
<?php
									 if( $viewallaction==true){
										 ?>
					<option value="all"  >All branches/Counters</option>
									<?php
									 }
							
	?>
	
	<?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="inputbankname" class="col-sm-2 control-label">Bank name?</label>
    <div class="col-sm-10">
	<select class="form-control" name="bankname" required>
	
	<option value=""  >---Select bank name---</option>
		<option value="all"  selected="selected">---All banks ---</option>

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

  
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
		 $data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
					 
										$banking= $this->usermodel->populatealldatanoarrayorderbydata('glaccounts','companyid',$companyid,'id >',0,'accountname',"ASC");


	
if(is_array($banking)) {

   foreach($banking as $bankingrow){

   //echo $courserow->coursename;
    ?>
			<option value="<?=  $bankingrow->number;   ?>"><?=  $bankingrow->accountname ."(Acc No:". $bankingrow->number ."-Balance: ".$bankingrow->amount.")"; ?></option>



	<?php

}} else {
    echo 'No bank available.';
}
	
?>
</select>
		
						<span class="text-danger"><?php echo form_error('bankname'); ?>

	</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="text" name="startdate" value="<?php echo set_value('startdate',$fromdate." 00:00:00"); ?>" 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="inputdownload" class="col-sm-2 control-label">Download?</label>
    <div class="col-sm-10">
	<select class="form-control" name="download" required>
	
	<option value=""  >---Select your option---</option>

		<option value="no" selected="selected" >--I want to view---</option>
			<option value="yes"  >--I want to download ---</option>

</select>
		

	</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="text" name="enddate" value="<?php echo set_value('enddate',$date." 23:59:59"); ?>" class="form-control" required placeholder="Enter End date">
		 
				
		<span class="text-danger"> <?php echo form_error('enddate'); ?>
		
		</span>
	</div>
  </div>
  
  
   
	

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="accounts" name="btn_viewaccounts" class="btn btn-primary"> View Cash flow</button>

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

    

				</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/generalledger' , 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>
<?php
									 if( $viewallaction==true){
										 ?>
					<option value="all"  >All branches/Counters</option>
									<?php
									 }
							
	?>
	
	<?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 id="deleteModel" 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">Delete</h4>
      </div>
      <div class="modal-body">
        <h3>Are you sure you want to delete this item? </h3>
      </div>
      <div class="modal-footer">
	  	

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

		
                 echo form_open('user/deletebyid' , array('class' => 'form-horizontal ', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>
 <input type="hidden" id="table"name="table" class="table" placeholder="table" value="debitcredit">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="user/generalledger">
 <input type="hidden" id="itemid1"name="itemid" class="itemid" placeholder="itemid" value=""><br>
 <button type="button" class="btn btn-success" data-dismiss="modal">No</button>
 		  	         <button type="submit" name="btn_delete" value="deletebyid" class="btn btn-danger"> Delete  </button>

	<?php echo form_close();?>
      </div>
    </div>

  </div>

  </div>		
	
	
			
			
		
		
  

 
</div>


















