<?php 	include_once('../../config.php');   	
		include_once(ABS_PATH.'/admin/login_check.php');    
		
		
		
		
		                        if(isset($_REQUEST['cuurentId']))
		                        {
		                            $_POST['userid'] = $_REQUEST['cuurentId'];
		                            $_POST['amount'] = $_REQUEST['amount'];
		                        }
		  
		            function SendMail($EMAIL,$subject,$message,$template_type,$attachment) 
		            {
		            
		            }
 
			if(isset($_POST['submitF']))
			{   
			           
							$stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
							$stmt->bindValue(':cuurentId',  $_POST['userid'] , PDO::PARAM_STR);  
							$stmt->execute();
							$UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);   
							$gname = $UI__Rgst->nm; 
							$directxfer = $UI__Rgst->directxfer;
							
							$stmt=$conn->prepare("select *  from UI__AddAccount    where id =:sId   ");   
							$stmt->bindValue(':sId',  $_POST['AccountList'] , PDO::PARAM_INT);  
							$stmt->execute(); 
							$UI__AddAccount = $stmt->fetch(PDO::FETCH_OBJ);    
							
							
							$_POST['AccountList'] = $_POST['AccountList']; 
							$_POST['rname_'] = $UI__AddAccount->accName;
							$_POST['accountNo'] = $UI__AddAccount->accno;
							$_POST['ifsc'] = $UI__AddAccount->ifsc; 
							$_POST['amount'] = $_POST['AMMT']; 
							$pay2All2 = $UI__Rgst->pay2second;   
				
						 
							
								$mobile  = $UI__Rgst->phm;
								$_POST['mobile'] = $mobile;
								$beneficiary_name =  $_POST['rname_'];
								$beneficiary_accountno = $_POST['accountNo'];
								$beneficiary_ifsc =  $_POST['ifsc'];
								$user_id  = rand(2223,23232);
								$status = 1;
								$payee_txn_id = mt_rand(29902,23894);
								$orderid = "NA";
								$report_id = "NA";
								$last_update = date("Y-m-d H:i");
								$client_id = rand(2223,23232);
								$utr = "XXXX"; 
								
					 
								$grapPay = 0;
								if(($UI__Rgst->pay2second==1)) 
									$grapPay = 2;
									
								$stmt =  $conn->prepare("insert into moneytransfer (amount,mobile,beneficiary_name,beneficiary_accountno,beneficiary_ifsc,user_id,cust_id,status,payee_txn_id,user_type,url,orderid,report_id,last_update,client_id,utr,bankTrnfer,pay2All2,grapPay) values(:amount,:mobile,:beneficiary_name,:beneficiary_accountno,:beneficiary_ifsc,:user_id,:cust_id,:status,:payee_txn_id,:user_type,:url,:orderid,:report_id,:last_update,:client_id,:utr,1,:pay2All2,:grapPay)");            
								$stmt->bindValue(':amount', $_POST['amount'], PDO::PARAM_STR);
								$stmt->bindValue(':mobile', $mobile, PDO::PARAM_STR);
								$stmt->bindValue(':beneficiary_name', $beneficiary_name, PDO::PARAM_STR);
								$stmt->bindValue(':beneficiary_accountno', $beneficiary_accountno, PDO::PARAM_STR);
								$stmt->bindValue(':beneficiary_ifsc', $beneficiary_ifsc, PDO::PARAM_STR);
								$stmt->bindValue(':user_id', $user_id, PDO::PARAM_STR);
								$stmt->bindValue(':cust_id', $_POST['userid'], PDO::PARAM_STR);
								$stmt->bindValue(':status', $status, PDO::PARAM_INT);
								$stmt->bindValue(':payee_txn_id', $payee_txn_id, PDO::PARAM_STR);
								$stmt->bindValue(':user_type', 0, PDO::PARAM_INT);
								$stmt->bindValue(':url', "NA", PDO::PARAM_STR);
								$stmt->bindValue(':orderid', $orderid, PDO::PARAM_STR);
								$stmt->bindValue(':report_id', $report_id, PDO::PARAM_STR);
								$stmt->bindValue(':last_update', $last_update, PDO::PARAM_STR);
								$stmt->bindValue(':client_id', $client_id, PDO::PARAM_STR);
								$stmt->bindValue(':utr', $utr, PDO::PARAM_STR);   
								$stmt->bindValue(':pay2All2', $pay2All2, PDO::PARAM_STR); 
								$stmt->bindValue(':grapPay', $grapPay, PDO::PARAM_STR);  
								$stmt->execute();
								
							 
									
								$stmt =  $conn->prepare("delete from recevier_users where senderCustom_id=:senderCustom_id and receiver_ph=:receiver_ph "); 
								$stmt->bindValue(':senderCustom_id',  $_POST['userid'] , PDO::PARAM_STR);
								$stmt->bindValue(':receiver_ph', $_POST['mobile'], PDO::PARAM_STR);      
								$stmt->execute();  
								 
								$stmt =  $conn->prepare("insert into recevier_users (amount,receiver_name,senderCustom_id,receiver_ph,account,ifsc,register_date) values(:amount,:receiver_name,:senderCustom_id,:receiver_ph,:txt_accountno,:txt_ifsc,:register_date)");
								$stmt->bindValue(':amount', $_POST['amount'], PDO::PARAM_STR);     
								$stmt->bindValue(':receiver_name', $_POST['rname_'], PDO::PARAM_STR);       
								$stmt->bindValue(':senderCustom_id', $_POST['userid'] , PDO::PARAM_STR);
								$stmt->bindValue(':receiver_ph', $_POST['mobile'], PDO::PARAM_STR);     
								$stmt->bindValue(':txt_accountno', $_POST['accountNo'], PDO::PARAM_STR);     
								$stmt->bindValue(':txt_ifsc', $_POST['ifsc'], PDO::PARAM_STR);     
								$stmt->bindValue(':register_date', date("d-M-Y"), PDO::PARAM_STR);       
								$stmt->execute();   
								
								////     
									
								$stmt=$conn->prepare("select eml from UI__Rgst  where  cuurentId=:cuurentId    ");   
								$stmt->bindValue(':cuurentId',  $_POST['userid']  , PDO::PARAM_STR);  
								$stmt->execute(); 
								$EMAIL = $stmt->fetch(PDO::FETCH_OBJ);    
								
								if($deduction>0)
								{
								$stmt=$conn->prepare("insert into UI__WithDraw(userid,Tdate,amt,orgAmt,order_id,bank_remark,status,accept) values(:userid,:Tdate,:amt,:orgAmt,:order_id,:bank_remark,:status,:accept)"); 
								$stmt->bindValue(':userid',  $_POST['userid']  , PDO::PARAM_STR);   
								$stmt->bindValue(':Tdate',  date("d-M-Y H:i") , PDO::PARAM_STR);   
								$stmt->bindValue(':amt',$deduction , PDO::PARAM_STR);
								$stmt->bindValue(':orgAmt', $deduction , PDO::PARAM_STR); 
								$stmt->bindValue(':order_id',  $payee_txn_id , PDO::PARAM_STR); 
								$stmt->bindValue(':bank_remark', "PA", PDO::PARAM_STR); 
								$stmt->bindValue(':status', $status , PDO::PARAM_STR); 
								$stmt->bindValue(':accept', 1 , PDO::PARAM_STR);      
								$stmt->execute();          
								LvBal($_POST['userid'],$deduction,2,"IMPS Tranfered",$_POST['userid']);   
								
								$stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
								$stmt->bindValue(':cuurentId',  $_POST['userid'] , PDO::PARAM_STR);  
								$stmt->execute();
								$UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);  
								
								
								$stmt=$conn->prepare("insert into UI__Receipt(type,bank,mobile,email,amountPaid,Tid,status,Tdate,custId,cdId,Topay,TopayName) values(:type,:bank,:mobile,:email,:amountPaid,:Tid,:status,:Tdate,:custId,:cdId,:Topay,:TopayName)"); 
								$stmt->bindValue(':type',   7 , PDO::PARAM_STR);   
								$stmt->bindValue(':bank',  "IMPS Tranfered" , PDO::PARAM_STR);   
								$stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
								$stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
								$stmt->bindValue(':amountPaid', $deduction  , PDO::PARAM_STR); 
								$stmt->bindValue(':Tid', mt_rand(1234552,23555), PDO::PARAM_STR); 
								$stmt->bindValue(':status', 1 , PDO::PARAM_STR); 
								$stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);      
								$stmt->bindValue(':custId', $_POST['userid']  , PDO::PARAM_STR);  
								$stmt->bindValue(':cdId', $_SESSION['LastIntId']  , PDO::PARAM_STR); 
								$stmt->bindValue(':Topay',  $beneficiary_accountno , PDO::PARAM_STR); 
								$stmt->bindValue(':TopayName',  $beneficiary_accountno  , PDO::PARAM_STR);     
								$stmt->execute();   
							
			
								}
								
								
							
								$stmt=$conn->prepare("insert into UI__WithDraw(userid,Tdate,amt,orgAmt,order_id,bank_remark,status,accept) values(:userid,:Tdate,:amt,:orgAmt,:order_id,:bank_remark,:status,:accept)"); 
								$stmt->bindValue(':userid',   $_POST['userid']  , PDO::PARAM_STR);   
								$stmt->bindValue(':Tdate',  date("d-M-Y H:i") , PDO::PARAM_STR);   
								$stmt->bindValue(':amt', ($_POST['amount']-$deduction) , PDO::PARAM_STR);
								$stmt->bindValue(':orgAmt', ($_POST['amount']-$deduction) , PDO::PARAM_STR); 
								$stmt->bindValue(':order_id',  $payee_txn_id , PDO::PARAM_STR); 
								$stmt->bindValue(':bank_remark', "PA", PDO::PARAM_STR); 
								$stmt->bindValue(':status', $status , PDO::PARAM_STR); 
								$stmt->bindValue(':accept', 1 , PDO::PARAM_STR);      
								$stmt->execute();          
								LvBal($_POST['userid'],($_POST['amount']-$deduction),2,"Money Tranfered",$_POST['userid']);    
								
								
								$stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
								$stmt->bindValue(':cuurentId',  $_POST['userid'] , PDO::PARAM_STR);  
								$stmt->execute();
								$UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);  
							 
								$stmt=$conn->prepare("insert into UI__Receipt(type,bank,mobile,email,amountPaid,Tid,status,Tdate,custId,cdId,Topay,TopayName) values(:type,:bank,:mobile,:email,:amountPaid,:Tid,:status,:Tdate,:custId,:cdId,:Topay,:TopayName)"); 
								$stmt->bindValue(':type',   7 , PDO::PARAM_STR);   
								$stmt->bindValue(':bank',  "IMPS Tranfered" , PDO::PARAM_STR);   
								$stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
								$stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
								$stmt->bindValue(':amountPaid', ($_POST['amount']-$deduction)   , PDO::PARAM_STR); 
								$stmt->bindValue(':Tid', mt_rand(1234552,23555), PDO::PARAM_STR); 
								$stmt->bindValue(':status', 1 , PDO::PARAM_STR); 
								$stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);      
								$stmt->bindValue(':custId', $_POST['userid']  , PDO::PARAM_STR);  
								$stmt->bindValue(':cdId', $_SESSION['LastIntId']  , PDO::PARAM_STR); 
								$stmt->bindValue(':Topay',  $beneficiary_accountno , PDO::PARAM_STR); 
								$stmt->bindValue(':TopayName',  $beneficiary_accountno  , PDO::PARAM_STR);     
								$stmt->execute(); 
								

								 
								$_SESSION['topSuc'] = 1; 
								$ary['Sccuecc']  = 1;
								$ary['message']  =  "Transaction successful";
								 
									
								$subject = "IMPS BY ".$_POST['userid']." On ".date("H:i");  
								$template_type = 1;
								$attachment = '';
								$name = $beneficiary_name;
								$Amt = $_POST['amount'];
								
								$message="
								<tr>
								<td align='left' valign='top'>
								<h4 style='font-weight:bold; padding:2px 2px; margin:3px; text-align:left; color:#002368;'>Dear user,</h4>
								<h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'>Thanks for Money Transfer with us. Your Details are as follows </h5> 
								<h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'> To: $name , Amount Rs : $Amt </h5>
								
								</td>
								</tr>"; 
								
								SendMail($EMAIL->eml,$subject,$message,$template_type,$attachment); 
								
								
								
								$status = 0;
								$subject = "IMPS BY ".$_POST['userid'];  
								$template_type = 1;
								$attachment = '';
								$name = $beneficiary_name;
								$Amt = $_POST['amount'];
								
								$message="
								<tr>
								<td align='left' valign='top'>
								<h4 style='font-weight:bold; padding:2px 2px; margin:3px; text-align:left; color:#002368;'>Dear user,</h4>
								<h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'>Thanks for Money Transfer with us. Your Details are as follows </h5> 
								<h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'> To: $name , Amount Rs : $Amt </h5>
								
								</td>
								</tr>"; 
								
								SendMail("dailypay2024@gmail.com",$subject,$message,$template_type,$attachment); 
								
								
								$mob = $UI__Rgst->phm; 
								$iD = $_POST['userid'];
								$msg = urlencode('Dear '.$iD.' your withdrawal amount of Rs. '.$Amt.' has been CREDITED by Bank Transfer to '.$beneficiary_name.', DAILYPAY.'); 
								$URL  = 'http://mobicomm.dove-sms.com//submitsms.jsp?user=DailyPAY&key=d92eabc025XX&mobile=+91'.$mob.'&message='.$msg.'&senderid=DAYPAY&accusage=1&entityid=1201169824017740929&tempid=1207169900458310637';
								
								
								$crl = curl_init();
								curl_setopt($crl, CURLOPT_URL, $URL);
								curl_setopt($crl, CURLOPT_FRESH_CONNECT, true);
								curl_setopt($crl, CURLOPT_RETURNTRANSFER, true); 
								$response = curl_exec($crl);
								
								$stmt =  $conn->prepare("insert into UI__Tlimits (custId,Tdate,amt,type) values(:custId,:Tdate,:amt,2)  ");   
								$stmt->bindValue(':custId', $_POST['userid'], PDO::PARAM_STR);
								$stmt->bindValue(':Tdate', date("d-M-Y"), PDO::PARAM_STR);
								$stmt->bindValue(':amt', $_POST['amount'], PDO::PARAM_STR);
								$stmt->execute();  
								 
								  
								$stmt=$conn->prepare("select *  from UI__PayUAutoManual   ");  
								$stmt->execute();     
								$RstUxd1Auto = $stmt->fetch(PDO::FETCH_OBJ);       
											
								$Remail =  "dailypay2024@gmail.com";
								$Rd =  "gp6ZiH";  
								$access_token = '{"email":"'.$Remail.'","password":"'.$Rd.'"}';  
								
								
								 
								 
								$ch = curl_init();
								curl_setopt($ch, CURLOPT_URL,'https://erp.pay2all.in/api/user');
								curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
								$headers = array();
								$headers[] = "Accept: application/json";
								$headers[] = "Authorization: Bearer ".$erpToken;
								$headers[] = "Content-Type: application/json";
								curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
								$result = curl_exec($ch); 
								 
						 
								$Data = json_decode($result);    
								$Pay2alllBal =  (int)str_replace(",","",$Data->data->balance->user_balance);      
							    
								include_once("autoTxn-2.php");  
								
								$PAYWAllet =  GetBalance($_POST['userid']);  
								$stmt=$conn->prepare("select id from UI__Rgst  where  cuurentId=:cuurentId    ");   
								$stmt->bindValue(':cuurentId',   $_POST['userid'] , PDO::PARAM_STR);  
								$stmt->execute(); 
								$UIid = $stmt->fetch(PDO::FETCH_OBJ);   
								
								$amount = password_hash(($PAYWAllet),PASSWORD_DEFAULT);  
								$stmt =  $conn->prepare("update _pkCc__ set bl1=:bl1,tm=:tm where Uxd=:Uxd "); 
								$stmt->bindValue(':bl1', $amount, PDO::PARAM_STR); 
								$stmt->bindValue(':tm', date("d-M-Y H:i"), PDO::PARAM_STR); 
								$stmt->bindValue(':Uxd', $UIid->id, PDO::PARAM_STR);  
								$stmt->execute();   

								
								$stmt=$conn->prepare("update    UI__LastBal set  LastBal=:LastBal  where  custId=:custId");   
								$stmt->bindValue(':LastBal',  ($UI__LastBal->LastBal-$_POST['amount']) , PDO::PARAM_STR);  
								$stmt->bindValue(':custId',  $_POST['userid'] , PDO::PARAM_STR);  
								$stmt->execute();   
								
								$stmt=$conn->prepare("select id from moneytransfer  order by id desc  ");     
								$stmt->execute(); 
								$LastId = $stmt->fetch(PDO::FETCH_OBJ);   
								
								 
								$stmt=$conn->prepare("update   moneytransfer    set  DebitCredit_id=:DebitCredit_id  where  id=:id");   
								$stmt->bindValue(':DebitCredit_id', $_SESSION['LastIntId'] , PDO::PARAM_STR);   
								$stmt->bindValue(':id',  $LastId->id , PDO::PARAM_STR);   
								$stmt->execute(); 
								
								if($status==1)
									$ary['reVal'] =  $_SESSION['LastIntId']."_";  
								else
									$ary['reVal'] =  $_SESSION['LastIntId'];   
									
								$_SESSION['MyStatus'] = $status; 
						  header("Location: AutoAccountList.php");
						  die;    
		}  
