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

 <div class="row">
  
   	

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

  
		<div class="panel panel-default" data-collapsed="0">
        	<div class="panel-heading">
            	<div class="panel-title" id="redcolor" >
            		<i class="entypo-plus-circled"></i>
				 <span class="pull-right"> View Sales Order</span>
	  <a data-toggle='modal' data-target='#addModal' class="btn btn-primary">Add Sales Order </a>
				 				 	  <a data-toggle='modal' data-target='#purchaseModal' class="btn btn-info">Search for Sales Order</a>

 <div class="collapse navbar-collapse" id="app-navbar-collapse">
                <!-- Left Side Of Navbar -->
				
				
				 
				   
				  <ul class="nav navbar-nav">
                   <li> <a href="<?php echo base_url(); ?>user/salesorder">Sales order</a>	</li>
                </ul>	
				
					
				
				
				<ul class="nav navbar-nav">
                   <li> <a href="<?php echo base_url(); ?>user/allinvoices"> All Invoices</a>	</li>
                </ul>
					
					   <ul class="nav navbar-nav">
                    <li><a href="<?php echo base_url(); ?>user/allquatation">Quotation</a></li>
                </ul>
                <!-- Right Side Of Navbar -->
            					    <a data-toggle='modal' data-target='#addsupplierModal' class="btn btn-info">Add A new customer </a>
<a data-toggle='modal' data-target='#addCategoryModal' class="btn btn-success">Daily Summary sales(Category) 
			</a>
            </div>

            	</div>
            </div>
			<div class="panel-body">
<CENTER> <B>WELCOME VSM PORTAL</B></CENTER>
			
	<div class="widget-content nopadding table_holder table-responsive" >				
				<?PHP
 echo $this->session->flashdata('deletemsg'); 
	 $session_data = $this->session->userdata('logged_in');

   
 	$data['id'] = $session_data['id'];
        
		 $userid = $data['id'];
$data['companyid'] = $session_data['companyid'];
	 $companyid = $data['companyid'];
		 $data['usertype'] = $session_data['usertype'];
	 $usertype = $data['usertype'];
	$data['branchid'] = $session_data['branchid'];
	 $branchid = $data['branchid'];

	 
	 	 	$finalsalesid = $userid.$companyid.time();
	    $addproductaction=$this->usermodel->populatuserpermissionsdataarray('purchases','add',$userid);
	   $viewallaction=$this->usermodel->populatuserpermissionsdataarray('reports','viewall',$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);
 	 $smsconfig = $this->usermodel->populateallarray('smsconfig','id',$companyid);
		 	  $tax1rate=$smsconfig[0]['tax1rate'];	
			  
			  
function formatMoney($number, $fractional=false) {
						if ($fractional) {
							$number = sprintf('%.2f', $number);
						}
						while (true) {
							$replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
							if ($replaced != $number) {
								$number = $replaced;
							} else {
								break;
							}
						}
						return $number;
					}
				echo $this->session->flashdata('msg'); 
								?>	
					<div class="row">
						<div class="col-md-12">
							
							<div class="panel-body">
		<div class="row">
						<div class="col-md-12">
