<link href="<?php echo base_url(); ?>assets/autocomplete/jquery-ui.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/autocomplete/ui.theme.css" rel="stylesheet">
    <link href="<?php echo base_url(); ?>assets/autocomplete/autocomplete.css" rel="stylesheet">
    <script src="<?php echo base_url(); ?>assets/autocomplete/jquery-ui.min.js"></script>
	
<!--
		 <script src="<?php echo base_url(); ?>assets/autocomplete/jquery.min.js"></script>


 -->

 
            
        <script type="text/javascript">  
		
		
		
		
			 $(document).ready(function() { 
			   $("#originalamount").hide();
               $("#bankname").hide();
          $("#transactioncode").hide();
          $("#PAYMENTDATE").hide();

					});
					
		
				
		         $(function () {
        $("#payment").change(function () {
            if ($(this).val() == "yes") {
            
			
               $("#bankname").show();
              					   $("#transactioncode").show();
           $("#PAYMENTDATE").show();

                     $("#originalamount").show();

            } else {
               			   $("#transactioncode").hide();
                     $("#originalamount").hide();
          $("#PAYMENTDATE").hide();

			$("#bankname").hide();

            
			
            }
        });
    });
		
		
		
		
		
  
		 $(this).ready( function() {  
            $("#id").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/purchaselookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });
		
		
		
		
			$(this).ready( function() {  
            $("#supplier").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/customerlookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });
		
		
		
		
		
		
			
		
		$(this).ready( function() {  
            $("#mysupplierid").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/customerlookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });
		
		
		
		
		
		
		$(this).ready( function() {  
            $("#mysupplier").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
					//  url: "<?php echo base_url(); ?>Systemusers/customerSaleslookup",  

                       url: "<?php echo base_url(); ?>Systemusers/customerlookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });
		
			$(this).ready( function() {  
            $("#mysupplier2").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/customerlookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });
		
			$(this).ready( function() {  
            $("#mysupplier1").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/customerSaleslookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });
		
    </script>  
	
         <script type="text/javascript">
  
		
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		  
		   
        });
		
		
		
    </script> 

         <script type="text/javascript">
  
		$(document).on("click", "#editbtn", function()
        {
          var mycategoryid = $(this).data('id');
		  $("#mycategoryid").val(mycategoryid); 
		       var paid = $(this).data('paid');
		   $("#paid").val(paid);
		    var ordernumber = $(this).data('ordernumber');
		   $("#ordernumber").val(ordernumber);
  		      var status = $(this).data('status');
		   $("#status").val(status);
   var shippingto = $(this).data('shippingto');
		   $("#shippingto").val(shippingto);
 
		    var remarks = $(this).data('remarks');
		   $("#remarks").val(remarks); 
		   
		     var taxable = $(this).data('taxable');
		   $("#taxable").val(taxable); 
		   
		     var vat = $(this).data('vat');
		   $("#vat").val(vat);
 
		    var vatrate = $(this).data('vatrate');
		   $("#vatrate").val(vatrate); 
		   
		     var amount = $(this).data('amount');
		   $("#amount").val(amount); 
		     var paiddate = $(this).data('paiddate');
		   $("#paiddate").val(paiddate);
 
		    var pin = $(this).data('pin');
		   $("#pin").val(pin); 
		   
		     var fromdate = $(this).data('fromdate');
		   $("#fromdate").val(fromdate); 
		 
		   var invoice_number = $(this).data('invoice_number');
		   $("#invoice_number").val(invoice_number); 

		     var supplier = $(this).data('supplier');
		   $("#supplier").val(supplier); 
		  
		   		     var branchid = $(this).data('branchid');
		   $("#branchid").val(branchid); 
		  
		  
		     var withholdingamount = $(this).data('withholdingamount');
		   $("#withholdingamount").val(withholdingamount); 
		  
		   		     var withholdingrate = $(this).data('withholdingrate');
		   $("#withholdingrate").val(withholdingrate); 
		   
		   
		   
        });
		
		
		
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		  
		   
        });
			$(document).on("click", "#paybtn", function()
        {
          var billid = $(this).data('id');
		  $("#billid").val(billid); 
		   
		     var amount = $(this).data('amount');
		   $("#amount1").val(amount); 
		      var 	paid = $(this).data('paid');
		   $("#paid1").val(paid); 
   var invoice = $(this).data('invoice');
		   $("#invoice1").val(invoice); 
		   
		   
		     var balance = $(this).data('balance');
		   $("#balance1").val(balance); 
		 
		  
		  
		   
        });
			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/startsales";
		alert(" printing...........");
    }else {

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

		    // document.body.innerHTML = originalContents;

	}
}
		
    </script>  
	
	
	

         <script type="text/javascript">
		
		
		              $(function () {
        $("#currency").change(function () {
            if ($(this).val() != "") {
            
			var tempcurrencytype = $("#currency").val() ;

 const getcurrencyvalue = tempcurrencytype.split(":=");
let toamount = getcurrencyvalue[0];
let mytocurrency = getcurrencyvalue[1];
  	 var myfinaltotals = document.getElementById('myfinaltotal').value;

  let finalcurrency= 0;
finalcurrency=toamount*myfinaltotals;
  finalcurrency = finalcurrency.toFixed(2);
            document.getElementById("tocurrencyamount").value = finalcurrency;
		document.getElementById("tocurrency").value = mytocurrency;
			













            } else {
             alert("No currency selected or set. Try again");
			$("#mytable").hide();

            
			
            }
        });
    });
	
	
	
	
	
	
	
	
	
	$(this).ready( function() {  
            $("#client").autocomplete({  
 
                minLength: 1,  
                source:   
                function(req, add){  
                    $.ajax({  
                        url: "<?php echo base_url(); ?>Systemusers/customerSaleslookup",  
                        dataType: 'json',  
                        type: 'POST',  
                        data: req,  
                        success:      
                        function(data){  
                            if(data.response =="true"){  
                                add(data.message);  
                                console.log(data);
                            }  
                        },  
                    });  
                },  
                     
            });  
        });
		
		
		
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
		    </script>  

  <style type="text/css">
  
  

    #printableArea { display: none; }
#print{  	


    background-repeat: no-repeat;
	font-size;20px;
  
    width:100%; 


}

#sale{  	


    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%; }

    }
    </style>
 
 <div class="row">
  
   	

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

  				<?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'];	
	 
	 
				$data['branchid'] = $session_data['branchid'];
	 $branchid = $data['branchid'];
	    $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);



	   	      $viewdirectpurchases=$this->usermodel->populatuserpermissionsdataarray('purchases','viewdirectpurchases',$userid);
	   	      $viewserials=$this->usermodel->populatuserpermissionsdataarray('purchases','viewserials',$userid);

	   $viewquotation=$this->usermodel->populatuserpermissionsdataarray('purchases','viewquotation',$userid);
  $viewpurchase=$this->usermodel->populatuserpermissionsdataarray('purchases','viewpurchase',$userid);
   $salesorder=$this->usermodel->populatuserpermissionsdataarray('purchases','salesorder',$userid);

  $budget=$this->usermodel->populatuserpermissionsdataarray('purchases','budget',$userid);
    $addpeople=$this->usermodel->populatuserpermissionsdataarray('members','add',$userid);

  
$viewdebtors=$this->usermodel->populatuserpermissionsdataarray('incomeexpenses','viewdebtors',$userid);
  $viewcreditors=$this->usermodel->populatuserpermissionsdataarray('incomeexpenses','viewcreditors',$userid);
  
	   $viewallcounters=$this->usermodel->populatuserpermissionsdataarray('purchases','viewallcounters',$userid);

	  	 $smsconfig = $this->usermodel->populateallarray('smsconfig','id',$companyid);
		 	  $tax1rate=$smsconfig[0]['tax1rate'];	

  $new_date1=date("Y-m-d H:i:00");
					 $duedates=   date('Y-m-d H:i:00',strtotime('+30 days',strtotime($new_date1)));


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;
					}
					
						$configuration = $this->usermodel->populateallarray('smsconfig','id',$companyid);