include ABS_PATH.'/admin/header.php';	
?>


 <script>
	$(function() {
		$( "#datepicker" ).datepicker(); 
	}); 
  
	$(document).ready(function()
	{   

	
	$("#product_frm").validate({
		
		errorElement:'div',
		rules:{ 
			userid:{
				required:true				 
			} 
			
			
			
		},
		messages:{				
			 
			 city:{
				required:"Enter city name"				 
			} 
		}
	});


	});
 


</script>



<script> 
$(document).ready(function()
{   
  
	
	    var URL = "<?php echo ROOTPATH; ?>";    
        $( "#userid" ).change(function() 
        {      
                   
                     
          $.ajax({	
                type: "POST",
                url: URL+"/ajax/validation.php",
                data: {userDatacheck:1,Data:$("#userid").val()},
                beforeSend: function(){ 
                },
                success: function(data)
                    {        
                        $("#AvailbleId").html("<span style='color:green;'>"+data+" &#x2713</span>");
                    }
                });   
        });
 
 
}); 

function SelecAcc(val)
        {
                    $.ajax({	
                   type: "POST",
                    url: "https://www.dailypayservices.in/mob/ajax/validation.php",
                    data: {SelectACcount:1,AccId:val},
                    beforeSend: function(){ 
                    },
                    success: function(data)
                        {       
                            var Mydata = jQuery.parseJSON(data); 
                            
                            
                            
                            if(Mydata.apprvd==0)
                            {
                             $("#AccountAdd").html("Account approval is pending");   
                            }else{
                            $("#rname_").val(Mydata.accName);   
                            $("#accountNo").val(Mydata.accno);   
                            $("#ifsc").val(Mydata.ifsc);   
                            $("#AccountAdd").html(""); 
                            }
                        }
                    });  
        }

