

         <script type="text/javascript">
  
		
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		  
		   
        });
		
		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/viewpurchases";
		alert(" printing...........");
    }else {

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

		    // document.body.innerHTML = originalContents;

	}
}


		
    </script> 

  <style type="text/css">
  
  

    #printable { display: none; }

    #myprint { display: none; }
#print{  	


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


}


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

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


}
    
    @media print
    {
    	#non-printable { display: none; }
    	#printableArea { display: block; font-size:16; width:100%; }
		    	#myprint { display: block; font-size:16; width:100%; }
				 #printable { display: block; }

    }
    </style>

 <div class="row">
  
   	

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

  
		<div class="panel panel-default" data-collapsed="0">
        	<div class="panel-heading"  id="non-printable">
            	<div class="panel-title" id="redcolor" >
            		<i class="entypo-plus-circled"></i>
				 <span class="pull-right"> View purchases</span>
	  
<a href="<?php echo base_url(); ?>user/viewpurchases" class="btn btn-success">Back to purchases</a>
	

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

			
	<div class="widget-content nopadding table_holder table-responsive" >				
				<?PHP
 echo $this->session->flashdata('deletemsg'); 
	 $session_data = $this->session->userdata('logged_in');

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
$data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];	
	    $addproductaction=$this->usermodel->populatuserpermissionsdataarray('purchases','add',$userid);

	 $updateaction=$this->usermodel->populatuserpermissionsdataarray('purchases','update',$userid);
  $updatebuyingpriceaction=$this->usermodel->populatuserpermissionsdataarray('purchases','updatebuyingprice',$userid);
  $deleteaction=$this->usermodel->populatuserpermissionsdataarray('purchases','delete',$userid);
  $updatesellingpriceaction=$this->usermodel->populatuserpermissionsdataarray('purchases','updatesellingprice',$userid);
    $updateclosedinvoiceaction=$this->usermodel->populatuserpermissionsdataarray('purchases','updateclosedinvoice',$userid);
		  	 					 $currentdate=date("Y-m-d H:i:s");

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;
					}
				echo $this->session->flashdata('msg'); 
								?>	
					<div class="row">
						<div class="col-md-12">
							
							<div class="panel-body">
	<div id="printableArea">	
									
				<table class="tablesorter table table-bordered  table-hover" id="sortable_table">			

             <thead>
			 
			 <td colspan="14" width="100%">
	<center>
					
										<BR><B>MAKE PAYMENT TO SUPPLIER IN BULK OF <?PHP echo $originalamount; ?>  </B>
		</center>	
		</td>
         <tr>
		 			<th> Supplier </th>

		 					<th> Invoice Date </th>

  <th> Invoice No </th>
			<th> Amount </th>
						<th> Paid </th>

					<th> Balance </th>


			<th> Paid Date </th>

														<th> Description </th>

											<th> Amount to pay </th>
											<th> Bank </th>
											<th> Pay? </th>

		


                 </tr>
             </thead>