$symbol=$configuration[0]["currencysymbol"];
$multicurrency=$configuration[0]["currency"];	
					
												$etims=$smsconfig[0]["hscode"];
				
					
					
					
					
					
					
								?>
		<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 data-toggle='modal' data-target='#addModal' class="btn btn-default">Add New Purchase </a>
	  	  <a data-toggle='modal' data-target='#addCreditNoteModal' class="btn btn-default">Add Credit Note </a>

				 				 	  <a data-toggle='modal' data-target='#purchaseModal' class="btn btn-default">Search for purchases</a>
 				 				 	  <a data-toggle='modal' data-target='#itempurchaseModal' class="btn btn-warning">Search for item purchases/Expiry</a>

  <a data-toggle='modal' data-target='#uploadopeningbalancesModal' class="btn btn-default">Upload Supplier Opening Balance  </a>

 <a data-toggle='modal' data-target='#uploadModal' class="btn btn-default">Upload purchased products  </a>



 <a data-toggle='modal' data-target='#uploadMasterModal' class="btn btn-default">Upload purchased Master </a>



 <div class="collapse navbar-collapse" id="app-navbar-collapse" ID="non-printable">
                <!-- Left Side Of Navbar -->
                <ul class="nav navbar-nav">
				 <?php

 if( $viewserials==true){
 ?>
				   <li><a href="<?php echo base_url(); ?>user/viewserialnumbers">View Serials </a></li>

 
<?php	
}
  ?>
  
   <?php

 if( $viewdirectpurchases==true){
 ?>
                    <li><a href="<?php echo base_url(); ?>user/viewpurchases">View Purchase</a></li>

 
<?php	
}
  ?>
 <?php

 if( $viewquotation==true){



 ?>
                   <li><a href="<?php echo base_url(); ?>user/allquatation">View Quotation</a></li>

 
<?php	
}
  ?>
	  <?php

 if( $salesorder==true){
 ?>
 <!--
 	  	  				 	  	                    <li> <a href="<?php echo base_url(); ?>user/salesorder"> Sales order</a>	</li>

-->
 
<?php	
}
  ?>
  
  
  
   <?php

 if( $viewpurchase==true){
 ?>
 	  	  				 	  	  			                   <li> <a href="<?php echo base_url(); ?>user/allpurchaseorder">Purchases order</a>	</li>


 
<?php	
}
  ?>
  
  
  
    
   <?php

 if( $budget==true){
 ?>
  	  	  <!--  <li> <a href="<?php echo base_url(); ?>user/getpaymentsdkpush?invoice_number=2147483647&myview=user/viewsales"> test</a>	</li>-->

 	  	  				 	  	  			                   <li> <a href="<?php echo base_url(); ?>user/viewbudget"> Budget</a>	</li>

 
<?php	
}
  ?>
  
  
  
	
	  <?php

 if( $addpeople==true){
 ?>
                         <a data-toggle='modal' data-target='#addsupplierModal' class="btn btn-default">Add new supplier </a>

 
<?php	
}
  ?>
	  		


  <?php

 if( $viewdebtors==true){
 ?>
 	  	  				 <a href="<?php echo base_url();?>user/allcreditors" class="btn btn-default"> All Debtors</a>

 
<?php	
}
  ?>
	  <?php

 if( $viewcreditors==true){
 ?>
 						 	  	  				 <a href="<?php echo base_url();?>user/viewallcreditors" class="btn btn-default"> All Creditors</a>

 
<?php	
}
  ?>			

							   <a data-toggle='modal' data-target='#updatemyModal' class="btn btn-default">Update Balances  </a>
	  <?php
 if ($etims =="EnableEtims"){
?>
 <a data-toggle='modal' data-target='#downloadetimspurchaseModal' class="btn btn-success">Download Etims Purchase </a>
 <a data-toggle='modal' data-target='#downloadetimspurchaseimportModal' class="btn btn-success">Download Etims Imports </a>
<?php

 }
							   
 ?>
	

                </ul>
					

                <!-- Right Side Of Navbar -->
            	 <div class="pull-right"  id="non-printable">
<form name="print" method="post" action="">
 <input type="submit" id="print"  accesskey="p" class="btn btn-default"  name="print"onclick="printDiv('sortable_table')" value="print receipt!" />
</form></div>
            </div>
			
			

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

			
	<div class="widget-content nopadding table_holder table-responsive" >				
	
					<div class="row">
						<div class="col-md-12">
									<div class="row">
						<div class="col-md-12" id="non-printable">
													<center> <b style="color:red">Welcome to Direct Purchases /Receiving of stock Window </b></center>

<?php 

		 echo $this->session->flashdata('msg'); 
        $attr = array("class" => "form-horizontal", "role" => "form", "id" => "search", "name" => "search");
        echo form_open("user/searchallmysalesorder", $attr);?>
	

            				<input type="hidden" name="view" value="userdata/viewpurchases" id="view" class="form-control" required placeholder="Enter status">

			
                <div class="col-md-9">
                    <input class="form-control" id="searchterm" name="searchterm" placeholder="General search.." type="text" value="<?php echo set_value('searchterm'); ?>" />
                </div>
                  <div class="col-md-3">
                    <input id="btn_search" name="btn_search" type="submit" class="btn btn-default" value="Search" />
                    <a href="<?php echo base_url(). "user/viewpurchases"; ?>" class="btn btn-default">Refresh</a>
              
			
        <?php echo form_close(); ?>
		  </div>
			 </div>	
                 </div>
							<div class="panel-body">
	
									
				<table class="tablesorter table table-bordered  table-hover" id="sortable_table">			

             <thead>
         <tr>
			<th> SN </th>
   <th id="non-printable">View</th>
   			<th> Supplier </th>

  <th> Invoice No </th>
  		     <th> Qty </th>

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

			<th> Balance </th>
<!--
					<th> VAT </th>
							<th> Vatable </th>
							<th> Exmp </th>
<th> Zero </th>

--->
					<th> Invoice Date </th>
			<th> Payment/Due Date </th>
				<th> Pin </th>

			<th> Type </th>
						<th> Status </th>

			<th>  Order No.</th>
						<th>  User</th>
												<th>  Details</th>


								<th id="non-printable"> Pay </th>

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

		


                 </tr>
             </thead>
