
 

         <script type="text/javascript">
  
		
		 $(document).on("click", "#managebtndelete", function()
        {
          var itemid = $(this).data('id');
		  $("#itemid1").val(itemid); 
		  
		  
		   
        });
		
		
		
    </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 viewloyality</span>
	  <a data-toggle='modal' data-target='#addModal' class="btn btn-primary">Add Points </a>
	  
	   <a data-toggle='modal' data-target='#uploadModal' class="btn btn-default">Update Balances  </a>
		  <a href="<?php echo base_url();?>user/viewvoucher" class="btn btn-info">  Create Vouchers </a>	

	  
				
            	</div>
            </div>
			<div class="panel-body">
			
	<div class="widget-content nopadding table_holder table-responsive" >	
	<div class="col-md-12">
        <?php 
		
        $attr = array("class" => "form-horizontal", "role" => "form", "id" => "search", "name" => "search");
        echo form_open("user/searchforloyalitypoints", $attr);?>
            <div class="form-group">
			
                <div class="col-md-5">
                    <input class="form-control" autofocus id="searchterm" name="searchterm" placeholder="Search for custoner by card or phone number, description etc.." type="text" value="<?php echo set_value('searchterm'); ?>" />
                </div>
				
				  <div class="col-md-2">
					<select class="form-control" name="type" required>
	
	<option value=""  >---Select type---</option>
<option value="all"  selected="selected" >-All-</option>
		<option value="Points"  >Points</option>
		<option value="Coins"  >Coins</option>

	
</select>
	  </div>			
                <div class="col-md-4">
                    <input id="btn_search" name="btn_search" type="submit" class="btn btn-default" value="Search" />
                    <a href="<?php echo base_url(). "user/viewloyality"; ?>" class="btn btn-default">Refresh</a>
                </div>
				 
            </div>
        <?php echo form_close(); ?>

        </div>	
		<?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'];	

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

             <thead>
         <tr>
		     <th>Type</th>
     <th>Card Number</th>
     <th>Customer</th>
	     <th>Points</th>
		   <th>Saved Amnt</th>
		   
		      <th>Original Amnt</th>
		   
		   

				   <th>Added by</th>
		   <th>Invoice</th>
				   <th>Date</th>

	<th>More</th>
		


                 </tr>
             </thead>
<?php
  $totalpoints=0;
$totalsavings=0;
$totaloriginal=0;

 if(!is_array($viewloyality)) 

 {


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


  	foreach ($viewloyality as $c): 

$totalpoints=$totalpoints+$c->value ;
$totalsavings=$totalsavings+$c->amount;
$totaloriginal=$totaloriginal+$c->originalamount;

             ?>



             <tr>
                
            <?php 
$id=$c->id;


?>

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

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

  
  
   <td><?php ; 
						   	
		$people = $this->usermodel->populateallarray('people','address_1',$c->cardnumber);
		  $fname=$people[0]['firstname'].$people[0]['surname']; 
		if($fname!=""){
			echo  $fname;
		}else{
			$people2 = $this->usermodel->populateallarray('people','phone',$c->cardnumber);
		 echo $fname2=$people2[0]['firstname'].$people[0]['people2'];; 
			
		}
		
 

  
  ?></td>
    <td><?php echo $c->value ; ?></td>
	    <td><?php echo $c->amount ; ?></td>
			    <td><?php echo $c->originalamount ; ?></td>


		
	
	
	   <td><?php ; 
   $customer_id=$c->userid;
   if($customer_id!=""){
	  
      $myname = $this->usermodel->getemployee($customer_id);
  
     $fname=$myname[0]['firstname']; 
  $lname=$myname[0]['lastname'];
echo $names=$fname;
   }else{
	    echo "No customer";  
   }
  
  
  ?></td>
					    <td><?php echo $c->invoice ; ?></td>
    <td><?php echo $c->dateposted ; ?></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>
									<?php
										if($usertype=="admin"){
											
											?>
                                    <ul class="dropdown-menu dropdown-primary pull-right" role="menu">
                                        
                                        <!-- teacher EDITING LINK -->
                                      
										
											  <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>
									
									
                                        <li class="divider"></li>
                                        
                                        <!-- teacher DELETION LINK -->
                                        
                                    </ul>
											<?php
										}
										?>
                                </div>
</td>
     	
                  
     		  
             </tr>

	<?php endforeach;} ?>

     
			    <tfoot>
         <tr>

     <th colspan="2">TOTAL </th>
		<th>Poists:</th>
		
			<th><?php  echo formatMoney($totalpoints, true);  ?> </th>
			<th><?php  echo formatMoney($totalsavings, true);  ?> </th>
	<th><?php  echo formatMoney($totaloriginal, true);  ?> </th>
	 			<th> </th>

     <th colspan="4"> </th>

              


			  </tr>
             </tfoot>

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

        
        </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="loyalitycards">

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

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

  </div>

  </div>		






						<div id="uploadModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">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/viewpoints' , 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="inputtype" class="col-sm-2 control-label">Category?</label>
    <div class="col-sm-10">
	<select class="form-control" name="type" required>
	

		<option value="all"  >Points/Coins</option>
	

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

	</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="view"  >I just want to view</option>
		<option value="update"  >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="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 Points</h4>
      </div>
      <div class="modal-body">
      
	  	

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


				echo $this->session->flashdata('msg'); 
		
                 echo form_open('user/addloyality' , 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="inputtransactiontype" class="col-sm-2 control-label">Transaction Type?</label>
    <div class="col-sm-10">
	<select class="form-control" name="transactiontype" required>
	
	<option value=""  >---Select Transaction---</option>

		<option value="Post"  >Post points/saving</option>
		<option value="Redeem"  >Redeem Points/Saving</option>

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

	</div>
  </div>
			<div class="form-group">
    <label for="inputcardnumber" class="col-sm-2 control-label">	Card/ID/ Phone Number </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="cardnumber" value="<?php echo set_value('cardnumber'); ?>" class="form-control" required placeholder="Enter card number">
		 
				
		<span class="text-danger"> <?php echo form_error('cardnumber'); ?>
		
		</span>
	</div>
  </div>		  		


  
  <div class="form-group">
    <label for="inputvalue" class="col-sm-2 control-label">	Amount </label>
    <div class="col-sm-10">
	
		  		<input type="text" name="value" value="<?php echo set_value('value'); ?>" class="form-control" required placeholder="Enter total amount or coins">
		 
				
		<span class="text-danger"> <?php echo form_error('value'); ?>
		
		</span>
	</div>
  </div>
  
  
  
  

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

		<option value="Points"  >Points</option>
		<option value="Coins"  >Coins</option>

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

	</div>
  </div>
  
	<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'); ?>"  class="form-control"  placeholder="Enter description"></textarea>
			
		<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="loyatity" name="btn_addloyality" class="btn btn-primary"> Add Points   </button>

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

    

				</div>

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

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

 
</div>


