<?php
  $ttoriginal=$originalamount;
    $totalamount=0;
     $balance=0;
   $ttpaid=0;
   $ttbalance=0;
 if(!is_array($viewpurchases)) 

 {


   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 

   
  	foreach ($viewpurchases as $c): 

		 
				  $ttoriginal= $ttoriginal-$balance;	
		
                 echo form_open('user/bulksuplierpayment' , 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;?>


             <tr>
                
            <?php 
$id=$c->id;
$invoice_number=$c->invoice;
$totalamount=$totalamount+$c->amount ; 
?>
	   <td>
	   	   											<input type="hidden" name="myid[]" id="myid" value="<?php echo set_value('id',$c->id); ?>" class="form-control" required placeholder="myid" >
	   											<input type="hidden" name="originalamount" id="originalamount" value="<?php echo set_value('originalamount',$originalamount); ?>" class="form-control" required placeholder="paid" >

	   											<input type="hidden" name="supplier[]" id="supplier" value="<?php echo set_value('supplier',$c->supplier); ?>" class="form-control" required placeholder="supplier" >
	   											<input type="hidden" name="invoice[]" id="invoice" value="<?php echo set_value('invoice',$c->invoice); ?>" class="form-control" required placeholder="invoice" >
	   											<input type="hidden" name="amount[]" id="amount" value="<?php echo set_value('amount',$c->amount); ?>" class="form-control" required placeholder="amount" >
	   											<input type="hidden" name="paid[]" id="paid" value="<?php echo set_value('paid',$c->paid); ?>" class="form-control" required placeholder="paid" >
					  	<input type="hidden" name="paymentmethodes[]" value="n/a"id="invoice1" class="form-control" required placeholder="Enter invoice">
					  	<input type="hidden" name="transactioncode" value="<?php echo set_value('transactioncode',$transactioncode); ?>"id="transactioncode" class="form-control" required placeholder="Enter invoice">

	 
	 	  	 <a  id="non-printable"  href="<?php echo base_url();?>user/viewmorestockbyinvoiceno?randomitemidentifier=<?php   {echo  $invoice_number;}  ?>">

	
	 <?php  $userids= $c->supplier ;

$myuser=$this->usermodel->getpeople($userids);
   echo $myname=$myuser[0]['company'];
$mydescription="Payment to ".$myname;
  ?>

  </a>
    <span id="printable">  <?php  echo $myname;?></span>
  </td>

              
     <td><?php echo $c->fromdate ; ?></td>

    <td><?php echo $c->invoice ; ?></td>
  <td><?php echo $c->amount ; ?></td>
    <td><?php echo $c->paid ; ?></td>
	    <td><?php 
		$balance=(double)$c->amount-(double)$c->paid ;
		 $ttpaid= (double)$ttpaid+(double)$c->paid;
   $ttbalance=  (double)$ttbalance+(double)$balance;

		echo $balance; 
		   $payment=0;
		   
		   
		   if($ttoriginal >= $balance){
			    $payment=$balance;
			   
		
		   }else{
			   
			   if($ttoriginal>0){
				      $payment=$ttoriginal;
			   }else{
				   
				     $payment=0;
			   }
			   
			   
			   
		   }

	
		
		?></td>

    <td>
<input type="text" name="paiddate[]" id="paiddate" value="<?php echo set_value('paiddate',$PAYMENTDATE); ?>" class="form-control" required placeholder="enter paid date" >

	
	</td>
	<td>
	  <input type="text" name="description[]" id="description" value="<?php echo set_value('description',$mydescription); ?>" class="form-control" required placeholder="Enter description" >

	  </td>
	 <td>
	  
	 <input type="text" name="payment[]" id="payment" value="<?php echo set_value('payment',$payment); ?>" class="form-control" required placeholder="Enter amount to pay" >

	  </td>
    <td>
 
	<select class="form-control" name="bankname[]" required>
	

<option value=""  >---Select Bank---</option>
<?php 

 $bankname=$bankname;

					 
										$bank= $this->usermodel->populateall('glaccounts','number',$bankname);


	
if(is_array($bank)) {

   foreach($bank as $bankrow){

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



	<?php

}} else {
    echo 'No bank available.';
}
	
?>
		
</select>
		
		
	
	</td>


	
	 
	  <td>
	  <select class="form-control" name="makepayment[]" required>
	<option value="yes"  >Make payment?</option>


<option value="yes"  selected="selected">Yes</option>
<option value="no"  >No</option>


</select>
		
		
	 
   </td>

                  
             </tr>


	<?php endforeach;} ?>
	
	
	 
             
 								<tr border="1" background="green">
									<td colspan="3"><b>Total amount</b></td>
 
									<td>
<?php if(isset($totalamount)) {echo formatMoney($totalamount, true);   }?>

									</td>
									
							<td>
<?php if(isset($ttpaid)) {echo formatMoney($ttpaid, true);   }?>

									</td>
	<td>
<?php if(isset($ttbalance)) {echo formatMoney($ttbalance, true);   }?>

									</td>									
									
									

	<td colspan="4"><b>BALNCE: <?PHP 	   echo (double)$ttbalance-(double)$originalamount; ?></b>
	
	
	CODE: <?PHP 	   echo $transactioncode; ?>
	</td>								
</tr>
	
	
	 	<tr>
			<td colspan="3"> </td>


				<td colspan="3">			

								 <button type="submit"  value="bulkpayment" name="btn_bulksuplierpayment" class="btn btn-primary"> <span class="glyphicon glyphicon-pencil"></span>Make Bulk Payment </a>   </button>
	
								</td>
								<td colspan="6"> </td>
								
	
	</TR>
				 							<?php echo form_close();?>	



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

	
	
	
	
  </div>
			
			
			
		
		
  

 
</div>


