<?php
 
 if(!is_array($viewpurchases)) 

 {

   echo "<tr  style='margin-bottom:0px;margin-top:0px;' '>";
      echo "<td colspan='14'>";
    
       echo '<div class="alert alert-warning text-center">There no records found..</div>';
    echo "</td>";
   echo "</tr>";
    }else {
?>
    
             <?php 
  $totalamount=0;
    $ttqty=0;

   $ttpaid=0;
   $ttbalance=0;
      $ttvat=0;
$tttaxable=0;

  	foreach ($viewpurchases as $c): 
 $ttvat= $ttvat+(double)$c->vat ;
	        $tttaxable= $tttaxable+(double)$c->taxable ;
		 
$myinvoice=$c->transactionstatus;
             ?>



             <tr>
                
            <?php 
$id=$c->id;
$invoice=$c->invoice;
$totalamount=$totalamount+(double)$c->amount ;
		//$counter= $this->usermodel->Getqty($companyid,$invoice);
		$invoice_number=$c->invoice;

//$myqty=0;
$myqty=$c->qty ;

$purchasetype=$c->status ;
     $ttqty=$ttqty+(double)$myqty;

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


              
  <td id="non-printable"><?php 
  

  if(($purchasetype=="purchases")|| ($purchasetype=="creditnote")){
	  
	  
  if($invoice==""){
	 echo $c->invoice ; 
	  
  }else{
	  
	  ?>
	  	  	  	 <a  id="more" class="btn btn-default"  href="<?php echo base_url();?>user/viewreceivedproducts?randomitemidentifier=<?php   {echo  $invoice;}  ?>">Add Item </a>

  

	  
	 <?php  
  }
  }else   if($purchasetype=="Opening Balance"){
	  
  if($invoice_number==""){
	  echo $c->invoice_number ; 
	  
  }else{
	  
	  ?>
				<a  id="more" class="btn btn-default" target="_blank"  href="<?php echo base_url();?>user/searchJE?searchterm=<?php     if(isset($invoice_number)) {echo $invoice_number; } ?> "> View  </a>


	  
<?php 
  }
   
   
  }else{
	  
  if($invoice_number==""){
	  echo $c->invoice_number ; 
	  
  }else{
	  
	  ?>
	  	  	  	 <a  id="more" class="btn btn-default"  href="<?php echo base_url();?>user/viewnewpurchaseorder?randomitemidentifier=<?php   {echo  $invoice_number;}  ?>">View  </a>
	  	  	  	 <a  id="more" class="btn btn-info"  href="<?php echo base_url();?>user/viewreceivedproducts?randomitemidentifier=<?php   {echo  $invoice;}  ?>">Add Item(LPO) </a>

  

	  
<?php 
  }
   
   
  }
  ?>
  


  
  
  </td>
  
   <td>
	 
	 <a id="non-printable" href="<?php echo base_url();?>user/editmember?randomitemidentifier=<?php   {echo  $c->supplier ;}  ?>">

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

$myuser=$this->usermodel->getpeople($userids);
    $myname=$myuser[0]['company'];
     $firstname=$myuser[0]['firstname'];
   if($myname!=""){
	   echo $myname;
	   
   }else{
	   
	   echo $firstname; 
	   
   }

  ?>
  <span id="printableArea"><?   echo $firstname;   ?>  </span>
  
  </a>
  
  </td>

    <td><?php echo $c->ordernumber ; ?></td>
	      <td><?php echo $myqty ; ?></td>

  <td><?php  echo formatMoney($c->amount, true); ?></td>
      <td><?php  echo formatMoney($c->paid, true); ?></td>

    <td><?php 
		$balance=$c->amount-(double)$c->paid ;
		 $ttpaid= (double)$ttpaid+(double)$c->paid;
   $ttbalance=  (double)$ttbalance+(double)$balance;
		 echo formatMoney($balance, true);?></td>
		 
		 
	
	  
 <!--
	      <td><?php  echo formatMoney($c->vat, true); ?></td>
	      <td><?php 
		  $VATABLE=0;
		  //	$VATABLE= $this->usermodel->getvatpurchaseBytype($companyid,$invoice,"VATABLE");

//$VATABLE=$VATABLE[0]["totalvat"];
// formatMoney($VATABLE, true); 
 echo formatMoney($c->taxable, true);
		?>
		  
		  
	</td>

	  	  <td><?php
		  $EXEMPTED=0;
	//	$myEXEMPTED= $this->usermodel->getvatpurchaseBytype($companyid,$invoice,"EXEMPTED");

 //$EXEMPTED=$myEXEMPTED[0]["totalvat"];
echo formatMoney($EXEMPTED, true); 

		?>
		  
		  
		  
		  
		  </td>
		  	  <td><?php
			  		  $ZERORATED=0;

		//$myZERORATED= $this->usermodel->getvatpurchaseBytype($companyid,$invoice,"ZERO RATED");

 //$ZERORATED=$myZERORATED[0]["totalvat"];
echo formatMoney($ZERORATED, true); 

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


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


		echo $pin = $myuser[0]['idnumber'];
		if(trim($c->pin) != trim($myuser[0]['idnumber'])){
			?>
			<b style="color:red"> .</b>
			<?php 
		}

	   ?></td>

	 


	  
	  <td><?php echo $c->status ; ?></td>
	  	  <td><?php echo $c->transactionstatus ; 
		  $transactionstatus=$c->transactionstatus;
		  
		  ?></td>

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

	      <td><?php  
		 
		 	$getuser = $this->usermodel->getpeople($c->userid);

		echo $mysurname = $getuser[0]['surname']; 
		  
		  
		  
		  ?></td>
		  
		  
		  
		  
		     <td>
			 
			 
			 <?php 
			 
 
			 ?>
	 
	 <a id="non-printable" href="<?php echo base_url();?>user/searchpurchase?searchterm=<?php   {echo  $c->description ;}  ?>">

	 <?php  
	 $description= $c->description;

$myuser=$this->usermodel->getpeople($description);


if($myuser != false){
    $myname=$myuser[0]['company'];
     $firstname=$myuser[0]['firstname'];
   if($myname !=""){
	   echo $myname;
	   
   }else{
	   
	   echo $firstname; 
	   
   }
    ?>
  <span id="printableArea"><?   echo $firstname;   ?>  </span>
  
  </a>
   <?php
   
}else{
	
			echo    $c->description;
	
}
	
  ?>
 
  
  </td>
		  
		  
		  
		  
		  
		  
		  
		  
		  
		  
		  
		  
		  
		  
		  
	   
	     <td  id="non-printable">
 	 <a class="btn btn-default paybtn" id="paybtn"  data-invoice='<?php echo  $c->invoice;?>'  data-amount='<?php echo  $c->amount;?>' data-balance='<?php echo  $balance;?>' data-paid='<?php echo  $c->paid;?>'  data-id='<?php echo  $c->id;?>' data-toggle='modal' data-target='#payModel'>Payment</a> 	 
 
  
  </td>
 <td id="non-printable"> 

 
 
					<div class="btn-group">
                                    <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
                                        More <span class="caret"></span>
                                    </button>
									
									
				
								
                                    <ul class="dropdown-menu dropdown-primary pull-right" role="menu">
                                        
										      
                                     	  <li> 
										  
										  		<?php						
if($myinvoice=="closed"){
	?>
	<a  id="more" class="btn btn-primary" href="<?php echo base_url();?>user/printgrn?invoice=<?php   if(isset($invoice)) {echo $invoice; } ?>&type=receiving">  Print GRN   </a>
									   <li class="divider"></li>

	<a  id="more" class="btn btn-primary" href="<?php echo base_url();?>user/printsuppliercreditnote?invoice=<?php   if(isset($invoice)) {echo $invoice; } ?>&type=receiving">   Print Goods Return Note   </a>

								
		<?php						
}
	?>		

						<?php	

if(($updateclosedinvoiceaction==false) && ($myinvoice=="closed")){
  	?>

	<?php
 
}else{
	?>
	   <li class="divider"></li>
   <li class="divider"></li>
				<a  id="more"  class="btn btn-warning" href="<?php echo base_url();?>user/updatereceivedeals?randomitemidentifier=<?php   {echo  $invoice;}  ?>&status=suspended"> Suspend</a>

								   <li class="divider"></li>
								
			 								<a  id="more"  class="btn btn-info" href="<?php echo base_url();?>user/updatereceivedeals?randomitemidentifier=<?php   {echo  $invoice;}  ?>&status=progress"> Work in progress</a>
   <li class="divider"></li>
											 								<a  id="more"  class="btn btn-success" href="<?php echo base_url();?>user/updatereceivedeals?randomitemidentifier=<?php   {echo  $invoice;}  ?>&status=closed"> Complete/Close</a>

	
		<?php
}
	?>	
			
                                                        </li>
										   <li class="divider"></li>
										
										
										
                                        <!-- teacher EDITING LINK -->
                                      
											<?php
											
 if( $updateaction==true){											
											?>
                                        
                                     	  <li> 

	 <a class="btn btn-default editbtn" id="editbtn" data-withholdingrate='<?php echo  $c->withholdingrate;?>'data-withholdingamount='<?php echo  $c->withholdingamount;?>' data-branchid='<?php echo  $c->branchid;?>' data-status='<?php echo  $c->status;?>'    data-paid='<?php echo  $c->paid;?>'  data-supplier='<?php echo  $c->supplier;?>'   data-invoice_number='<?php echo  $c->invoice;?>' data-fromdate='<?php echo  $c->fromdate;?>' data-pin='<?php echo  $c->pin;?>' data-paiddate='<?php echo  $c->paiddate;?>' data-amount='<?php echo  $c->amount;?>'  data-vatrate='<?php echo  $c->vatrate;?>'  data-vat='<?php echo  $c->vat;?>'	 data-taxable='<?php echo  $c->taxable;?>'	 data-shippingto='<?php echo  $c->shippingto;?>' data-remarks='<?php echo  $c->description;?>'   data-ordernumber='<?php echo  $c->ordernumber;?>'  data-id='<?php echo  $c->id;?>' data-toggle='modal' data-target='#editProductModel'> 	 

                                                <i class="glyphicon glyphicon-pencil"></i>
																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='#deleteModal<?php  $c->id; ?>'>	 


                                                <i class="glyphicon glyphicon-pencil"></i>
																Delete
                                                </a>
                                                        </li>
														
														--->
														
									
										<?php
										}
										?>
                                        <li class="divider"></li>
                                      <li> 
											<?php 
								
	
											?>
	  	  	  	 <a  id="more" class="btn btn-default"  href="<?php echo base_url();?>user/viewpaidsuppliers?randomitemidentifier=<?php   {echo  $invoice;}  ?>">

						 


                                                <i class="glyphicon glyphicon-pencil"></i>
																View Payments  
                                                </a>
                                                        </li>
														
														<?php
										if($transactionstatus=="closed"){
											
											?>		
														
														
			
											
										
											
												  <li class="divider"></li>
                                        <li> 
<a  id="more" class="btn btn-primary" href="<?php echo base_url();?>user/printinternalinvoice?invoice=<?php   if(isset($c->invoice)) {echo $c->invoice; } ?>&type=receiving"> 
								 
																							 

                                                <i class="glyphicon glyphicon-pencil"></i>
																Print Internal Invoice
                                                </a>
																		
										</li>
										
	<?PHP
	}
?>
										
											
								  <li class="divider"></li>
                                        <li> 
				<a  id="more" class=" btn-success" target="_blank"  href="<?php echo base_url();?>user/searchJE?searchterm=<?php   {echo   $c->invoice;}  ?> ">
								 
																							 

                                                <i class="glyphicon glyphicon-pencil"></i>
															View	GL Transactions
                                                </a>
																		
										</li>		

		
												  <li class="divider"></li>
                                        <li> 
<a  id="more" class="btn btn-primary" href="<?php echo base_url();?>user/printsuppliercreditnote?invoice=<?php   if(isset($c->invoice)) {echo $c->invoice; } ?>"> 
								 
																							 

                                                <i class="glyphicon glyphicon-pencil"></i>
																Print Supplier Credit Note
                                                </a>
																		
										</li>										
														<li class="divider"></li>	

														  <li>
														  	 <a  id="more" class="btn btn-default" href="<?php echo base_url();?>user/viewmorerequestdocuments?randomitemidentifier=<?php   {echo  $c->invoice;;}  ?>">Upload Documets </a>

												</li>
																		
                                        
                                    </ul>
										
                                </div>
</td>
                  
             </tr>

	<?php endforeach;} ?>
	
	<tfoot>
         <tr id="non-printable">
			<th>  </th>
   <th id="non-printable">View</th>
   			<th> Supplier </th>

  <th> Invoice No </th>
  		     <th> Qty </th>

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

			<th> Balance </th>
<!--
					<th> VAT </th>
							<th> Taxable </th>
							<th> Exmp </th>
<th> Zero </th>
-->
					<th> Invoice Date </th>
			<th> Paid Date </th>
				<th> Pin </th>

			<th> Type </th>
						<th> Status </th>

			<th>  Order No.</th>
			<th id="non-printable"> User </th>
								<th id="non-printable"> Pay </th>

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

		


                 </tr>
         

            <tr border="1" background="green">
									<td colspan="4"><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>
<?php if(isset($ttvat)) {echo formatMoney($ttvat, true);   }?>

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

									</td>									
						


	<td colspan="5"></td>								
</tr>
	    </tfoot>
        </table>
		<div class="col-md-12 text-center" id="non-printable">    <?php echo $links; ?>
					   		<span style="color:red; font-size:20px"><?php  echo $total_rows. "   Purchases (s) in the system. " ;?>    </span>

        
        </div>
	</div>

	
	<div id="addModal2" 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 sub product category</h4>
      </div>
      <div class="modal-body">
      
	  	

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

				echo $this->session->flashdata('deletemsg'); 


				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/addproductcategory' , 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="inputname" class="col-sm-2 control-label">	Name </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="name" value="<?php echo set_value('name'); ?>" class="form-control" required placeholder="Enter name">
		 
				
		<span class="text-danger"> <?php echo form_error('name'); ?>
		
		</span>
	</div>
  </div>

  
  <div class="form-group">
    <label for="inputmaincategory" class="col-sm-2 control-label">Main Category?</label>
    <div class="col-sm-10">
	<select class="form-control" name="maincategory"  required>
		<option value=""  >---Select Sub-category---</option>


	
	
	<?php 
					 

					 


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

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



	<?php

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

	</div>
  </div>
  
  
	<div class="form-group">
    <label for="inputdescription" class="col-sm-2 control-label">	Order / Priority No</label>
    <div class="col-sm-10">
		  		<input type="text" name="description" value="<?php echo set_value('description'); ?>" class="form-control"  placeholder="Enter Order / Priority No">

			
		<span class="text-danger"> <?php echo form_error('description'); ?>
		
		</span>
	</div>
  </div>
		

	

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="category" name="btn_addproductcategory" class="btn btn-default"> Add Category   </button>

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

    

				</div>

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



	
	
				<div id="addsupplierModal" 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  Supplier</h4>
      </div>
      <div class="modal-body">
      
	  	

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



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/addmember' , 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="status" value="1" class="form-control" required placeholder="Enter status">