<?php 

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

            				<input type="hidden" name="view" value="userdata/salesorder" 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-success" value="Search" />
                    <a href="<?php echo base_url(). "user/salesorder"; ?>" class="btn btn-primary">Refresh</a>
              
			
        <?php echo form_close(); ?>
		  </div>
			 </div>	
                 </div>	
				
				
				
				
				
				
               
            </div>
									
				<table class="tablesorter table table-bordered  table-hover" id="sortable_table">			

             <thead>
         <tr>
  <th>View </th>
    <th> S.O No </th>
			<th> Amount </th>
					<th> Order Date </th>
			<th> 	Due Date </th>
				<th> Entry Date </th>

			<th> Customer </th>
			<th> Remarks </th>
				<th> Route / Category </th>

				<th> Shipping to </th>
							<th> Expense </th>
														<th> Status </th>

					<th>More</th>

		


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

			 }else{
 if(!is_array($viewpurchases)) 

 {


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

		 

             ?>



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

              
  <td><?php 
  if($invoice_number==""){
	  echo $c->invoice_number ; 
	  
  }else{
	  
	  ?>
	  	  	  	 <a  id="more" class="btn btn-warning"  href="<?php echo base_url();?>user/viewnewsalesorder?randomitemidentifier=<?php   {echo  $invoice_number;}  ?>">View</a>

  

	  
	 <?php  

  }
  ?>
  

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

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

	 

	 <td>
	 
			 
	 <a  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; 
	   
   }

  ?>
  </a>
  
  </td>
	  
	  
	  <td><?php echo $c->description ; ?></td>
	  	  <td><?php echo $c->remarks ; ?></td>

	  	  <td><?php echo $c->shippingto ; ?></td>
	  
	  
	   <td><?php  $ordernumber=$c->ordernumber ; 
	   
	   $totalexpense=$this->usermodel->populateallexpensebyno("expenses","amount", "idno",$ordernumber);
	   echo $amount= $totalexpense[0]["amount"];
	   
	   
	   
	   
	   
	   ?></td>
	   
	   	  	  <td><?php echo $c->transactionstatus ; ?></td>

 <td> 

 
 
					<div class="btn-group">
                                    <button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown">
                                        More <span class="caret"></span>
                                    </button>
								
                                    <ul class="dropdown-menu dropdown-primary pull-right" role="menu">
                                        
                                        <!-- teacher EDITING LINK -->
                                      
											<?php
										if($usertype=="admin"){
											
											?>
											<!--
											  <li> 
										 <a 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> 
				<a  id="more" class=" btn-success"  href="<?php echo base_url();?>user/viewmyexpense?searchterm=<?php   {echo  $c->ordernumber;}  ?>&finaltotal=<?php   {echo  $c->ordernumber;}  ?>">
								 
																							 

                                                <i class="glyphicon glyphicon-pencil"></i>
																Expenses
                                                </a>
																		
										</li>
									
                                        <li class="divider"></li>
                                        <li> 
				<a  id="more" class=" btn-success"  href="<?php echo base_url();?>user/searchJE?searchterm=<?php   {echo  $invoice_number;}  ?> ">
								 
																							 

                                                <i class="glyphicon glyphicon-pencil"></i>
															View	GL Transactions
                                                </a>
																		
										</li>
                                        
                                    </ul>
										
                                </div>
</td>
                  
             </tr>

	<?php endforeach;} ?>

              <?php }?>
 								<tr border="1" background="green">
									<td colspan="2"> <b>Total amount</b></td>

									<td><input type="text" name="total" style="background:#999999 ; width:100px" readonly="true"  value="<?php if(isset($totalamount)) {echo formatMoney($totalamount, true);   }?>" class="form-field"/> </td>
</td>
	<td colspan="7"></td>								
</tr>
	
        </table>
		<div class="col-md-12 text-center">    <?php echo $links; ?>
					   		<span style="color:red; font-size:20px"><?php  echo $total_rows. " 	Record(s). " ;?>    </span>

        
        </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  Business/Customer</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"id="status" class="form-control" required placeholder="Enter status">

<input type="hidden" name="view" value="user/salesorder"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"  selected="selected">Customer</option>
		<option value="supplier"  >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="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="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" id="groupname" >		
    <label for="inputcategoryid" class="col-sm-2 control-label">Default Group Name?</label>
    <div class="col-sm-10">
	<select class="form-control" name="categoryid" >
	
	<option value=""  >---Select Group Name---</option>

	
	<?php 
					 
				$mycategory = $this->usermodel->populatecategory($companyid);
	
	