</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> Money  Transfered : <?php if(isset($_SESSION['MyStatus'])) {
								
								        if($_SESSION['MyStatus']!=0)
								            echo "Amount Procced";
								        else
								            echo "Its Failed";
								}
								    ?>
								</h3></div>    
								
                                <div align="right"> 
                                    <input type="button"    class="btn btn-warning" name="btnback" id="btnback" value="REFRESH" onClick="javascript:location.href='WithaddAccount.php';" />
                                </div>
								 
							</div>
							
							
			  				<div class="panel-body">    
			  					<form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" id="product_frm"> 
							   	 <div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">Userid</label>
								    <div class="col-sm-6">
								      <input name="userid"  id="userid" class="form-control"   placeholder="Enter UserId"  value="<?php echo $_POST['userid'];?>"   required >
								      <span id="AvailbleId"></span>
								    </div>
								 </div>
								 <hr> 
								 
								 <?php 
								    if(isset($_POST['userid']))
								    {
								 ?>
								  <div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">Select Account</label>
								    <div class="col-sm-6"> 
                                            <select class="form-control"  name="AccountList" id="AccountList" onchange="SelecAcc(this.value)" required>
                                            <option value="">Select Account</option>
                                            <?php 
                                            
                                            $stmt=$conn->prepare("select * from UI__AddAccount  where  custId=:cuurentId  ");   
                                            $stmt->bindValue(':cuurentId',  $_POST['userid'] , PDO::PARAM_STR);  
                                            $stmt->execute();
                                            $UI__AddAccount = $stmt->fetchAll(PDO::FETCH_OBJ);   
                                            foreach($UI__AddAccount as $data) 
                                            {  
                                            ?>
                                            <option value="<?php echo $data->id;?>"><?php echo $data->accName;?></option>
                                            <?php } ?>
                                            </select>   
								    </div>
								 </div>
                                 <hr>  
                                <div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">Receiver Acc No</label>
								    <div class="col-sm-6">
								        <input type="number"  class="form-control"     name="accountNo"  id="accountNo"  required  readonly/>
								    </div>
								 </div>
								 <hr> 
								
								<div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">Receiver IFSC</label>
								    <div class="col-sm-6">
								        <input type="text"  class="form-control"    name="ifsc"  id="ifsc"  required  readonly /> 
								    </div>
								 </div>
								 <hr> 
								 <?php } ?>
								 
								 
								  <?php 
								    if(!isset($_POST['userid']))
								    {
								 ?>
	 								 
								  <div class="form-group">
										<label for="inputEmail3" class="col-sm-2 control-label">CONTINUE</label>
										<div class="col-sm-10">
										  <input type="submit"    class="btn btn-primary"  name="Continue" value="CONTINUE">
										</div>
								  </div>  
								  
								  <?php }else {  ?>  
								  
								 <div class="form-group">
								    <label for="inputEmail3" class="col-sm-2 control-label">Amount </label>
								    <div class="col-sm-6">
								        <input type="number"  class="form-control"    name="AMMT"  id="AMMT" value="<?php echo $_POST['amount'];?>" required  /> 
								    </div>
								 </div>
								 <hr> 
								  
								  
								  <div class="form-group">
										<label for="inputEmail3" class="col-sm-2 control-label">Withdawls</label>
										<div class="col-sm-10">
										  <input type="submit"    class="btn btn-primary"  name="submitF" value="Withdawls">
										</div>
								  </div>  
								  
								
								  <?php }  ?>
								  
								</form>  
			  				</div>
			  			</div>
	  				</div> 
	  			</div>  


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

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