<input type="hidden" name="view" value="user/viewpurchases"id="view" class="form-control" required placeholder="Enter status">


	
		 
				
					<div class="form-group">
    <label for="inputcategory" class="col-sm-2 control-label">	Category	 </label>
    <div class="col-sm-10">
	
	<select class="form-control" name="category" >
	<option value=""  >---Select category---</option>
	<option value="member"  >Customer</option>
		<option value="supplier" selected="selected" >Supplier</option>
				<option value="user"  >Employee</option>
								<option value="accomodation" >Accomodation</option>

				<option value="reseller"  >Reseller/Agents</option>

	</select>		 
				
		<span class="text-danger"> <?php echo form_error('category'); ?>
		
		</span>
	</div>
  </div>
						
						
					<div class="form-group">
    <label for="inputcompany" class="col-sm-2 control-label">	Company Name </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="company" required value="<?php echo set_value('company'); ?>" class="form-control"  placeholder="Enter company name if any">
		 
				
		<span class="text-danger"> <?php echo form_error('company'); ?>
		
		</span>
	</div>
  </div>	
						
						
						
						
						
						
						
	<div class="form-group">
    <label for="inputfirstname" class="col-sm-2 control-label"> Contact	Names<span style="color:red;">*</span></label>
    <div class="col-sm-10">
	
		  		<input type="text" name="firstname" value="<?php echo set_value('firstname'); ?>" class="form-control" required placeholder="Enter first and last name">
		 
				
		<span class="text-danger"> <?php echo form_error('firstname'); ?>
		
		</span>
	</div>
  </div>

  
  	<div class="form-group">
    <label for="inputphone" class="col-sm-2 control-label">	Phone <span style="color:red;">*</span></label>
    <div class="col-sm-10">
	
		  		<input type="text" name="phone" value="<?php echo set_value('phone'); ?>" class="form-control" required placeholder="Enter phone e.g 254712345678">
		 
				
		<span class="text-danger"> e.g 254712345678 <?php echo form_error('phone'); ?>
		
		</span>
	</div>
  </div>
  
   	<div class="form-group">
    <label for="inputphoneaddress_1" class="col-sm-2 control-label">Phone 2	 </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="address_1" value="<?php echo set_value('address_1'); ?>" class="form-control"  placeholder="Enter other line e.g 254712345678">
		 
				
		<span class="text-danger">Other Number e.g 254712345678 <?php echo form_error('address_1'); ?>
		
		</span>
	</div>
  </div>
  
  
  
  	<div class="form-group">
    <label for="inputidno" class="col-sm-2 control-label">	ID Number	 </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="idno" value="<?php echo set_value('idno'); ?>" class="form-control"  placeholder="Enter idno if any ">
		 
				
		<span class="text-danger"> <?php echo form_error('idno'); ?>
		
		</span>
	</div>
  </div>
  
  
  
     
   	<div class="form-group">
    <label for="inputidnumber" class="col-sm-2 control-label">	PIN  </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="idnumber" value="<?php echo set_value('idnumber'); ?>" class="form-control"  placeholder="Enter Campany Pin">
		 
				
		<span class="text-danger"> <?php echo form_error('idnumber'); ?>
		
		</span>
	</div>
  </div>
  
  
  
  
  
  
  
   	<div class="form-group">
    <label for="inputphonegender" class="col-sm-2 control-label">Contact	Gender	 </label>
    <div class="col-sm-10">
	
	<select class="form-control" name="gender" >
	
	<option value=""  >---Select Gender---</option>
	<option value="female"  >female</option>
		<option value="male"  >male</option>
	</select>		 
				
		<span class="text-danger"> <?php echo form_error('gender'); ?>
		
		</span>
	</div>
  </div>
   <div class="form-group">
    <label for="inputcountry" class="col-sm-2 control-label">Country?</label>
    <div class="col-sm-10">
	<select class="form-control" name="country" >
	


	
	<?php 
					 
			$mycountry = $this->nationmodel->populatenation();
	