if(is_array($mycategory)) {

   foreach($mycategory as $mycategoryrow){

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



	<?php

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

	</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 / Details / Remarks</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-primary"> Add Business / Customer   </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">Sales order Report</h4>
      </div>
      <div class="modal-body">
      
	  	

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

				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/viewsalesordereport' , 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-3 control-label">Counter</label>
    <div class="col-sm-9">
	<select class="form-control" name="branchname"  id="branchname" required>
	
	
	<option value=""  >---Select Branch/Counter Name--</option>
<?php
										 ?>
					<option value="all"  >All branches/Counters</option>
									<?php
									
							
				 
					 		$maincategory = $this->usermodel->populateall('branch','companyid',$companyid);


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

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



	<?php

}} else {
    echo 'No main counter available.';
}

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


							


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="inputfromdate" class="col-sm-3 control-label">From Date </label>
    <div class="col-sm-9">
	
		  		<input type="text" name="fromdate" value="<?php echo set_value('fromdate',$mydates); ?>" 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-3 control-label">	To Date </label>
    <div class="col-sm-9">
	
		  		<input type="text" name="todate" value="<?php echo set_value('todate',$mydates1); ?>" class="form-control" required placeholder="Enter End date">
		 
				
		<span class="text-danger"> <?php echo form_error('todate'); ?>
		
		</span>
	</div>
  </div>
  
  
    <div class="form-group">
    <label for="inputsupplier" class="col-sm-3 control-label">supplier?</label>
    <div class="col-sm-9">
	<select class="form-control" name="supplier" required>
	
	<option value=""  >---Select supplier---</option>

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

	
if(is_array($mysuppliers)) {

   foreach($mysuppliers as $suppliersrow){

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



	<?php

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

	</div>
  </div>
  
 <div class="form-group">
    <label for="inputdownload" class="col-sm-3 control-label">Download?</label>
    <div class="col-sm-9">
	<select class="form-control" name="download" required>
	
	<option value=""  >---Select your option---</option>

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

</select>
		

	</div>
  </diV>
	
				  <div class="form-group">
    <label for="inputsupplier" class="col-sm-3 control-label">Route / Category</label>
    <div class="col-sm-9">
				
	
		
		
		
				
				<select class="form-control" name="mytable"  id="mytable" >
	
	
	<option value=""  >---Select</option>
	<option value="all" selected="selected"  >---All--</option>

	<?php 
					 
					 		$maincategory = $this->usermodel->populateall('tables','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">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="event" name="btn_addevent" class="btn btn-primary"> View Sales Order  </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/salesorder">
 <input type="hidden" id="itemid1"name="itemid" class="itemid" placeholder="itemid" value=""><br>
 <button type="button" class="btn btn-success" data-dismiss="modal">No</button>
 		  	         <button type="submit" name="btn_delete" value="deletebyid" class="btn btn-danger"> Delete  </button>

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

  </div>

  </div>		
	
	
	
	<div id="addCategoryModal" 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">Category Daily summary Report</h4>
      </div>
      <div class="modal-body">
      
	  	

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



				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/viewgroupsalesreportcategory' , array('class' => 'form-horizontal form-groups-bordered validate', 'enctype' => 'multipart/form-data'));
				 if(validation_errors()):?>
<div class='alert alert-danger text-center'><?php echo validation_errors(); ?></div>
<?php endif;?>


  <div class="form-group">
    <label for="inputbranchname" class="col-sm-2 control-label">Counter</label>
    <div class="col-sm-10">
	<select class="form-control" name="branchname"  id="branchname" required>
	
	
	<option value=""  >---Select Branch/Counter Name--</option>
<?php
									 if( $viewallaction==true){
										 ?>
					<option value="all"  >All branches/Counters</option>
									<?php
									 }
							
	?>
	
	<?php 
					 
					 		$maincategory = $this->usermodel->populateall('branch','companyid',$companyid);


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

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



	<?php

}} else {
    echo 'No main counter available.';
}
	
?>
</select>
		

		
	</div>
  </div>
  
  
  
  
  
  
   <div class="form-group">
    <label for="inputuser" class="col-sm-2 control-label">User?</label>
    <div class="col-sm-10">
	<select class="form-control" name="user" required>
	
	<option value=""  >---Select user---</option>

						<?php
		
		 
			?>
						<option value="all" selected="selected"  >All 	users</option>
<?php


							$allusers = $this->usermodel->populatealldatanoarraythree('people', 'companyid',$companyid,'status',1,'category','user');

 
  

  ?>

	
	
	
	<?php 
				
				
	

	
if(is_array($allusers)) {

   foreach($allusers as $userrow){

   //echo $courserow->coursename;
    ?>
					<option value="<?=  $userrow->id;   ?>"><?=  $userrow->firstname ."- ".$userrow->surname ."(". $userrow->email.")"; ?></option>



	<?php

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

	</div>
  </div>
  
  
  
  
  
    <div class="form-group">
    <label for="inputsupplier" class="col-sm-2 control-label">Customer name</label>
    <div class="col-sm-10">
	
		  		<input type="text" name="customer" id="mysupplier" autofocus value="<?php echo set_value('supplier',"all"); ?>" class="form-control" required placeholder="Enter Customer/Supplier name">
		 
				
		<span class="text-danger">Enter "all" to view everyone <?php echo form_error('supplier'); ?>
		
		</span>
	</div>
  </div>
  
  
  
  
  
  
       <div class="form-group">
	 
	 
	 
    <label for="inputpaymentstatus" class="col-sm-2 control-label">Sales Status</label>
    <div class="col-sm-10">
	<select class="form-control" name="paymentstatus" required>
	<option  value="all"  >---All/Any sales status--</option>
   <option value="Cleared">Cleared</option>
   <option value="No">No (Not cleared)</option>

	 <option value="Pending">Pending</option>
									  
									  				


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

	</div>
  </div>



		  <div class="form-group">
    <label for="inputsupplier" class="col-sm-2 control-label">Route / Category</label>
    <div class="col-sm-10">
				
	
		
		
		
				
				<select class="form-control" name="mytable"  id="mytable" >
	
	
	<option value=""   >---Select route</option>
	<option value="all"  selected="selected" >-All/Everything</option>

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


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

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



	<?php

}} else {
    echo 'No main counter available.';
}
 
?>
</select>
		
				
		</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($mydates))); ?>"   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',"00:00:00"); ?>" class="form-control" required placeholder="Enter start time">

					</div>
				</div>
			

			
			
						    <label for="inputfromdate" 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($mydates1))); ?>" 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:00"); ?>" class="form-control" required placeholder="Enter stop time">

					</div>
				</div>
			
	
  
  
	 <div class="form-group">
	 
	 
	 
    <label for="inputtype" class="col-sm-2 control-label">Sales types</label>
    <div class="col-sm-10">
	<select class="form-control" name="type" required>
	<option  value="all"  >Both Paid and Credit sales--</option>
   <option value="Cash">All Paid Sales Only </option>
 <option value="Invoice">Credit/Invoice Sales Only</option>
   <option value="cash">Paid through Cash</option>
   <option value="mpesa">Paid through Mobile Money</option>
   <option value="card">Paid through Card</option>
   <option value="bank">Paid through Bank</option>
   <option value="points">Paid through Points</option>
   <option value="voucher">Paid through Voucher</option>
   <option value="creditnote">Paid through Creditnote</option>

									  
									  				


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

	</div>
  </div>



     <div class="form-group" >
	 
	 
	 
    <label for="inputdisplay" class="col-sm-2 control-label">Report type?</label>
    <div class="col-sm-10">
	<select class="form-control" name="display" required>
	<option  value=""  >---Which type of report do you need--</option>
		<option selected="selected" value="summary" >Summary</option>
		<option value="detailed" >Detailed (Item/ Product based)</option>

	

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

	</div>
  </div>
         <div class="form-group" style="display:none">
	 
	 
	 
    <label for="inputgroup" class="col-sm-2 control-label">Group </label>
    <div class="col-sm-10">
	<select class="form-control" name="group" required>
	<option  value="all"    >---Do you want to group sales --</option>
		<option  value="no" selected="selected"   >---No Grouping--</option>

   <option value="Daily">Daily</option>
   	 <option value="Weekly">Weekly</option>
   <option value="Monthly">Monthly</option>
   	 <option value="Yearly">Yearly</option>

								
									  
									  				


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

	</div>
  </div>
     <div class="form-group" style="display:none">
	 
	 
	 
    <label for="inputcollections" class="col-sm-2 control-label">Display collections?</label>
    <div class="col-sm-10">
	<select class="form-control" name="collections" required>
	<option  value=""  >---Do you want group collections?-</option>
