<?php 	include_once('../../config.php'); 
        include_once(ABS_PATH.'/admin/login_check.php');    
		 
          
			if(isset($_POST['Cpin']))
			{    
			    $RandNo = rand(pow(10, 6-1), pow(10, 6)-1);      
			    for($i=0;$i<$_POST['TotalPins'];$i++)
			    {    
         		    $digits = 6;
                    $Amt = rand(pow(10, $digits-1), pow(10, $digits)-1);    
                    $Mpim = "CAT".$Amt;//+3400; 
                    $amount = password_hash($Amt,PASSWORD_DEFAULT);    
        		    $stmt=$conn->prepare("insert into  UI__PnMX (Vld,AMMT,createdOn,MPin,PhNo) values(:Vld,:AMMT,:createdOn,:MPin,:PhNo) ");   
                    $stmt->bindValue(':Vld', $amount , PDO::PARAM_STR);
                    $stmt->bindValue(':AMMT', $_POST['PlanPn'] , PDO::PARAM_STR);
                    $stmt->bindValue(':createdOn', date("d-M-Y H:i:s") , PDO::PARAM_STR); 
                    $stmt->bindValue(':MPin', $Mpim , PDO::PARAM_STR);    
                    $stmt->bindValue(':PhNo', $RandNo , PDO::PARAM_STR);     
                    $stmt->execute();        
			    }
			    header("Location: ".ROOTPATH."/admin/wallet/subwallet.php");   
			    die;
			}   
		 
?>  
<?php  include ABS_PATH.'/admin/header.php';	?>  


 <script>
 
var URL  = '<?php echo ROOTPATH;?>';  
	$(function() {
		$( "#datepicker" ).datepicker(); 
	}); 
  
  
   
	$(document).ready(function()
	{   

	
	$("#product_frm").validate({
		
		errorElement:'div',
		rules:{ 
			 
			TotalPins:{
				required:true,
				maxlength:3,
				mainlength:1
			}   
			
		},
		messages:{				
			  
		}
	});


	});
 
function Verify()
{
    
    $.ajax({	
    type: "POST",
    url: URL+"/admin/ajax/default.php",
    data: {Verify:1,phoneNo:$("#PhNo").val()},	
    beforeSend: function(){ 
    
    },
    success: function(val)
        {      
           var dm = jQuery.parseJSON(val); 
           if(dm['found']==1) 
                $("#Verydata").html(dm['name']+",<BR> "+dm['cust_id']);
           else
                $("#Verydata").html("Please check phone no");
            
        }
    });  
}


function CreMeNewPinFun()
{
 
    
    $.ajax({	
    type: "POST",
    url: URL+"/admin/ajax/default.php",
    data: {CrtPn:1,phoneNo:$("#PhNo").val(),PlanPn:$("#PlanPn").val()},	
    beforeSend: function(){ 
    
    },
    success: function(val)
        {       
           
           $("#NewCretedPid").val(val);
           $("#CreMeNewPin").hide(); 
        }
    });  
    
}

</script>
 
		 <div class="col-md-10">

	  			<div class="row">
	  				<div class="col-md-12">
	  					<div class="content-box-large">
							<div class="panel-heading">
								<div class="panel-title"> <h3> Create Pin </h3> <span style="color:green;"> </span></div>    
								
							 	
								<div align="right"> 
								    <a  class="btn btn-warning"  href="subwallet.php" > Go Back </a>
					            </div>  
					
							  
								 
							</div>
							
							
			  				<div class="panel-body">    
			  					<form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" id="product_frm" autocomplete="off"> 
								
							 
								  
								 	 
							   <div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">Packages</label>
								    <div class="col-sm-3">
								       <select class="form-control" name="PlanPn" id="PlanPn">
								           <option value="1">100</option>
								           <option value="2">500</option>
								           <option value="3">1000</option>
								           <option value="4">5000</option>
								           <option value="5">10000</option>
								       </select>
								    </div>
								 </div>
								 <hr>
								    
							
								 
								  <div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">  Enter No of Pins</label>
								    <div class="col-sm-3">
								      <input name="TotalPins" id="TotalPins" class="form-control"   type="number"  placeholder="Total Pins"   >
								    </div>
								 </div>
								 <hr> 
							
							 
								  <div class="form-group" id="CreMeNewPin">
										<label for="inputEmail3" class="col-sm-2 control-label">Create Pin</label>
										<div class="col-sm-10">
										  <input type="submit"    class="btn btn-primary"  name="Cpin"  value="Crete New Pin">
										</div>
								  </div>   
								</form>
								
								
							
			  				</div>
			  			</div>
	  				</div>
	  				 
	  			</div>

	  			 


	  		<!--  Page content -->
		  </div>
		</div>
    </div>

<?php  include ABS_PATH.'/admin/footer.php'; unset($_SESSION['WltMsg']);	?>    