

         <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>
	<form name="print" method="post" action="">
 
 <div class="row">

 

   	<div class="col-md-6">
				
	
</div>
   	<div class="col-md-6">
<input type="submit" id="print"  accesskey="p" class="btn btn-primary"  name="print"onclick="printDiv('printableArea')" value="print receipt!" />
</div></div>
</form>

            	</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);

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>
			 <tr>
			 <td colspan="14" width="100%">
	<center>
					
										<?php $bussinessname=$configuration[0]['businessname']; if(isset($bussinessname)) {echo   $bussinessname; }?>
										<BR><B>PURCHASES REPORT FOR
										<?php

						 if(($supplier!=0)||($supplier!="")){
							
							
							$mysupplier=$this->usermodel->populateallarray('people','id', $supplier);
						
						if($mysupplier[0]['company']!=""){
												echo$comments=$mysupplier[0]['company'];
	
						}else{
												echo$comments=$mysupplier[0]['firstname'];
	
						}
						
						if($mysupplier[0]['idno']!=""){
												echo "</br> IDNO/PIN".$comments=$mysupplier[0]['idno'];
	
						}
							if($mysupplier[0]['phone']!=""){
												echo "</br> Phone".$comments=$mysupplier[0]['phone'];
	
						}
						 }  
						
							 if($groupdata!="all"){
								 												echo$groupdata;

							 }
						
							 
						 
							?>
							 </B>
		</center>	
		</td>
		</tr>
         <tr>
		  
		     <th> # </th>

  <th> Supplier</th>
    		     <th> Qty </th>

			<th> Amount </th>
						<th> Paid </th>

									<th> Balance </th>

			<th>  Date </th>
			
					<th  id="non-printable">More</th>

		


                 </tr>
             </thead>
<?php
 if(!is_array($viewpurchases)) {
				    echo '<div class="alert alert-danger text-center">There was no purchase found in the system</div>';

			 }else{
 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 
  $totalamount=0;
    $ttqty=0;
	   $i=0;

   $ttpaid=0;
   $ttbalance=0;
    $ttvat=0;
$tttaxable=0;
  	foreach ($viewpurchases as $c): 
		 	   $i++;

		  $ttvat= $ttvat+$c->vat ;
	        $tttaxable= $tttaxable+$c->taxable ;

             ?>



             <tr>
                
            <?php 
$id=$c->id;
$invoice_number=$c->invoice;
$totalamount=$totalamount+$c->amount ; 

//$counter= $this->usermodel->Getqty($companyid,$invoice_number);
		
//$myqty=$counter[0]["myqty"];
$myqty=$c->qty ;


     $ttqty=$ttqty+$myqty;
?>

              
 
  
  <td>
  <?php echo $i; ?>
  </td>

	 <td>
	 
	 	  	 <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'];

  ?>

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

  <td><?php echo $c->amount ; ?></td>
    <td><?php echo $c->paid ; ?></td>
	    <td><?php 
		$balance=$c->amount-$c->paid ;
		 $ttpaid= $ttpaid+$c->paid;
   $ttbalance=  $ttbalance+$balance;
		echo $balance; ?></td>
   
     <td><?php echo $c->fromdate ; ?></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 -->
                                      
										
                     <a  id="more" target="_blank" class="btn btn-primary" href="<?php echo base_url();?>user/viewmypurchases?randomitemidentifier=<?php   {echo  $userids;}  ?>">  

						 


                                                <i class="glyphicon glyphicon-pencil"></i>
Pending Invoices                                                </a>
                                                        </li>
                                        
                                    </ul>
										
                                </div>
</td>
                  
             </tr>

	<?php endforeach;} ?>

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

									</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="2"></td>								