<option  value="no">No grouping</option>
	<option value="yes" selected="selected" >Allow Grouping</option>


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

	</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=""  >---Do you want to download report in Excel--</option>
<option selected="selected" value="no">No (I just want to  view sales)</option>
	<option value="yes" >Yes(I want to download)</option>


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

	</div>
  </div>
	

	
	 <div class="form-group">

    <div class="col-sm-offset-2 col-sm-10">
     
	         <button type="submit"  value="event" name="btn_addevent" class="btn btn-primary"> View Report </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 Sales Order</h4>
      </div>
      <div class="modal-body">
      
	  	

				<?PHP
//$session_data = $this->session->userdata('logged_in');
  $myconfiguration = $this->usermodel->populateallarray('smsconfig','id',$companyid);
	$ordeno=$myconfiguration[0]["website"]; 
	
$myno=$ordeno;

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

<input type="hidden" name="view" value="user/viewnewsalesorder?randomitemidentifier=" class="form-control" required placeholder="Enter invoiceno">
								<input type="hidden" name="paymentmethodes" value="" class="form-control" required placeholder="Enter invoiceno">


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

								<input type="hidden" name="status" value="s.o" class="form-control" required placeholder="Enter sales">







					  <div class="form-group">
    <label for="inputsupplier" class="col-sm-3 control-label">Posting Branch</label>
    <div class="col-sm-9">
				
	
		
		
		
				
				<select class="form-control" name="branchid"  id="branchid" required>
	
	
	<option value=""  >---Select Branch/Counter Name--</option>