if(is_array($mycountry)) {

   foreach($mycountry as $mycountryrow){

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



	<?php

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

	</div>
  </div>
  
  
  
  
    	<div class="form-group">
    <label for="inputemail" class="col-sm-2 control-label">	Email </label>
    <div class="col-sm-10">
	
		  		<input type="email" name="email" value="<?php echo set_value('email'); ?>" class="form-control"  placeholder="Enter Your email">
		 
				
		<span class="text-danger"> <?php echo form_error('email'); ?>
		
		</span>
	</div>
  </div>
  
  	
  
  
    
  	<div class="form-group">
    <label for="inputcity" class="col-sm-2 control-label">	City 	 </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="city" value="<?php echo set_value('city'); ?>" class="form-control"  placeholder="Enter City or town">
		 
				
		<span class="text-danger"> <?php echo form_error('city'); ?>
		
		</span>
	</div>
  </div>
  
  
  
  	<div class="form-group">
    <label for="inputzip" class="col-sm-2 control-label">	Zip Code 	 </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="zip" value="<?php echo set_value('zip'); ?>" class="form-control"  placeholder="Enter Zip Code">
		 
				
		<span class="text-danger"> <?php echo form_error('zip'); ?>
		
		</span>
	</div>
  </div>
  
  
  
 
  
  	
 
  
    	<div class="form-group">
    <label for="inputwebsite" class="col-sm-2 control-label">		Website/Link 	 </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="website" value="<?php echo set_value('website'); ?>" class="form-control"  placeholder="Enter website if any">
		 
				
		<span class="text-danger"> <?php echo form_error('website'); ?>
		
		</span>
	</div>
  </div>
  
  	<div class="form-group">
    <label for="inputentrydate" class="col-sm-2 control-label">	Entry date  	 </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="entrydate" value="<?php echo set_value('entrydate'); ?>" class="form-control"  placeholder="Enter Entry date">
		 
				
		<span class="text-danger"> <?php echo form_error('entrydate'); ?>
		
		</span>
	</div>
  </div>
  
  
  
  
	<div class="form-group">
    <label for="inputcomments" class="col-sm-2 control-label">	Description</label>
    <div class="col-sm-10">

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

	

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="member" name="btn_addmember" class="btn btn-default"> Add new Supplier   </button>

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

    

				</div>

		</div>
	    </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 23:59:59");
					  
					  
					  $frommydate=date("Y-m-d 00:00:00");
		  $new_date=date("Y-m-d H:i: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="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( $viewallcounters==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="inputdaterange" class="col-sm-2 control-label">Use date range?</label>
    <div class="col-sm-10">
	<select class="form-control" name="daterange" required>
	
	<option value=""  >---Do  you want a specific period---</option>
			<option value="yes"   selected="selected" >--Yes,I want to view between specific dates---</option>

		<option value="no"  >--No, I want to view everything---</option>

</select>
		

	</div>
  </diV>
	
	
	 <div class="form-group">
    <label for="inputpayment" class="col-sm-2 control-label">Payment?</label>
    <div class="col-sm-10">
	<select class="form-control" name="payment" id="payment"required>
	
	<option value=""  >---Do  you want pay this supplier in bulk?---</option>
			<option value="no"selected="selected"  >--No, I just want to view purchases---</option>

			<option value="yes"   >--Yes, I want make bulk payment to this supplier ---</option>


</select>
		

	</div>
  </diV>
	
	
	 <div class="form-group" id="bankname">
    <label for="inputbankname" class="col-sm-2 control-label">Bank name?</label>
    <div class="col-sm-10">
	<select class="form-control" name="bankname" >
	
	<option value=""  >---Select bank name---</option>
	
	<?php 
	
					 
										$banking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype','1');


	
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.';
}
	

	$allbanking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype<>','1');

										
if(is_array($allbanking)) {

   foreach($allbanking as $allbankingrow){

   //echo $courserow->coursename;
    ?>
		<option value="<?=  $allbankingrow->number;   ?>"><?=  $allbankingrow->accountname ."(Acc No:". $bankingrow->number ."-Acc Name: ".$bankingrow->accountname.")  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="inputsupplier" class="col-sm-2 control-label">Supplier name</label>
    <div class="col-sm-10">
	
		  		<input type="text" name="supplier" id="mysupplier1" autofocus value="<?php echo set_value('supplier'); ?>" class="form-control" required placeholder="Enter Customer name or all to view all supliers">
		 
				
		<span class="text-danger"> Enter "all" or supplier name<?php echo form_error('supplier'); ?>
		
		</span>
	</div>
	</div>
  
  
  
<div class="form-group" id="PAYMENTDATE">


    <label for="inputPAYMENTDATE" class="col-sm-2 control-label">Payment Date </label>

				<div class="col-sm-5">
					<div class="form-group">

                     		  		<input type="date" name="PAYMENTDATE" value="<?php echo set_value('PAYMENTDATE',date("Y-m-d", strtotime($mydate))); ?>" class="form-control" required placeholder="Enter PAYMENTDATE date">

					</div>
				</div>
				<div class="col-sm-5">
					<div class="form-group">
					

							  		<input type="time"  name="paymentfrotime" value="<?php echo set_value('paymentfrotime',date("H:i:s")); ?>" class="form-control" required placeholder="Enter start time">

					</div>
				</div>
			
		</div>
			
			
  
  
  
  
  
  
  
	
					  <div class="form-group" id="originalamount">
    <label for="inputoriginalamount" class="col-sm-2 control-label">Amount</label>
    <div class="col-sm-10">
	
		  		<input type="text" name="originalamount"  autofocus value="<?php echo set_value('originalamount',0); ?>" class="form-control" required placeholder="Enter amount to pay">
		 
				
		<span class="text-danger"> <?php echo form_error('originalamount'); ?>
		
		</span>
	</div>
	</div>


  	<div class="form-group"  id="transactioncode" >
    <label for="inputtransactioncode" class="col-sm-2 control-label">	Transactions Code </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="transactioncode" value="<?php echo set_value('transactioncode'); ?>" class="form-control"  placeholder="Enter Code">
		 
				
		<span class="text-danger"> <?php echo form_error('transactioncode'); ?>
		
		</span>
	</div>
  </div>




    <label for="inputfromdate" class="col-sm-2 control-label">From Date </label>

				<div class="col-sm-5">
					<div class="form-group">

                     		  		<input type="date" name="fromdate" value="<?php echo set_value('fromdate',date("Y-m-d", strtotime($frommydate))); ?>" class="form-control" required placeholder="Enter start date">

					</div>
				</div>
				<div class="col-sm-5">
					<div class="form-group">
					

							  		<input type="time"  name="frotime" value="<?php echo set_value('frotime',date("00:00:00")); ?>" class="form-control" required placeholder="Enter start time">

					</div>
				</div>
			
		
			
			
						    <label for="inputtodate" class="col-sm-2 control-label">To Date </label>

				<div class="col-sm-5">
					<div class="form-group">

		  		<input type="date" name="todate" value="<?php echo set_value('todate',date("Y-m-d", strtotime($mydate))); ?>" class="form-control" required placeholder="Enter End date">

					</div>
				</div>
				<div class="col-sm-5">
					<div class="form-group">
					

							  		<input type="time"  name="totime" value="<?php echo set_value('totime',"23:59:59"); ?>" class="form-control" required placeholder="Enter stop time">

					</div>
				</div>
  
  




















   

  
  

	   <div class="form-group" style="display:none">
    <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="all"  selected>---All types---</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="inputgroup" class="col-sm-2 control-label">Category?</label>
    <div class="col-sm-10">
	<select class="form-control" name="group" required>
	
	<option value=""  >---Select group/category---</option>

		<option value="all" selected="selected"  >--I want view all/any category---</option>
	<?php 
					 
			$group =  $this->usermodel->populateall('category','companyid',$companyid);
	

	
if(is_array($group)) {

   foreach($group as $grouprow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $grouprow->id;   ?>"><?=  $grouprow->name; ?></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="inputgroupall" class="col-sm-2 control-label">Group purchases?</label>
    <div class="col-sm-10">
	<select class="form-control" name="groupall" required>
	
	<option value=""  >-Group all the purchases---</option>

		<option value="no" selected="selected" >--NO---</option>
			<option value="yes"  >--YES--</option>

</select>
		

	</div>
  </diV>
	 <div class="form-group">
    <label for="inputpaymentstatus" class="col-sm-2 control-label">Status?</label>
    <div class="col-sm-10">
	<select class="form-control" name="paymentstatus" required>
	
	<option value=""  >---Select your option---</option>

		<option value="all" selected="selected" >-All-</option>
		<option value="paid" selected="selected" >-Paid-</option>
		<option value="unpaid" selected="selected" >-UnPaid-</option>

</select>
		

	</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-default"> View Purchases  </button>

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

    

				</div>

		</div>
	    </div>
    </div>	
	
	
	
	
	
	
			<div id="itempurchaseModal" 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 per item</h4>
      </div>
      <div class="modal-body">
      
	  	

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

				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/viewitembasedpurchasereport' , 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="inputreporttype" class="col-sm-2 control-label">Report Type?</label>
    <div class="col-sm-10">
	<select class="form-control" name="reporttype" required>
	
	<option value=""  >---Select Report Type?---</option>
			<option value="purchases"selected="selected"  >Purchases Report</option>

			<option value="expiry"   >Expiry Report</option>


</select>
		

	</div>
  </diV>










	  <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( $viewallcounters==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="inputdaterange" class="col-sm-2 control-label">Use date range?</label>
    <div class="col-sm-10">
	<select class="form-control" name="daterange" required>
	
	<option value=""  >---Do  you want a specific period---</option>
			<option value="yes"   selected="selected" >--Yes,I want to view between specific dates---</option>

		<option value="no"  >--No, I want to view everything---</option>

</select>
		

	</div>
  </diV>
	
	
	 <div class="form-group">
    <label for="inputgrouping" class="col-sm-2 control-label">Group Items?</label>
    <div class="col-sm-10">
	<select class="form-control" name="grouping" required>
	
	<option value=""  >---Do  you want to group items/products?---</option>
			<option value="yes"selected="selected"  >Yes</option>

			<option value="no"   >No</option>


</select>
		

	</div>
  </diV>
  
  
	 <div class="form-group">
    <label for="inputitemtype" class="col-sm-2 control-label">Item type?</label>
    <div class="col-sm-10">
	<select class="form-control" name="itemtype" required>
	
	<option value=""  >---Do  you want view the history of all items or one item?---</option>
			<option value="all"selected="selected"  >View all items/products</option>

			<option value="one"   >I want to view one item/prodcut</option>


</select>
		

	</div>
  </diV>
	
	  <div class="form-group">
    <label for="inputcode" class="col-sm-2 control-label">Product code</label>
    <div class="col-sm-10">
	
		  		<input type="text" name="code" id="id" autofocus value="<?php echo set_value('code',"all"); ?>" class="form-control"  placeholder="Enter code or name">
		 
				
		<span class="text-danger"> <?php echo form_error('code'); ?>
		
		</span>
	</div>
  </div>
  
	

    <label for="inputfromdate" class="col-sm-2 control-label">From Date </label>

				<div class="col-sm-5">
					<div class="form-group">

                     		  		<input type="date" name="fromdate" value="<?php echo set_value('fromdate',date("Y-m-d", strtotime($frommydate))); ?>" class="form-control" required placeholder="Enter start date">

					</div>
				</div>
				<div class="col-sm-5">
					<div class="form-group">
					

							  		<input type="time"  name="frotime" value="<?php echo set_value('frotime',date("00:00:00")); ?>" class="form-control" required placeholder="Enter start time">

					</div>
				</div>
			
		
			
			
						    <label for="inputtodate" class="col-sm-2 control-label">To Date </label>

				<div class="col-sm-5">
					<div class="form-group">

		  		<input type="date" name="todate" value="<?php echo set_value('todate',date("Y-m-d", strtotime($mydate))); ?>" class="form-control" required placeholder="Enter End date">

					</div>
				</div>
				<div class="col-sm-5">
					<div class="form-group">
					

							  		<input type="time"  name="totime" value="<?php echo set_value('totime',"23:59:59"); ?>" class="form-control" required placeholder="Enter stop time">

					</div>
				</div>
  
  



			
				
				
				
					  <div class="form-group">
    <label for="inputsupplier" class="col-sm-2 control-label">Supplier name</label>
    <div class="col-sm-10">
	
		  		<input type="text" name="supplier" id="mysupplier2" autofocus value="<?php echo set_value('supplier',"all"); ?>" class="form-control" required placeholder="Enter Customer name">
		 
				
		<span class="text-danger"> <?php echo form_error('supplier'); ?>
		
		</span>
	</div>
  </div>
				
		
	  <div class="form-group">
    <label for="inputbatchno" class="col-sm-2 control-label">Batch No</label>
    <div class="col-sm-10">
	
		  		<input type="text" name="batchno" id="batchno" autofocus value="<?php echo set_value('batchno',"all"); ?>" class="form-control"  placeholder="Enter batchno">
		 
				
		<span class="text-danger"> <?php echo form_error('batchno'); ?>
		
		</span>
	</div>
  </div>
  
		
		
		
		
		
		
		
		
		
  <div class="form-group">
    <label for="inputcategory" class="col-sm-2 control-label">	Sub category?</label>
    <div class="col-sm-10">
	<select class="form-control" name="category"  required>
	
	<option selected="selected" value="all"  >---All/Any Category--</option>

	
	<?php 
					 
					 		$productcategory = $this->usermodel->populateall('productcategory','companyid',$companyid);


							


if(is_array($productcategory)) {

   foreach($productcategory as $productcategoryrow){

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



	<?php

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

	</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-default"> 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-default" 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="uploadopeningbalancesModal" 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 Opening balances  data(CSV)</h4>
		
      </div>
      <div class="modal-body">
        <a href="<?php echo base_url();?>downloads/supplierbalance.xlsx" class="btn btn-info">Download   opening balance template </a>	 

	  	

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



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/uploadsupplierinvoice' , 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="inputfromdate" class="col-sm-2 control-label">Balance Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="fromdate" value="<?php echo set_value('fromdate',$new_date); ?>" 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="inputfiscalyear" class="col-sm-2 control-label">	Current fiscal year?</label>
    <div class="col-sm-10">
	<select class="form-control" name="fiscalyear"  id="fiscalyear" required>
	
	<option selected="selected" value="all"  >--Current fiscal year--</option>

	
	<?php 

					 		$productcategory = $this->usermodel->populatealldatawhere('fiscalyear','id','desc','companyid',$companyid);

					 		//$productcategory = $this->usermodel->populateall('productcategory','companyid',$companyid);


							


if(is_array($productcategory)) {

   foreach($productcategory as $productcategoryrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $productcategoryrow->id;   ?>"><?=  $productcategoryrow->name." (From ".$productcategoryrow->startdate." to ". $productcategoryrow->enddate.")"; ?></option>



	<?php

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

	</div>
  </div>

	
	
	
  
  
  
  
  
  
  
	<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_uploadsupplierinvoice" class="btn btn-default">Upload new Opening Balance  </button>

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

    

				</div>

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

						<div id="uploadMasterModal" 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 Purchase Master(CSV)</h4>
		
      </div>
      <div class="modal-body">
        <a href="<?php echo base_url();?>downloads/purchasemaster.xlsx" class="btn btn-info">Download   purchases template </a>	 

	  	

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



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/uploadpurchasesmaster' , 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">
    <label for="inputpaymenttype" class="col-sm-2 control-label">Purchase type</label>
    <div class="col-sm-10">
	<select class="form-control" id="paymenttype" name="paymenttype" required required>
	
	<option value=""  >---Select Purchase type---</option>
			<option value="purchases" selected="selected" >Final Purchases</option>

		<option value="p.o"  >LPO Purchases(Raw)</option>

		

</select>
		

	</div>
  </div>
	

	
	 <div class="form-group">

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

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

    

				</div>

		</div>
	    </div>
    </div>
	
	
	
	
	
						<div id="downloadetimspurchaseModal" 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">Download Etims Purchase</h4>
		
      </div>
      <div class="modal-body">

	  	

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



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/downloadetimspurchase' , 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',$new_date); ?>" class="form-control" required placeholder="Enter start date">
		 
				
		<span class="text-danger"> <?php echo form_error('fromdate'); ?>
		
		</span>
	</div>
  </div>
  
	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="downloadetimpurchases" name="btn_downloadetimpurchases" class="btn btn-info">Download Now </button>

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

    

				</div>

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

	
	
	
	

						<div id="downloadetimspurchaseimportModal" 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">Download Etims Purchase Imports</h4>
		
      </div>
      <div class="modal-body">

	  	

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



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/downloadetimspurchaseimports' , 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',$new_date); ?>" class="form-control" required placeholder="Enter start date">
		 
				
		<span class="text-danger"> <?php echo form_error('fromdate'); ?>
		
		</span>
	</div>
  </div>
  
	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="downloadetimpurchasesimports" name="btn_downloadetimpurchasesimports" class="btn btn-info">Download Now </button>

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

    

				</div>

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

						<div id="uploadMasterModal" 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 Purchase Master(CSV)</h4>
		
      </div>
      <div class="modal-body">
        <a href="<?php echo base_url();?>downloads/purchasemaster.xlsx" class="btn btn-info">Download   purchases template </a>	 

	  	

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



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/uploadpurchasesmaster' , 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">
    <label for="inputpaymenttype" class="col-sm-2 control-label">Purchase type</label>
    <div class="col-sm-10">
	<select class="form-control" id="paymenttype" name="paymenttype" required required>
	
	<option value=""  >---Select Purchase type---</option>
			<option value="purchases" selected="selected" >Final Purchases</option>

		<option value="p.o"  >LPO Purchases(Raw)</option>

		

</select>
		

	</div>
  </div>
	

	
	 <div class="form-group">

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

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

    

				</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">
        <a href="<?php echo base_url();?>downloads/purchasestock.csv" class="btn btn-info">Download   purchases template </a>	 

	  	

				<?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-default">Upload new purchases  </button>

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

    

				</div>

		</div>
	    </div>
    </div>
	<div id="editProductModel" 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">Update purchases Main</h4>
      </div>
      <div class="modal-body">
      
	  	

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

			 $finalsalesid = $userid.time();


				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;?>
	<input type="hidden" name="view" required value="user/viewpurchases" class="form-control"  placeholder="view">
	<input type="hidden" name="status" required id="status" value="" class="form-control"  placeholder="status">
	<input type="hidden" name="branchid" required id="branchid" value="" class="form-control"  placeholder="status">

	<input type="hidden" name="action" required value="update" class="form-control"  placeholder="insert">

	<input type="hidden" name="mycategoryid" value=""id="mycategoryid" class="form-control" required placeholder="Enter mycategoryid">
			  		
		<input type="hidden" name="vattype" required value="VATABLE" class="form-control"  placeholder="vattype">






		  <div class="form-group">
    <label for="inputsupplier" class="col-sm-2 control-label">Supplier name</label>
    <div class="col-sm-10">
	
		  		<input type="text" name="supplier"    id="supplier" autofocus value="<?php echo set_value('supplier'); ?>" class="form-control" required placeholder="Enter Customer name">
		 
				
		<span class="text-danger"> <?php echo form_error('supplier'); ?>
		
		</span>
	</div>
  </div>














  	
  
	<div class="form-group">
    <label for="inputinvoice_number" class="col-sm-2 control-label">	Ref No :  </label>
    <div class="col-sm-10">
			  		<input type="text" readonly id="invoice_number" 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="inputordernumber" class="col-sm-2 control-label">Invoice / Receipt No : </label>
    <div class="col-sm-10">
	
		  		<input type="text" id="ordernumber"  name="ordernumber" value="<?php echo set_value('ordernumber'); ?>" class="form-control"  placeholder="Enter  order number if any ">
		 
				
		<span class="text-danger"> <?php echo form_error('ordernumber'); ?>
		
		</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" id="fromdate" 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="inputpin" class="col-sm-2 control-label">	Supplier Pin :  </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="pin"  id="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"  id="paiddate" 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" id="amount" value="<?php echo set_value('amount'); ?>" class="form-control"  placeholder="This is automatic">
		 
				
		<span class="text-danger"> <?php echo form_error('amount'); ?>
		
		</span>
	</div>
  </div>
  
  	<div class="form-group">
    <label for="inputpaid" class="col-sm-2 control-label">Paid Amount :  </label>
    <div class="col-sm-10">
	
		  		<input type="text"  name="paid" id="paid" value="<?php echo set_value('paid'); ?>" class="form-control"  placeholder="enter paid amount">
		 
				
		<span class="text-danger"> <?php echo form_error('paid'); ?>
		
		</span>
	</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" id="vatrate"  value="" 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"  id="vat"  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"  id="taxable" 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="inputshippingto" class="col-sm-2 control-label">Shipping to details..</label>
    <div class="col-sm-10">

	<textarea name="shippingto"  id="shippingto"  class="form-control" placeholder="Shipping to details if any."><?php echo set_value('shippingto'); ?></textarea> 
			
	</div>
  </div>
  
  
       	<div class="form-group">
    <label for="inputwithholdingrate" class="col-sm-2 control-label">Withholding	VAT Rate  </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="withholdingrate" id="withholdingrate"  value="" class="form-control"  placeholder="Enter withholding rate (%)">
		 
				
		<span class="text-danger"> <?php echo form_error('withholdingrate'); ?>
		
		</span>
	</div>
  </div>
  
  
  
       	<div class="form-group">
    <label for="inputwitwithholdingamount" class="col-sm-2 control-label">Withholding	Amount </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="withholdingamount" id="withholdingamount"  value="" class="form-control"  placeholder="Enter withholding amount">
		 
				
		<span class="text-danger"> <?php echo form_error('withholdingamount'); ?>
		
		</span>
	</div>
  </div>
  
  
  
  
	<div class="form-group">
    <label for="inputremarks" class="col-sm-2 control-label">	Remarks/Note </label>
    <div class="col-sm-10">

				<textarea name="remarks"  id="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-default"> Update Purchase   </button>

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

    

				</div>

		</div>
	    </div>
    </div>
					
			
	
	
		
					<div id="payModel" 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">Pay this Supplier.</h4>
      </div>
      <div class="modal-body">
      
	  	

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

					  $mydate=date("Y-m-d 23:59:59");
 		  $currentdate = date('Y-m-d H:i:s');

				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/updatesupplierpayment' , 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="billid" value=""id="billid" class="form-control" required placeholder="Enter billid">
			  	<input type="hidden" name="invoice" value=""id="invoice1" class="form-control" required placeholder="Enter invoice">
					  	<input type="hidden" name="paymentmethodes" value="n/a"id="invoice1" class="form-control" required placeholder="Enter invoice">

	
		 <div class="form-group">
    <label for="inputpaymenttype" class="col-sm-2 control-label">Payment type</label>
    <div class="col-sm-10">
	<select class="form-control" id="paymenttype" name="paymenttype" required required>
	
	<option value="" >---Select Payment type---</option>
			<option value="Payment"  selected="selected"  >I want to make payment</option>
			<option value="Payment-Withhold"  >I want to make Withholding-Tax  payment</option>

		<option value="Cancel"  >I want Cancel payment</option>

		

</select>
		

	</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="date" name="paiddate" value="<?php echo set_value('fromdate',date("Y-m-d", strtotime($new_date))); ?>" class="form-control2" required placeholder="Enter start date">
		 
											  		<input type="time"  name="frotime" value="<?php echo set_value('frotime',date("H:i:s")); ?>" class="form-control2" required placeholder="Enter start time">

		<span class="text-danger"> <?php echo form_error('paiddate'); ?>
		
		</span>
	</div>
  </div>
	
	

	
	
	
	
	
	
	
 
  <div class="form-group">
    <label for="inputbankname" class="col-sm-2 control-label">Bank from1?</label>
    <div class="col-sm-10">
	<select class="form-control" name="bankid" required>
	
	<option value=""  >---Select bank name---</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->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype','1');

										
if(is_array($banking)) {

   foreach($banking as $bankingrow){

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



	<?php

}} else {
    echo 'No bank available.';
}
	
	
	$allbanking=false;
	
	//$allbanking= $this->usermodel->populatealldatanoarray('glaccounts','companyid',$companyid,'accounttype<>','1');

										
if(is_array($allbanking)) {

   foreach($allbanking as $allbankingrow){

   //echo $courserow->coursename;
    ?>
		<option value="<?=  $allbankingrow->number;   ?>"><?=  $allbankingrow->accountname ."(Acc No:". $allbankingrow->number ."-Acc Name: ".$allbankingrow->accountname.")"; ?></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="inputpayment" class="col-sm-2 control-label">	Amount To pay </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="payment" id="myfinaltotal" value="<?php echo set_value('payment'); ?>" id="payment" class="form-control" required placeholder="Enter payment">
		 
				
		<span class="text-danger"> <?php echo form_error('payment'); ?>
		(<?php if(isset($symbol)) {echo $symbol; }?>)
		</span>
	</div>
  </div>
 
 
 
   <div class="form-group">
    <label for="inputmycode" class="col-sm-2 control-label">Cheque	Number/Code </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="mycode" value="<?php echo set_value('mycode'); ?>" id="mycode" class="form-control"  placeholder="Enter payment number/code">
		 
				
		<span class="text-danger"> <?php echo form_error('mycode'); ?>
		
		</span>
	</div>
  </div>
  
		

 
 
 
 
 
 
 
 
 
  	
  
  
							 				 <?php
				 if( $multicurrency=="yes"){
	$countbranch=$this->usermodel->countbranches($companyid);
 if( $countbranch >1){
 $mybranches= $this->usermodel->populateallarray('branch','id',$branchid);
if(isset($mybranches[0]['currency']) !=""){
	$symbol=$mybranches[0]['currency'];

}else{
$symbol=$configuration[0]["currencysymbol"]; 
	
}
			 
 }else{
$symbol=$configuration[0]["currencysymbol"]; 
	



 }	  ?>
						
				
<div class="form-group">
    <label for="inputamount" class="col-sm-2 control-label">Currency To transfer :  </label>
    <div class="col-sm-10">
				 <select class="chzn-select" name="newcurrency" id="currency" style="width:100%" style="margin:0px; padding:0px;" >
	
	<option value="" selected="selected"  >---Select Other Currency---</option>
								   
									   
		<?php 

      $currency = $this->usermodel->populateall('currency','companyid', $companyid);


if(is_array($currency)) {

   foreach($currency as $currencyrow){

  


  
   ?>
	    <option  value="<?php echo $currencyrow->toamount.":=". $currencyrow->name; ?> "><?=$currencyrow->name." => ". $currencyrow->basecurrency."(".$currencyrow->toamount.")";?></option>

   
    <?php   


   
   
  

}} else {
    echo 'There is no any  currency for this house.... PLease add charges first.';
}

?>
</select>	
		<br><br>			
	<input type="text"     name="tocurrencyamount" value=""  id="tocurrencyamount" style="background:#FFF0F5" class="form-control1" required placeholder="to currency">
	<input type="text" readonly   id="tocurrency"  name="tocurrency"  value="<?php if(isset($symbol)) {echo $symbol; }?>" style="background:#FFF0F5"class="form-control1" required placeholder="to currency">
	<input type="hidden" readonly     name="currency"  value="<?php if(isset($symbol)) {echo $symbol; }?>" style="background:#FFF0F9"class="form-control1" required placeholder="base currency">

			
	</div>
  </div>
  
  
  

	
	
  
  
  
  
  
  
  
  
  
  			
					
  			<?php	
			}else{
			?>
	<input type="hidden" readonly    name="tocurrencyamount" value="0"  id="tocurrencyamount" style="background:#FFF0F5" class="form-control1" required placeholder="to currency">
	<input type="hidden" readonly   id="tocurrency"  name="tocurrency"  value="<?php if(isset($symbol)) {echo $symbol; }?>" style="background:#FFF0F5"class="form-control1" required placeholder="to currency">
	<input type="hidden" readonly     name="currency"  value="<?php if(isset($symbol)) {echo $symbol; }?>" style="background:#FFF0F9"class="form-control1" required placeholder="base currency">

			
				
			<?php	
			}
			?>
	
  
  
  
  
	<div class="form-group">
    <label for="inputdescription" class="col-sm-2 control-label">	Description</label>
    <div class="col-sm-10">

				<textarea name="description" value="<?php echo set_value('description'); ?>"  id="description" class="form-control"  placeholder="Enter payment details e.g paid to? "></textarea>
			
		<span class="text-danger"> <?php echo form_error('description'); ?>
		
		</span>
	</div>
  </div>

  
  
 
			<div class="form-group">
    <label for="inputamount" class="col-sm-2 control-label">Original Amount </label>
    <div class="col-sm-10">
	
		  		<input type="text" readonly name="amount" value="<?php echo set_value('amount'); ?>" id="amount1" class="form-control" required placeholder="Enter amount">
		 
				
		<span class="text-danger"> <?php echo form_error('amount'); ?>
		
		</span>
	</div>
  </div>
	<div class="form-group">
    <label for="inputpaid" class="col-sm-2 control-label">Paid Amount </label>
    <div class="col-sm-10">
	
		  		<input type="text" readonly name="paid" value="<?php echo set_value('amount'); ?>" id="paid1" class="form-control" required placeholder="Enter paid">
		 
				
		<span class="text-danger"> <?php echo form_error('paid'); ?>
		
		</span>
	</div>
  </div>
	
<div class="form-group">
    <label for="inputbalance" class="col-sm-2 control-label">Balance Due </label>
    <div class="col-sm-10">
	
		  		<input type="text" readonly name="balance" value="<?php echo set_value('balance'); ?>" id="balance1" class="form-control" required placeholder="Enter balance">
		 
				
		<span class="text-danger"> <?php echo form_error('balance'); ?>
		
		</span>
	</div>
  </div>
	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="purchase" name="btn_paypurchases" class="btn btn-default"> Make payment  </button>

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

    

				</div>

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

						<div id="updatemyModal" 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">Update balances</h4>
		
      </div>
      <div class="modal-body">
      
	  	

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

 $frm=date("Y-m-d 00:00:00");	

				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/updatesupplierbalances' , 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/viewloyality"id="view" class="form-control" required placeholder="Enter view">
	
	


	 <div class="form-group">
    <label for="inputfromdate" class="col-sm-2 control-label">Balance  start Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="fromdate" value="<?php echo set_value('fromdate',$frm); ?>" 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">Balance  End  Date </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="todate" value="<?php echo set_value('todate',$new_date); ?>" class="form-control" required placeholder="Enter end date">
		 
				
		<span class="text-danger"> <?php echo form_error('enddate'); ?>
		
		</span>
	</div>
  </div>
		
  
  
   <div class="form-group">
    <label for="inputaction" class="col-sm-2 control-label">Action</label>
    <div class="col-sm-10">
	<select class="form-control" name="action" required>
	
		<option value="" selected  >---Select action you need---</option>
		<option value="update"  selected="selected">Update balances</option>

	

</select>
		
						<span class="text-danger"><?php echo form_error('action'); ?>

	</div>
  </div>
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="loyatity" name="btn_addviewpoints" class="btn btn-primary"> Update Balance   </button>

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

    

				</div>

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

	
	
	
	
	
	
	
	
	
	
	<div id="addCreditNoteModal" 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 Credit Note</h4>
      </div>
      <div class="modal-body">
      
	  	

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

 $mylastrecord=0;
 	$lastrecord = $this->usermodel->last_purchasecode($companyid);
			if($lastrecord !=false){
				 $mylastrecord=$lastrecord[0]["id"]+1;
			}else{
				
				 $mylastrecord=$mylastrecord+1;
			}
 

				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;?>
	<input type="hidden" name="mycategoryid" value=""id="mycategoryid" class="form-control" required placeholder="Enter mycategoryid">
	<input type="hidden" name="view" value="user/viewreceivedproducts?randomitemidentifier" class="form-control" required placeholder="Enter mycategoryid">

  		  		<input type="hidden" name="vattype" required value="VATABLE" class="form-control"  placeholder="vattype">
  		  		<input type="hidden" name="action" required value="insert" class="form-control"  placeholder="insert">
  		  		<input type="hidden" name="status" required value="creditnote" class="form-control"  placeholder="status">

				
					  <div class="form-group">
    <label for="inputsupplier" class="col-sm-2 control-label">Receiving Branch</label>
    <div class="col-sm-10">
				
				
				<select class="form-control" name="branchid"  id="branchid" required>
	
	
	<option value=""  >---Select Branch/Counter to Open--</option>

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


if(is_array($mybranch)) {

   foreach($mybranch as $branchrow){

   ?>
					<option selected="selected" value="<?=  $branchrow->id;   ?>"><?=  $branchrow->name; ?></option>




	<?php

}} else {
    echo 'No Branch available.';
}
	
?>
	
	
	
	
	
	
	<?php 
					 
					 		$maincategory = $this->usermodel->populateall('branch','companyid',$companyid);


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

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



	<?php

}} else {
    echo 'No main counter available.';
}
	
?>
</select>
				
		</div>
  </div>
					
				
				
			
				
					  <div class="form-group">
    <label for="inputsupplier" class="col-sm-2 control-label">Supplier name</label>
    <div class="col-sm-10">
	
		  		<input type="text" name="supplier" id="mysupplierid" autofocus value="<?php echo set_value('supplier'); ?>" class="form-control" required placeholder="Enter Customer name">
		 
				
		<span class="text-danger"> <?php echo form_error('supplier'); ?>
		
		</span>
	</div>
  </div>
				
				
				
				
				
				
			
  	
		 		  		<input readonly type="hidden" name="invoice_number" id="invoice_number" required value="<?php echo set_value('invoice_number',$finalsalesid); ?>" class="form-control"  placeholder="Enter invoice or Receip tnumber">

	

  
	<div class="form-group">
    <label for="inputinvoice_number" class="col-sm-2 control-label">	Invoice / Receipt No :  </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="ordernumber" required value="<?php echo set_value('ordernumber',$mylastrecord); ?>" class="form-control"  placeholder="Enter invoice or Receipt number">
		 
				
		<span class="text-danger"> <?php echo form_error('ordernumber'); ?>
		
		</span>
	</div>
  </div>
  
  		  		<input type="hidden"  name="paid" id="paid" value="0.00" class="form-control"  placeholder="enter paid amount">


  
  
      <label for="inputfromdate" class="col-sm-2 control-label">Invoice Date  </label>

  
  <div class="col-sm-5">
					<div class="form-group">

                     		  		<input type="date" name="fromdate" value="<?php echo set_value('fromdate',date("Y-m-d", strtotime($new_date))); ?>" class="form-control" required placeholder="Enter start date">

					</div>
				</div>
				<div class="col-sm-5">
					<div class="form-group">
					

							  		<input type="time"  name="frotime" value="<?php echo set_value('frotime',date("H:i:s")); ?>" class="form-control" required placeholder="Enter start time">

					</div>
				</div>
			

  
  		    <label for="inputpaiddate" class="col-sm-2 control-label">Payment /Due Date </label>

				<div class="col-sm-5">
					<div class="form-group">

		  		<input type="date" name="paiddate" value="<?php echo set_value('paiddate',date("Y-m-d", strtotime($duedates))); ?>" class="form-control" required placeholder="Enter Payment Date or due date">

					</div>
				</div>
				<div class="col-sm-5">
					<div class="form-group">
					

							  		<input type="time"  name="totime" value="<?php echo set_value('totime',date("H:i:s")); ?>" class="form-control" required placeholder="Enter stop time">

					</div>
				</div>
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  	<div class="form-group" style="display:none">
    <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" style="display:none">
    <label for="inputamount" class="col-sm-2 control-label">Total Amount :  </label>
    <div class="col-sm-10">
	
		  		<input type="text" readonly name="amount" value="0.00" class="form-control"  placeholder="This is automatic">
		 
				
		<span class="text-danger"> <?php echo form_error('amount'); ?>
		
		</span>
	</div>
  </div>
  
  
  
  

	

  
  
  
  
  
      	<div class="form-group" style="display:none">
    <label for="inputpin" class="col-sm-2 control-label">	VAT Rate  </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="vatrate" value="<?php     if(isset($tax1rate)) {echo $tax1rate; } ?>" class="form-control"  placeholder="Enter vat rate (%)">
		 
				
		<span class="text-danger"> <?php echo form_error('vatrate'); ?>
		
		</span>
	</div>
  </div>
 <div class="form-group" style="display:none">
    <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" style="display:none">
    <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="inputshippingto" class="col-sm-2 control-label">Shipping to details..</label>
    <div class="col-sm-10">

	<textarea name="shippingto" class="form-control" placeholder="Shipping to details if any."><?php echo set_value('shippingto'); ?></textarea> 
			
	</div>
  </div>
  
  
  
  
	<div class="form-group">
    <label for="inputremarks" class="col-sm-2 control-label">	Remarks/Note </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">
    <label for="inputsupplier" class="col-sm-2 control-label">Posting Branch to?</label>
    <div class="col-sm-10">
				
				
				<select class="form-control" name="branchto"  id="branchto" required>
	
	
	<option value="" selected="selected"  >---Select where stock should go to--</option>

	
								
<?php
					 		$maincategory = $this->usermodel->populateall('branch','companyid',$companyid);

	     $mybranch=$this->usermodel->populateall('branch','id',$branchid);
   $mycounters=count($maincategory);

if(is_array($mybranch)) {

   foreach($mybranch as $branchrow){
	   
	




 if($mycounters>1){
	 ?>
						<option value="Main"    >Main store(HQ/Products)</option>

	 <?php
 }else{
	 ?>

					<option  selected="selected"  value="<?=  $branchrow->id;   ?>"><?=  $branchrow->name; ?></option>



	<?php 
 }



   ?>




	<?php

}} else {
    echo 'No Branch available.';
}
	
?>
	
	
	
	
					<option value="Main"  >Main store(HQ/Products)</option>

	
	<?php 
					 


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

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



	<?php

}} else {
    echo 'No main counter available.';
}
	
?>
</select>
				
		</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-default"> NEXT(Credit Note) >>   </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');

 $mylastrecord=0;
 	$lastrecord = $this->usermodel->last_purchasecode($companyid);
			if($lastrecord !=false){
				 $mylastrecord=$lastrecord[0]["id"]+1;
			}else{
				
				 $mylastrecord=$mylastrecord+1;
			}
 

				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;?>
	<input type="hidden" name="mycategoryid" value=""id="mycategoryid" class="form-control" required placeholder="Enter mycategoryid">
	<input type="hidden" name="view" value="user/viewreceivedproducts?randomitemidentifier" class="form-control" required placeholder="Enter mycategoryid">
  		  		<input type="hidden" name="status" required value="purchases" class="form-control"  placeholder="status">
		  		<input type="hidden" name="withholdingrate" value="0" class="form-control"  placeholder="Enter vat rate (%)">
		  		<input type="hidden" name="withholdingamount" value="0" class="form-control"  placeholder="Enter vat rate (%)">

  		  		<input type="hidden" name="vattype" required value="VATABLE" class="form-control"  placeholder="vattype">
  		  		<input type="hidden" name="action" required value="insert" class="form-control"  placeholder="insert">

				
					  <div class="form-group">
    <label for="inputsupplier" class="col-sm-2 control-label">Receiving Branch</label>
    <div class="col-sm-10">
				
				
				<select class="form-control" name="branchid"  id="branchid" required>
	
	
	<option value=""  >---Select Branch/Counter to Open--</option>

									
								
<?php
	     $mybranch=$this->usermodel->populateall('branch','id',$branchid);


if(is_array($mybranch)) {

   foreach($mybranch as $branchrow){

   ?>
					<option selected="selected" value="<?=  $branchrow->id;   ?>"><?=  $branchrow->name; ?></option>




	<?php

}} else {
    echo 'No Branch available.';
}
	
?>
	
	
	
	
	
	
	<?php 
				 if( $viewallcounters==true){	 
					 		$maincategory = $this->usermodel->populateall('branch','companyid',$companyid);


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

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



	<?php

}} else {
    echo 'No main counter available.';
}
				 }	
?>
</select>
				
		</div>
  </div>
					
				
				
			
				
					  <div class="form-group">
    <label for="inputsupplier" class="col-sm-2 control-label">Supplier name</label>
    <div class="col-sm-10">
	
		  		<input type="text" name="supplier" id="mysupplier" autofocus value="<?php echo set_value('supplier'); ?>" class="form-control" required placeholder="Enter supplier name">
		 
				
		<span class="text-danger"> <?php echo form_error('supplier'); ?>
		
		</span>
	</div>
  </div>
				
				
				
				
				
				
			
  	
		 		  		<input readonly type="hidden" name="invoice_number" id="invoice_number" required value="<?php echo set_value('invoice_number',$finalsalesid); ?>" class="form-control"  placeholder="Enter invoice or Receip tnumber">

	

  
	<div class="form-group">
    <label for="inputinvoice_number" class="col-sm-2 control-label">	Invoice / Receipt No :  </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="ordernumber" required value="<?php echo set_value('ordernumber',$mylastrecord); ?>" class="form-control"  placeholder="Enter invoice or Receipt number">
		 
				
		<span class="text-danger"> <?php echo form_error('ordernumber'); ?>
		
		</span>
	</div>
  </div>
  
  		  		<input type="hidden"  name="paid" id="paid" value="0.00" class="form-control"  placeholder="enter paid amount">


  
  
      <label for="inputfromdate" class="col-sm-2 control-label">Invoice Date  </label>

  
  <div class="col-sm-5">
					<div class="form-group">

                     		  		<input type="date" name="fromdate" value="<?php echo set_value('fromdate',date("Y-m-d", strtotime($new_date))); ?>" class="form-control" required placeholder="Enter start date">

					</div>
				</div>
				<div class="col-sm-5">
					<div class="form-group">
					

							  		<input type="time"  name="frotime" value="<?php echo set_value('frotime',date("H:i:s")); ?>" class="form-control" required placeholder="Enter start time">

					</div>
				</div>
			

      	<div class="form-group">

  		    <label for="inputpaiddate" class="col-sm-2 control-label">Payment /Due Date </label>

				<div class="col-sm-5">
					<div class="form-group">

		  		<input type="date" name="paiddate" value="<?php echo set_value('paiddate',date("Y-m-d", strtotime($duedates))); ?>" class="form-control" required placeholder="Enter Payment Date or due date">

					</div>
				</div>
				<div class="col-sm-5">
					<div class="form-group">
					

							  		<input type="time"  name="totime" value="<?php echo set_value('totime',date("H:i:s")); ?>" class="form-control" required placeholder="Enter stop time">

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

  
  
  
  
  
  
  
  
  
  
  
  	<div class="form-group" style="display:none">
    <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" style="display:none">
    <label for="inputamount" class="col-sm-2 control-label">Total Amount :  </label>
    <div class="col-sm-10">
	
		  		<input type="text" readonly name="amount" value="0.00" class="form-control"  placeholder="This is automatic">
		 
				
		<span class="text-danger"> <?php echo form_error('amount'); ?>
		
		</span>
	</div>
  </div>
  
  
  
  

	

  
  
  
  
  
      	<div class="form-group" style="display:none">
    <label for="inputpin" class="col-sm-2 control-label">	VAT Rate  </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="vatrate" value="<?php     if(isset($tax1rate)) {echo $tax1rate; } ?>" class="form-control"  placeholder="Enter vat rate (%)">
		 
				
		<span class="text-danger"> <?php echo form_error('vatrate'); ?>
		
		</span>
	</div>
  </div>
 <div class="form-group" style="display:none">
    <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" style="display:none">
    <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="inputshippingto" class="col-sm-2 control-label">Update B.price?</label>
    <div class="col-sm-10">
<select class="form-control" name="shippingto" required>
<option  value=""      >-Select Updating method-</option>

<option  value="Yes"    >Update old B.price(Yes-Use Avarage)</option>

	<option  value="Direct" selected="selected"  >Update old B.price(Yes-Use Direct amount)</option>
	<option value="No"     >No(Don't change B.Price)</option>

	

</select>





			
	</div>
  </div>
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
	<div class="form-group">
    <label for="inputremarks" class="col-sm-2 control-label">	Remarks/Note </label>
    <div class="col-sm-10">

				<textarea name="remarks" id="client" 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">
    <label for="inputsupplier" class="col-sm-2 control-label">Posting Branch to?</label>
    <div class="col-sm-10">
				
				
				<select class="form-control" name="branchto"  id="branchto" required>
	
	
	<option value="" selected="selected"  >---Select where stock should go to--</option>
					<option value="Main"   >Main store(HQ/Products)</option>

	
								
<?php
					 		$maincategory = $this->usermodel->populateall('branch','companyid',$companyid);

	     $mybranch=$this->usermodel->populateall('branch','id',$branchid);
   $mycounters=count($maincategory);

if(is_array($mybranch)) {

   foreach($mybranch as $branchrow){
	   
	




 if($mycounters>1){
	 ?>

					<option   value="<?=  $branchrow->id;   ?>"><?=  $branchrow->name; ?></option>

	 <?php
 }else{
	 ?>

					<option  selected="selected" value="<?=  $branchrow->id;   ?>"><?=  $branchrow->name; ?></option>



	<?php 
 }



   ?>




	<?php

}} else {
    echo 'No Branch available.';
}
	
?>
	
	
	
	

	
	<?php 
					 

 if( $viewallcounters==true){
							
					$maincategorys = $this->usermodel->populatealldatanoarraythree('branch','id <>', $branchid,'status',"active",'companyid',$companyid);


if(is_array($maincategorys)) {

   foreach($maincategorys as $maincategoryrow){

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



	<?php

}} else {
    echo 'No main counter available.';
}
	
 }
?>
</select>
				
		</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-default"> NEXT >>   </button>

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

    

				</div>

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

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

 
</div>


