</tr>
	
        </table>
	
	</div>
	</div>

	
	
	
	
			<div id="purchaseModal" 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">Purchases Report</h4>
      </div>
      <div class="modal-body">
      
	  	

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

				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/viewpurchasereport' , 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="inputfromdate" class="col-sm-2 control-label">From Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="fromdate" value="<?php echo set_value('fromdate',$frommydate); ?>" class="form-control" required placeholder="Enter start date">
		 
				
		<span class="text-danger"> <?php echo form_error('fromdate'); ?>
		
		</span>
	</div>
  </div>
  
  	<div class="form-group">
    <label for="inputtodate" class="col-sm-2 control-label">	To Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="todate" value="<?php echo set_value('todate',$mydate); ?>" class="form-control" required placeholder="Enter End date">
		 
				
		<span class="text-danger"> <?php echo form_error('todate'); ?>
		
		</span>
	</div>
  </div>
  
  
    <div class="form-group">
    <label for="inputsupplier" class="col-sm-2 control-label">supplier?</label>
    <div class="col-sm-10">
	<select class="form-control" name="supplier" required>
	
	<option value=""  >---Select supplier---</option>

		<option value="all"  >--I want view all/any supplier---</option>
	<?php 
					 
			$mysuppliers =  $this->usermodel->populatemysupplier($companyid);
	

	