<?php
									 if( $viewallaction==true){
										 ?>
									<?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.';
}
 }else{
?>
	<?php 
					 
					 		$maincategory = $this->usermodel->populateall('branch','id',$branchid);


							


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" 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">
    <label for="inputsupplier" class="col-sm-3 control-label">Customer?</label>
    <div class="col-sm-9">
		
			  		<input type="text" name="supplier" id="customer" 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="inputagent" class="col-sm-3 control-label">Sales person/ Agent?</label>
    <div class="col-sm-9">
		
			  		<input type="text" name="agent" id="agent" autofocus value="<?php echo set_value('agent'); ?>" class="form-control"  placeholder="Enter agent/ sales person">

		
				
		<span class="text-danger"> 	<?php echo form_error('supplier'); ?>
		
		</span>
	</div>
  </div>	
		
			<div class="form-group">
    <label for="inputordernumber" class="col-sm-3 control-label">Sales Order  No: </label>
    <div class="col-sm-9">
	
		  		<input type="text"  name="ordernumber" value="<?php echo set_value('ordernumber',$myno.$total_rows); ?>"  class="form-control"  placeholder="Enter  order number ">
		 
				
		<span class="text-danger"> <?php echo form_error('ordernumber'); ?>
		
		</span>
	</div>
  </div>

			<div class="form-group">
    <label for="inputinvoice" class="col-sm-3 control-label">Ref  No: </label>
    <div class="col-sm-9">
	
												<input type="text" name="invoice" value="<?php echo set_value('invoiceno',$finalsalesid); ?>" class="form-control" required placeholder="Enter Ref No">
		 
				
		<span class="text-danger"> <?php echo form_error('invoice'); ?>
		
		</span>
	</div>
  </div>

	
  	

				
			  <div class="form-group">
    <label for="inputorderdate" class="col-sm-3 control-label">Sales Order Date </label>
    <div class="col-sm-9">

	<input type="text" name="orderdate" value="<?php echo set_value('orderdate',$mydate); ?>"id="orderdate" class="form-control" required placeholder="Enter specific order date  (dd-mm-YYY) ">
			<span class="text-danger"> <?php echo form_error('orderdate'); ?>
		
		</span>
	</div>
  </div>		
			
		
					  <div class="form-group">
    <label for="inputcanceldate" class="col-sm-3 control-label">Due Date </label>
    <div class="col-sm-9">

	<input type="text" name="canceldate" value="<?php echo set_value('canceldate',$mydates1); ?>"id="canceldate" class="form-control" required placeholder="Enter Exp Expiry Date order date  (dd-mm-YYY) ">
			<span class="text-danger"> <?php echo form_error('canceldate'); ?>
		
		</span>
	</div>
  </div>		
		
		 
		<div class="form-group">
    <label for="inputorderedby" class="col-sm-3 control-label">	Ordered by: </label>
    <div class="col-sm-9">
	
		  		<input type="text" name="orderedby" value="<?php echo set_value('orderedby'); ?>" class="form-control"  placeholder="Enter  contact Name for Sales Order ">
		 
				
		<span class="text-danger"> <?php echo form_error('orderedby'); ?>
		
		</span>
	</div>
  </div>
	
			
	
						
			  <div class="form-group">
    <label for="inputterms" class="col-sm-3 control-label">Terms of payment </label>
    <div class="col-sm-9">

	<input type="text" name="terms" value="<?php echo set_value('terms'); ?>"id="terms" class="form-control"  placeholder="Enter Terms of payment  ">
			<span class="text-danger"> <?php echo form_error('terms'); ?>
		
		</span>
	</div>
  </div>		
				
			  <div class="form-group" style="display:none">
    <label for="inputfob" class="col-sm-3 control-label">Freight On Board </label>
    <div class="col-sm-9">

	<input type="text" name="fob" value="<?php echo set_value('fob',"Road"); ?>"id="fob" class="form-control"  placeholder="Enter person in charge   ">
			<span class="text-danger"> <?php echo form_error('fob'); ?>
		
		</span>
	</div>
  </div>		
		
		
		
		
		
		
	

			    <div class="form-group" style="display:none">
    <label for="inputamount" class="col-sm-3 control-label">Total Amount   </label>
    <div class="col-sm-9">
		
				<input type="text" name="amount" readonly value="<?php echo set_value('0') ;?>" id="amount" class="form-control"   placeholder="Please total amount is automatic ">

				
		</span>
	</div>
  </div>
	
 
  	    <div class="form-group">
    <label for="inputdeliverymethod" class="col-sm-3 control-label"> Delivery Method:   </label>
    <div class="col-sm-9">
		
				<input type="text" name="deliverymethod" value="<?php echo set_value('deliverymethod') ;?>" id="dob" class="form-control"   placeholder="Please provide delivery method ">

				
		
	</div>
  </div>
  	

				
  
					  <div class="form-group">
    <label for="inputsupplier" class="col-sm-3 control-label">Route / Category</label>
    <div class="col-sm-9">
				
	
		
		
		
				
				<select class="form-control" name="mytable"  id="mytable" >
	
	
	<option value="" selected="selected" >---Select</option>

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


							


if(is_array($maincategory)) {

   foreach($maincategory as $maincategoryrow){

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



	<?php

}} else {
    echo 'No main counter available.';
}
 
?>
</select>
		
				
		</div>
  </div>
					
			


  
  
  <div class="form-group">
    <label for="inputshippingto" class="col-sm-3 control-label">Shipping to details..</label>
    <div class="col-sm-9">

	<textarea name="shippingto" class="form-control" placeholder="Shipping to details."><?php echo set_value('shippingto'); ?></textarea> 
			
	</div>
  </div>
<div class="form-group">
    <label for="inputdescription" class="col-sm-3 control-label">Note/Message</label>
    <div class="col-sm-9">

	<textarea name="description" class="form-control" placeholder="Bussines/comments/note"><?php echo set_value('description'); ?></textarea> 
			
	</div>
  </div>
  

  
  	

	
	 <div class="form-group">

    <div class="col-sm-10">
     
	         <button type="submit"  name="btn_purchaseorder"  value="mysalesorder"  class="btn btn-primary"> NEXT >> </button>

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

    

				</div>
				</div>
	

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

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

 
</div>


















