<?php
        include("homeheader.php");
		  
		   
		if(isset($_POST['submit_airtime'])){
			$grp = $_POST['selectgrp'];
		    $amnt = $_POST['amount'];
		   $memberid = "";
		
		if($grp == "--Select Group--" || empty($amnt) ) {
			?>
				<script>
					alert("Select the Group to send Airtime to.");
					window.location="sendtogroup.php";
				</script>
			<?php
			
							/*   echo ' <div class="col-md-offset-3 col-md-9">
                                        <button id="btn-signup" type="button" class="btn btn-error"><i class="icon-hand-right"></i>Error! Select Group and Enter Amount First. </button>
										</div> ';
										*/
			// header("Location: sendtogroup.php");
		}
		}
		else{
						$grp = $_GET['gid'];
						$gid = $_GET['gid'];
						$s=mysql_query("select * from airtime_groups where group_id='$grp' ");
						$cdt=mysql_fetch_array($s);
						$grp = $cdt['name'];
						$amnt = $_GET['amount'];
						$memberid = $_GET['cid'];
			
		}
    ?>

  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-3 left_col">
          <div class="left_col scroll-view">
            <!--div class="navbar nav_title" style="border: 0;">
              <a href="index.html" class="site_title">
			  <div class="profile_pic" style="margin-top:-10px;">
			  <img src="images/mlogo.png" alt="" class="img-circle profile_img" />
			    </div>
			  <!--i class="fa fa-paw"></i--> <!--span>Instant Airtime </span></a>
            </div-->

            <div class="clearfix"></div>

			
            <!-- menu profile quick info -->
            <div class="profile">
              <div class="profile_pic">
			   <?php 
			  if($img == ""){
				  ?>
				   <img src="profileimages/noimage.gif" alt="..." class="img-circle profile_img">
				  <?php
			  }else{
				?>
				 <img src="<?php echo $photo ?>" alt="..." class="img-circle profile_img" width="40px;" height="60px;">
            <?php				
			  }
			  ?>
              </div>
             <div class="profile_info">

                <span>Welcome,</span>
				<h2> <?php $fname = $dat['fname']; $lname = $dat['lname']; echo $fname." ".$lname ?> </h2>
             <!--   <h2>John Doe</h2> -->
              </div>
            </div>
            <!-- /menu profile quick info -->

            <br />

            <!-- sidebar menu -->
            <div id="sidebar-menu" class="main_menu_side hidden-print main_menu">
              <div class="menu_section">
			  <br/>
                <h3>General</h3>
                <ul class="nav side-menu">
                  <li ><a  href="homepage.php" ><i class="fa fa-home"></i>  Home <span class="fa fa-chevron-right"></span></a> </li>
                  <li ><a><i class="fa fa-building"></i> My Contacts <span class="fa fa-chevron-down"></span></a> 
				    <ul class="nav child_menu">
					    <li><a  href="addcontact.php" ><i class="fa fa-user-plus"></i>Add New Contact<span class="fa fa-chevron-right"></span></a> </li>
						<li><a  href="addnewcontact.php" ><i class="fa fa-eye"></i>View Contacts<span class="fa fa-chevron-down"></span></a> 
						<!--ul class="nav child_menu">
						 <li><a  href="addnewcontact.php" ><i class="fa fa-bug"></i>List<span class="fa fa-chevron-right"></span></a> </li>
						<li><a  href="viewcontacts.php" ><i class="fa fa-bug"></i>Grid<span class="fa fa-chevron-right"></span></a> </li>
						</ul-->
						</li>
					   </ul>
				  </li>
                  <li ><a><i class="fa fa-users"></i> Groups <span class="fa fa-chevron-down"></span></a> 
				        <ul class="nav child_menu">
					   <li><a  href="creategroup.php" ><i class="fa fa-paw"></i>Create Group<span class="fa fa-chevron-right"></span></a> </li>
						<li><a  href="viewgroups.php" ><i class="fa fa-eye"></i>View Groups<span class="fa fa-chevron-right"></span></a> </li>
					   </ul>
				  </li>
                  <li class="active" ><a><i class="fa fa-table"></i> Topup <span class="fa fa-chevron-down"></span></a>  
				   <ul class="nav child_menu">
						<li><a  href="sendtogroup.php" ><i class="fa fa-cloud-download"></i>Topup To Group<span class="fa fa-chevron-right"></span></a> </li>
						<li><a  href="selectcontacttosend.php" ><i class="fa fa-building"></i>Select from Contacts<span class="fa fa-chevron-right"></span></a> </li>
						<li><a  href="sendtome.php" ><i class="fa fa-mobile"></i> Topup My Line<span class="fa fa-chevron-right"></span></a> </li>
						 <li><a href="autosend-airtime.php" ><i class="fa fa-recycle"></i> Auto-Send Airtime <span class="fa fa-chevron-right"></span></a> </li>
					   </ul>
					  				  
				  </li>
                   <li><a><i class="fa fa-gg"></i> Billing <span class="fa fa-chevron-down"></span></a> 
				   <ul class="nav child_menu">
                     <li><a  href="purchasetome.php" ><i class="fa fa-server"></i> Top-up My Account<span class="fa fa-chevron-right"></span></a> </li>
					   </ul>
				  </li>
				   <li><a><i class="fa fa-bar-chart-o"></i> View Reports <span class="fa fa-chevron-down"></span></a>  
				      <!--  <ul class="nav side-menu"> -->
					   <ul class="nav child_menu">
						<li><a  href="creditassignment.php" ><i class="fa fa-bars"></i>Credit Assignment<span class="fa fa-chevron-right"></span></a> </li>
					   </ul>
				   </li>
                </ul>
              </div>

            </div>
			 </div>
        </div>
		
		<?php include("topmenubar.php"); ?>
			 
		 <!-- page content -->
        <div class="right_col" role="main">
		  <!-- /top navigation -->
		     <div class="row">
          <!-- top tiles -->
          <div class="row tile_count">
            <div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count">
              <p> </p>
            </div>
          </div>
		  </div>
          <!-- /top tiles -->
		    <div class="x_title">
                    <h2>Send Airtime to &nbsp;<b><u><?php echo $grp; ?></u></b>&nbsp;&nbsp; Group </h2> 	
                    <div class="clearfix"></div>
                  </div>
		 
		 <div class="row" >
		 <?php 
			
		  $dt = mysql_query("select * from airtime_groups where customer_id = '$session_id' and name = '$grp' "); 
				$rst = mysql_fetch_array($dt);
				$gid=$rst['group_id'];
				
		 ?>
		               <!-- send credit form -->
			  <!--form name="contacts" data-parsley-validate class="form-horizontal form-label-left" method="post" action="">
			   <!-- Search Button -->
			   <!--input type="hidden"  id="grop" name="grop" value="<?php echo $grp; ?>"/>
			   <input type="hidden" id="pay" name="pay" value="<?php echo $amnt; ?>"/>
			   <input type="hidden" id="grupid" name="grupid" value="<?php echo $gid; ?>"/-->
					  	
							
					<!--div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-3" for="first-name" style="color:#FF5722;"><b><u>Name </b></u></label>
						 <label class="control-label col-md-3 col-sm-3 col-xs-3" for="first-name" style="color:#FF5722;"><b><u>Contact </b></u></label>
                        <label class="control-label col-md-3 col-sm-3 col-xs-3" style="color:#FF5722;margin-left:-80px;" ><b><u> Amount  </b></u></label>
                        <label class="control-label col-md-3 col-sm-3 col-xs-3" style="color:#FF5722;margin-left:-80px;" ><b><u> Send Airtime  </b></u></label>
					</div-->
					  
					  <div class="x_content">
					
							
					  <?php
					  if(empty($memberid)){
						  ?>
						  <table id="datatable" class="table table-striped table-bordered">
								<thead>
									<tr>
										<th style="color:#FF5722;"><b>Name</b></th>
										<th style="color:#FF5722;"><b>Contact</b></th>
										<th style="color:#FF5722;"><b>Amount</b></th>
										<th style="color:#FF5722;"><b>Send Airtime</b></th>
									</tr>
								</thead>
							<tbody>
						 <?php 
						  $s = mysql_query("select * from airtime_groups where customer_id = '$session_id' and name = '$grp' "); 
						$rst1 = mysql_fetch_array($s);
						$gid1 = $rst1['group_id'];
					 
						$c = mysql_query("select * from airtime_contacts where customer_id = '$session_id' and group_id = '$gid1' limit 500");
						$records = mysql_num_rows($c);
						$phone_numbers = array();
						$count = 0;
						while($row=mysql_fetch_array($c)){
							?>
							<tr>
								<td><label  for="first-name"><?php echo $row['fname']." ".$row['lname']; ?> </label> </td>
								<td><label  for="first-name"><?php echo $row['contact']; ?> </label> </td>
								<form name="dataform" method="post">
								<td> 
								<input style="display:none;" type="text" value="<?php echo $row['contact_id']; ?>" name="id" />
								<input style="display:none;" type="text" value="<?php echo $row['contact']; ?>" name="phne" />
								<input style="display:none;" type="text" value="<?php echo $gid1; ?>" name="gid" />
								<input style="display:none;" type="text" value="<?php echo $amnt; ?>" name="amt" />
								<input type="text" name="amount" value="<?php echo $amnt; ?>" /> 
								</td>
								<td> <button type="submit" class="btn btn-primary" name="send_to_individual" > Send </button> </td>
								</form>
								</tr>	
						<?php
			
						}
						?>
						    </tbody>
                    </table>
					
						  <?php
					   if(isset($_POST['send_to_individual'])){
						   
						   $contactid = $_POST['id'];
						    $grpx = $_POST['gid'];
						    $send_amnt = $_POST['amount'];
							
						   	$bal=$usrcr['amount'];
						if($bal==0){
						// no credit
							?>
								<script>
									alert("Error! Your account balance is insufficient. Please topup your account.");
										window.location="sendtogrp.php?gid=<?php echo $grpx; ?>&&amount=<?php echo $send_amnt; ?>";
								</script>
							<?php
							}else{
							
								$mid = $_POST['id'];
								$mnt = $_POST['amount'];
								$phone = $_POST['phne'];
								
								if(!empty($mnt)){
									
									 $amount = (int)$mnt;
									 
									 if($amount > $bal){
									?>
										<script>
											alert("Error! Your account balance is insufficient to send <?php echo "Ksh. ".$amount; ?>. Your account balance is <?php echo "Ksh. ".$bal; ?>. Please topup your account.");
											window.location="sendtogrp.php?gid=<?php echo $grpx; ?>&&amount=<?php echo $send_amnt; ?>";
										</script>
									<?php
								
									}else{
										// send airtime to the selected contact 
										$username = $get_credentials['username'];
										$password = $get_credentials['password'];
							
										// send airtime		
										$parameters = "username=$username&password=$password&recipient=$phone&amount=$amount";
										$url = "http://www.mobisky.biz/api/sendairtime.php?$parameters";
										//fopen("$url","r"); 
		
										$ch = curl_init();
										// set URL and other appropriate options
										curl_setopt($ch, CURLOPT_URL, "$url");
										curl_setopt($ch, CURLOPT_HEADER, 0);
										// Pass it to the browser
										curl_exec($ch);
		
											if(curl_error($ch)) {
												echo 'error:' . curl_error($ch);
										    }
										// close cURL resource, and free up system resources
										curl_close($ch);	
							 
									  //insert data 
									$qry =	mysql_query("insert into airtime_sending_records values('','$session_id','$amount','$phone',Now(),'1') ");
									
									// update account balance
								//		$availbal = ((int)$bal) -  $amount;
								//	$query = mysql_query("update airtime_user_credits set current_amount='$availbal', last_updated=Now() where customer_id='$session_id'");
									
										$qry2 = mysql_query("select * from airtime_logs where id='$session_lid' ");
										$sdata=mysql_fetch_array($qry2);
										$actions=$sdata['user_actions'];
										$query  = mysql_query("update airtime_logs set user_actions='$actions Sent Airtime to phone no. $phone Ksh. $amount.' where id='$session_lid'  ");
						
									if($query){
										?>
											<script>
												alert("Airtime Successfully sent.");
												window.location="sendtogrp.php?gid=<?php echo $grpx; ?>&&amount=<?php echo $mnt; ?>&&cid=<?php echo $mid; ?>";
											</script>
										<?php
									}else{
										?>
											<script>
												alert("Error sending airtime. Please try again.");
												window.location="sendtogrp.php?gid=<?php echo $grpx; ?>&&amount=<?php echo $mnt; ?>";
											</script>
										<?php
									}
										
										
									}
								}else{
									// amount field empty
										?>
								<script>
									alert("Error! Amount field cannot be empty. Please try again.");
										window.location="sendtogrp.php?gid=<?php echo $grpx; ?>&&amount=<?php echo $mnt; ?>";
								</script>
							<?php
								}
							
							
							} 
						  
					  }
					  ?>
                 
						<?php
					  }else{
						  ?>
						  <table id="datatable" class="table table-striped table-bordered">
								<thead>
									<tr>
										<th style="color:#FF5722;"><b>Name</b></th>
										<th style="color:#FF5722;"><b>Contact</b></th>
										<th style="color:#FF5722;"><b>Amount</b></th>
										<th style="color:#FF5722;"><b>Send Airtime</b></th>
									</tr>
								</thead>
							<tbody>
							<?php
							$s2 = mysql_query("select * from airtime_groups where customer_id = '$session_id' and name = '$grp' ");
							$rst2 = mysql_fetch_array($s2);
							$gid2 = $rst2['group_id'];
					 
							$c = mysql_query("select * from airtime_contacts where customer_id = '$session_id' and group_id = '$gid2' and contact_id != '$memberid' limit 500");
							$records = mysql_num_rows($c);
							$phone_numbers = array();
							$count = 0;
							
							while($row=mysql_fetch_array($c)){
								?>
								<tr>
								<td><label  for="first-name"><?php echo $row['fname']." ".$row['lname']; ?> </label> </td>
								<td><label for="first-name"> <?php echo $row['contact']; ?> </label> </td>
								<form name="datafrm" method="post">
								<td> 
								<input style="display:none;" type="text" value="<?php echo $row['contact_id']; ?>" name="id" />
								<input style="display:none;" type="text" value="<?php echo $row['contact']; ?>" name="phne" />
								<input style="display:none;" type="text" value="<?php echo $gid2; ?>" name="gid" />
								<input style="display:none;" type="text" value="<?php echo $amnt; ?>" name="amt" />
								<input type="text" name="amount" value="<?php echo $amnt; ?>" />  
								</td>
								<td> <button type="submit" class="btn btn-primary" name="send__individual" > Send </button> </td>
								</form>
								</tr>
						<?php
						}
						?>
						    </tbody>
                    </table>
					
						  <?php
					   if(isset($_POST['send__individual'])){
						   
						   $contactid = $_POST['id'];
						    $grp = $_POST['gid'];
						    $send_amnt = $_POST['amount'];
							
						   	$bal=$usrcr['amount'];
						if($bal==0){
						// no credit
							?>
								<script>
									alert("Error! Your account balance is insufficient. Please topup your account.");
										window.location="sendtogrp.php?gid=<?php echo $grp; ?>&&amount=<?php echo $send_amnt; ?>";
								</script>
							<?php
							}else{
								$mid = $_POST['id'];
								$mnt = $_POST['amount'];
								$phone = $_POST['phne'];
								
								if(!empty($mnt)){
									
									 $amount = (int)$mnt;
									 
									 if($amount > $bal){
									?>
										<script>
											alert("Error! Your account balance is insufficient to send <?php echo "Ksh. ".$amount; ?>. Your account balance is <?php echo "Ksh. ".$bal; ?>. Please topup your account.");
											window.location="sendtogrp.php?gid=<?php echo $grp; ?>&&amount=<?php echo $send_amnt; ?>";
										</script>
									<?php
								
									}else{
										// send airtime to the selected contact 
										$username = $get_credentials['username'];
										$password = $get_credentials['password'];
							
										// send airtime		
										$parameters = "username=$username&password=$password&recipient=$phone&amount=$amount";
										$url = "http://www.mobisky.biz/api/sendairtime.php?$parameters";
										//fopen("$url","r"); 
		
										$ch = curl_init();
										// set URL and other appropriate options
										curl_setopt($ch, CURLOPT_URL, "$url");
										curl_setopt($ch, CURLOPT_HEADER, 0);
										// Pass it to the browser
											curl_exec($ch);
											
											if(curl_error($ch)) {
												echo 'error:' . curl_error($ch);
										    }

										// close cURL resource, and free up system resources
										curl_close($ch);	
							 
									  //insert data 
									$qry =	mysql_query("insert into airtime_sending_records values('','$session_id','$amount','$phone',Now(),'1') ");
									
									// update account balance
							//			$availbal = ((int)$bal) -  $amount;
							//		$query = mysql_query("update airtime_user_credits set current_amount='$availbal', last_updated=Now() where customer_id='$session_id'");
									
									$qry2 = mysql_query("select * from airtime_logs where id='$session_lid' ");
										$sdata=mysql_fetch_array($qry2);
										$actions=$sdata['user_actions'];
									$query = mysql_query("update airtime_logs set user_actions='$actions Sent Airtime to phone no. $phone Ksh. $amount.' where id='$session_lid'  ");
						
									if($query){
										?>
											<script>
												alert("Airtime Successfully sent.");
												window.location="sendtogrp.php?gid=<?php echo $grp; ?>&&amount=<?php echo $send_amnt; ?>&&cid=<?php echo $mid; ?>";
											</script>
										<?php
									}else{
										?>
											<script>
												alert("Error sending airtime. Please try again.");
												window.location="sendtogrp.php?gid=<?php echo $grp; ?>&&amount=<?php echo $send_amnt; ?>";
											</script>
										<?php
									}
										
										
									}
								}else{
									// amount field empty
										?>
								<script>
									alert("Error! Amount field cannot be empty. Please try again.");
										window.location="sendtogrp.php?gid=<?php echo $grp; ?>&&amount=<?php echo $send_amnt; ?>";
								</script>
							<?php
								}
							
							
							} 
						  
					  }
					  ?>
					  
					<?php	  
					  }
					   ?>
					  
					 <br/>
					  <form data-parsley-validate class="form-horizontal form-label-left" method="post" action="">
						<!-- Search Button -->
						<input type="hidden"  id="grop" name="grop" value="<?php echo  $grp; ?>"/>
						<input type="hidden" id="pay" name="pay" value="<?php echo $amnt; ?>"/>
						<input type="hidden" id="grupid" name="grupid" value="<?php echo $gid; ?>"/>
						<div class="form-group">
							<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
								<button  class="btn btn-primary" name="cancel" > Cancel </button> 
								<input type="submit"  class="btn btn-success" name="send_airtime" value="Send Airtime to All Members"/>
							</div>
						</div>
					</form>
			</div>	
			<?php 
				
			?>
				
					<div class="form-group">
                        <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
							<a href="sendtogroup.php"> <button  class="btn btn-primary" > Select Group</button>  </a>
						</div>
                    </div>
					
					<?php 
					if(isset($_POST['send_airtime'])) {
						
						    $grp = $_POST['grop'];
						    $gid = $_POST['grupid'];
						    $amnt = $_POST['pay'];
							
							$bal=$usrcr['amount'];
						if($bal==0){
						// no credit
							?>
								<script>
									alert("Error! Your account balance is insufficient. Please topup your account.");
									window.location="sendtogrp.php?gid=<?php echo  $gid; ?>&&amount=<?php echo $amnt; ?>";
								</script>
							<?php
						}else{
							      $amount = (int)$amnt;
									$s = mysql_query("select * from airtime_groups where customer_id = '$session_id' and name = '$grp' ");
									$rslt = mysql_fetch_array($s);
									$gidx = $rslt['group_id'];
					 
									$c = mysql_query("select * from airtime_contacts where customer_id = '$session_id' and group_id = '$gidx' ");
									$nums = mysql_num_rows($c);
									
									$total_amount =  $amount * $nums;
									
									if($total_amount > $bal){
										?>
											<script>
											alert("Error! Your account balance is insufficient to send <?php echo "Ksh. ".$total_amount; ?>. Your account balance is <?php echo "Ksh. ".$bal; ?>. Please topup your account.");
											window.location="sendtogrp.php?gid=<?php echo $gid; ?>&&amount=<?php echo $amnt; ?>";
										</script>
									<?php
									}else{
											$username = $get_credentials['username'];
											$password = $get_credentials['password'];
											$send_amnt = $_POST['pay'];
											
											$ch = curl_init();
										while($row=mysql_fetch_array($c)){
											// send airtime to all members in this group
											$phone = $row['contact'];
							
											// send airtime		
											$parameters = "username=$username&password=$password&recipient=$phone&amount=$amount";
											$url = "http://www.mobisky.biz/api/sendairtime.php?$parameters";
											//fopen("$url","r"); 
	
											// set URL and other appropriate options
											curl_setopt($ch, CURLOPT_URL, "$url");
											curl_setopt($ch, CURLOPT_HEADER, 0);
											// Pass it to the browser
											curl_exec($ch);	
											
											if(curl_error($ch)) {
												echo 'error:' . curl_error($ch);
										    }
											//insert data 
											$qry =	mysql_query("insert into airtime_sending_records values('','$session_id','$amount','$phone',Now(),'1') ");
											
											$qry2 = mysql_query("select * from airtime_logs where id='$session_lid' ");
											$sdata=mysql_fetch_array($qry2);
											$actions=$sdata['user_actions'];
											mysql_query("update airtime_logs set user_actions='$actions Sent Airtime to phone no. $phone Ksh. $amount.' where id='$session_lid'  ");
										}
										
											if(curl_error($ch)) {
												  ?>
														<script>
															alert("Error sending airtime. Please try again.");
															window.location="sendtogrp.php?gid=<?php echo $gid; ?>&&amount=<?php echo $amnt; ?>";
														</script>
													<?php
											}else{
												 ?>
													 <script>
														alert("Success. Airtime sent to <?php echo $nums; ?> recipients.");
														window.location="sendtogroup.php";
													 </script>
												 <?php
											}
										
										// close cURL resource, and free up system resources
											curl_close($ch);
											
										  //update user credit
										/*		$availbal = ((int)$bal) -  $total_amount;
												$query = mysql_query("update airtime_user_credits set current_amount='$availbal', last_updated=Now() where customer_id='$session_id'");
												if($query){
												 ?>
													 <script>
														alert("Success. Airtime sent to <?php echo $nums; ?> recipients.");
														window.location="sendtogroup.php";
													 </script>
												 <?php
												}else{
												   ?>
														<script>
															alert("Error sending airtime. Please try again.");
															window.location="sendtogrp.php?gid=<?php echo $gid; ?>&&amount=<?php echo $amnt; ?>";
														</script>
													<?php
												}  */
										
										
									}
								   
								} 
								
								
							}
							
					?>
		  
		  </div>
		  
		  
		  
		  
		  </div>
		  
		  
		          <!-- /page content. End of main -->

     <?php include("footerlinks.php"); ?>
	 
 <script src="vendors/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="vendors/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- FastClick -->
    <script src="vendors/fastclick/lib/fastclick.js"></script>
    <!-- NProgress -->
    <script src="vendors/nprogress/nprogress.js"></script>
    <!-- Chart.js -->
    <script src="vendors/Chart.js/dist/Chart.min.js"></script>
    <!-- gauge.js -->
    <script src="vendors/bernii/gauge.js/dist/gauge.min.js"></script>
    <!-- bootstrap-progressbar -->
    <script src="vendors/bootstrap-progressbar/bootstrap-progressbar.min.js"></script>
    <!-- iCheck -->
    <script src="vendors/iCheck/icheck.min.js"></script>
    <!-- Skycons -->
    <script src="vendors/skycons/skycons.js"></script>
    <!-- Flot -->
    <script src="vendors/Flot/jquery.flot.js"></script>
    <script src="vendors/Flot/jquery.flot.pie.js"></script>
    <script src="vendors/Flot/jquery.flot.time.js"></script>
    <script src="vendors/Flot/jquery.flot.stack.js"></script>
    <script src="vendors/Flot/jquery.flot.resize.js"></script>
    <!-- Flot plugins -->
    <script src="js/flot/jquery.flot.orderBars.js"></script>
    <script src="js/flot/date.js"></script>
    <script src="js/flot/jquery.flot.spline.js"></script>
    <script src="js/flot/curvedLines.js"></script>
    <!-- jVectorMap -->
    <script src="js/maps/jquery-jvectormap-2.0.3.min.js"></script>
    <!-- bootstrap-daterangepicker -->
    <script src="js/moment/moment.min.js"></script>
    <script src="js/datepicker/daterangepicker.js"></script>
	
	<script src="vendors/datatables.net/js/jquery.dataTables.min.js"></script>
    <script src="vendors/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
    <script src="vendors/datatables.net-buttons/js/dataTables.buttons.min.js"></script>
    <script src="vendors/datatables.net-buttons-bs/js/buttons.bootstrap.min.js"></script>
    <script src="vendors/datatables.net-buttons/js/buttons.flash.min.js"></script>
    <script src="vendors/datatables.net-buttons/js/buttons.html5.min.js"></script>
    <script src="vendors/datatables.net-buttons/js/buttons.print.min.js"></script>
    <script src="vendors/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js"></script>
    <script src="vendors/datatables.net-keytable/js/dataTables.keyTable.min.js"></script>
    <script src="vendors/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
    <script src="vendors/datatables.net-responsive-bs/js/responsive.bootstrap.js"></script>
    <script src="vendors/datatables.net-scroller/js/datatables.scroller.min.js"></script>
    <script src="vendors/jszip/dist/jszip.min.js"></script>
    <script src="vendors/pdfmake/build/pdfmake.min.js"></script>
    <script src="vendors/pdfmake/build/vfs_fonts.js"></script>
	
	    <script src="vendors/select2/dist/js/select2.full.min.js"></script>

  

    <!-- Datatables -->
	 <script>
      $(document).ready(function() {
        var handleDataTableButtons = function() {
          if ($("#datatable-buttons").length) {
            $("#datatable-buttons").DataTable({
              dom: "Bfrtip",
              buttons: [
                {
                  extend: "copy",
                  className: "btn-sm"
                },
                {
                  extend: "csv",
                  className: "btn-sm"
                },
                {
                  extend: "excel",
                  className: "btn-sm"
                },
                {
                  extend: "pdfHtml5",
                  className: "btn-sm"
                },
                {
                  extend: "print",
                  className: "btn-sm"
                },
              ],
              responsive: true
            });
          }
        };

        TableManageButtons = function() {
          "use strict";
          return {
            init: function() {
              handleDataTableButtons();
            }
          };
        }();

        $('#datatable').dataTable();
        $('#datatable-keytable').DataTable({
          keys: true
        });

        $('#datatable-responsive').DataTable();

        $('#datatable-scroller').DataTable({
          ajax: "js/datatables/json/scroller-demo.json",
          deferRender: true,
          scrollY: 380,
          scrollCollapse: true,
          scroller: true
        });

        var table = $('#datatable-fixed-header').DataTable({
          fixedHeader: true
        });

        TableManageButtons.init();
      });
    </script>	
	
    <!-- Select2 -->
    <script>
      $(document).ready(function() {
        $(".select2_single").select2({
          placeholder: "Select a state",
          allowClear: true
        });
        $(".select2_group").select2({});
        $(".select2_multiple").select2({
       placeholder: "Chose Contacts to topup",
          allowClear: true
        });
      });
    </script>
    <!-- /Select2 -->	
		  
   
	
		  
		  