if(is_array($mysuppliers)) {

   foreach($mysuppliers as $suppliersrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $suppliersrow->id;   ?>"><?=  $suppliersrow->company ."(". $suppliersrow->firstname ."- ".$suppliersrow->phone.")"; ?></option>



	<?php

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

	</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 the purchases---</option>
			<option value="yes"  >--I want to download the purchases---</option>

</select>
		

	</div>
  </diV>

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="event" name="btn_addevent" class="btn btn-primary"> View Purchases  </button>

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

    

				</div>

		</div>
	    </div>
    </div>	
	
	
	
	
	
	
	
	
	
	
	
	<div id="deleteModal" 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="view" value="purchaseorder">

 <input type="hidden" id="view"name="view" class="view" placeholder="view" value="user/viewpurchases">
 <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 id="uploadModal" 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">Please Upload Correct Products data(CSV)</h4>
		
      </div>
      <div class="modal-body">
      
	  	

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



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/uploadpurchases' , 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;?>
<input type="hidden" name="type" value="product"id="type" class="form-control" required placeholder="Enter type">
				<input type="hidden" name="view" value="user/viewpurchases"id="view" class="form-control" required placeholder="Enter view">
	
	
	<div class="form-group">
    <label for="inputsurname" class="col-sm-2 control-label">	CSV LIST</label>
    <div class="col-sm-10">
		
			<input type="file" name="file" width="400"  value="<?php echo set_value('file') ;?>" placeholder="Select EXCELL" class="form-control" required placeholder="Enter Surname"  >

		  		
				
		<span class="text-danger"> Upload correct format of CSV File  here..<?php echo form_error('file'); ?>
		
		</span>
	</div>
  </div>	
  
	

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="uploadpurchases" name="btn_uploadpurchases" class="btn btn-primary">Upload new purchases  </button>

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

    

				</div>

		</div>
	    </div>
    </div>
	
	<div id="addModal" 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">Add new Purchases</h4>
      </div>
      <div class="modal-body">
      
	  	

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



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/addpurchases' , 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="inputinvoice_number" class="col-sm-2 control-label">	Invoice Number :  </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="invoice_number" value="<?php echo set_value('invoice_number'); ?>" class="form-control"  placeholder="Enter invoice_number">
		 
				
		<span class="text-danger"> <?php echo form_error('invoice_number'); ?>
		
		</span>
	</div>
  </div>
  
  
  <div class="form-group">
    <label for="inputfromdate" class="col-sm-2 control-label">Invoice Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="fromdate" value="<?php echo set_value('fromdate',$mydate); ?>" class="form-control" required placeholder="Enter Entry date">
		 
				
		<span class="text-danger"> <?php echo form_error('fromdate'); ?>
		
		</span>
	</div>
  </div>
  
  
  <div class="form-group">
    <label for="inputsupplier" class="col-sm-2 control-label">supplier?</label>
    <div class="col-sm-10">
	<select class="form-control" name="supplier" required>
	
	<option value=""  >---Select supplier---</option>

	
	<?php 
					 
			$mysuppliers =  $this->usermodel->populatemysupplier($companyid);
	

	
if(is_array($mysuppliers)) {

   foreach($mysuppliers as $suppliersrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $suppliersrow->id;   ?>"><?=  $suppliersrow->company ."(". $suppliersrow->firstname ."- ".$suppliersrow->phone.")"; ?></option>



	<?php

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

	</div>
  </div>
  
  
  
  
  
  
  
  	<div class="form-group">
    <label for="inputpin" class="col-sm-2 control-label">	Supplier Pin :  </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="pin" value="<?php echo set_value('pin'); ?>" class="form-control"  placeholder="Enter supplier PIN">
		 
				
		<span class="text-danger"> <?php echo form_error('pin'); ?>
		
		</span>
	</div>
  </div>
  
  
  
  
  
  

  
  	<div class="form-group">
    <label for="inputpaiddate" class="col-sm-2 control-label">Payment Date</label>
    <div class="col-sm-10">
	
		  		<input type="text" name="paiddate" value="<?php echo set_value('paiddate',$mydate); ?>" class="form-control" required placeholder="Enter Payment Date">
		 
				
		<span class="text-danger"> <?php echo form_error('paiddate'); ?>
		
		</span>
	</div>
  </div>
  
    	<div class="form-group">
    <label for="inputamount" class="col-sm-2 control-label">Total Amount :  </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="amount" value="<?php echo set_value('amount'); ?>" class="form-control" required placeholder="Enter Your Total amount used">
		 
				
		<span class="text-danger"> <?php echo form_error('amount'); ?>
		
		</span>
	</div>
  </div>
  
  
  
  
   <div class="form-group">
    <label for="inputvattype" class="col-sm-2 control-label">vat type?</label>
    <div class="col-sm-10">
	<select class="form-control" name="vattype" required>
	
	<option value=""  >---Is this purchase inclusive---</option>

		<option value="VATABLE"  >VATABLE</option>
			<option value="ZERO RATED"  >ZERO RATED</option>
				<option value="ZERO RATED"  >EXEMPTED</option>
	
</select>
		
						<span class="text-danger"><?php echo form_error('vattype'); ?>

	</div>
  </div>
  

	

  
  
  
  
  
      	<div class="form-group">
    <label for="inputpin" class="col-sm-2 control-label">	VAT Rate  </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="vatrate" value="16" class="form-control"  placeholder="Enter vat rate (%)">
		 
				
		<span class="text-danger"> <?php echo form_error('vatrate'); ?>
		
		</span>
	</div>
  </div>
 <div class="form-group">
    <label for="inputvat" class="col-sm-2 control-label">  VAT Amount :  </label>
    <div class="col-sm-10">
	
		  		<input type="text" readonly name="vat" value="<?php echo set_value('vat'); ?>" class="form-control" required placeholder="This is automatic upon saving">
		 
				
		<span class="text-danger"> <?php echo form_error('vat'); ?>
		
		</span>
	</div>
  </div>
   <div class="form-group">
    <label for="inputtaxable" class="col-sm-2 control-label">Taxable  Amount :  </label>
    <div class="col-sm-10">
	
		  		<input type="text" readonly name="taxable" value="<?php echo set_value('taxable'); ?>" class="form-control" required placeholder="This is automatic upon saving">
		 
				
		<span class="text-danger"> <?php echo form_error('taxable'); ?>
		
		</span>
	</div>
  </div>
  
	<div class="form-group">
    <label for="inputremarks" class="col-sm-2 control-label">	Remarks </label>
    <div class="col-sm-10">

				<textarea name="remarks" value="<?php echo set_value('remarks'); ?>"  class="form-control"  placeholder="Enter remarks"></textarea>
			
		<span class="text-danger"> <?php echo form_error('remarks'); ?>
		
		</span>
	</div>
  </div>
		

	

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="purchase" name="btn_purchase" class="btn btn-primary"> Add purchase   </button>

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

    

				</div>

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

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

 
</div>


















