<?php
	include_once('../../config.php');    
	 
	  
	                        
	                   
	                   
	                   
                        $ary = $_POST;
                        $stmt=$conn->prepare("insert into   UI__dashboardPay2all(Tdate,response) values(:Tdate,:response)");  
                        $stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);     
                        $stmt->bindValue(':response',  json_encode($ary) , PDO::PARAM_STR);     
                        $stmt->execute(); 
                        $Job2_ncode2 = json_decode(json_encode($ary));  
                        
                        
                        
                        $stmt=$conn->prepare("insert into   test(name) values(:name)");  
                        $stmt->bindValue(':name', json_encode($ary) , PDO::PARAM_STR);      
                        $stmt->execute(); 
                         
                        
                        // Prepaired Recharge
                        $stmt=$conn->prepare("select client_id   from    UI__Recharges where  client_id=:client_id  ");   
                        $stmt->bindValue(':client_id', $Job2_ncode2->client_id, PDO::PARAM_STR); 
                        $stmt->execute();   
                        
                        if($stmt->rowCount()>0)   
                        {    
                            if( ($Job2_ncode2->status_id==1) || ($Job2_ncode2->status_id==0) )
                            {    
                                $stmt=$conn->prepare("update UI__Recharges set status=1,utr=:UTR  where client_id=:client_id  ");    
                                $stmt->bindValue(':client_id', $Job2_ncode2->client_id, PDO::PARAM_STR);  
                                $stmt->bindValue(':utr', $Job2_ncode2->utr, PDO::PARAM_STR);   
                                $stmt->execute();         
                            }else if( ($Job2_ncode2->status_id==2) || ($Job2_ncode2->status_id==4))
                            {    
                                $stmt =  $conn->prepare("select cust_id,amount  from   UI__Recharges  where  client_id=:client_id ");   
                                $stmt->bindValue(':client_id', $Job2_ncode2->client_id  , PDO::PARAM_STR); 
                                $stmt->execute();  
                                $UI__Recharges = $stmt->fetch(PDO::FETCH_OBJ);     
                                
    
                                $stmt=$conn->prepare("update UI__Recharges set status=0 where client_id=:client_id  ");  
                                $stmt->bindValue(':client_id', $Job2_ncode2->client_id, PDO::PARAM_STR);   
                                $stmt->execute();    
                                AddFundNew($UI__Recharges->cust_id,($UI__Recharges->amount),"Refund");  
                            }
                        }
                        
                        
                        // IMPS**************************** NoramalPay2all
                        $stmt=$conn->prepare("select client_id   from    UI__TxnFailUsers where  client_id=:client_id  ");   
                        $stmt->bindValue(':client_id', $Job2_ncode2->client_id, PDO::PARAM_STR); 
                        $stmt->execute();   
                        
                        if($stmt->rowCount()>0)   
                        {    
                            if( ($Job2_ncode2->status_id==1) || ($Job2_ncode2->status_id==0) )
                            {    
                                $stmt=$conn->prepare("update UI__TxnFailUsers set status=1,paidDateTime=:paidDate,UTR=:UTR  where client_id=:client_id  ");   
                                $stmt->bindValue(':paidDate', date("d-M-Y H:i") , PDO::PARAM_STR);
                                $stmt->bindValue(':client_id', $Job2_ncode2->client_id, PDO::PARAM_STR);  
                                $stmt->bindValue(':UTR', $Job2_ncode2->utr, PDO::PARAM_STR);   
                                $stmt->execute();         
                            }else if( ($Job2_ncode2->status_id==2) || ($Job2_ncode2->status_id==4))
                            {    
                                $stmt =  $conn->prepare("select custId,amt  from   UI__TxnFailUsers  where  client_id=:client_id ");   
                                $stmt->bindValue(':client_id', $Job2_ncode2->client_id  , PDO::PARAM_STR); 
                                $stmt->execute();  
                                $UI__TxnFailUsers = $stmt->fetch(PDO::FETCH_OBJ);     
                                
    
                                $stmt=$conn->prepare("update UI__TxnFailUsers set status=0,paidDateTime=:paidDate  where client_id=:client_id  ");   
                                $stmt->bindValue(':paidDate', date("d-M-Y H:i") , PDO::PARAM_STR);
                                $stmt->bindValue(':client_id', $Job2_ncode2->client_id, PDO::PARAM_STR);   
                                $stmt->execute();    
                                AddFundNew($UI__TxnFailUsers->custId,($UI__TxnFailUsers->amt),"Refund");  
                            }
                        }
                        
                        // IMPS****************************  GrapPay
                        $stmt=$conn->prepare("select client_id   from    UI__TxnFailUsersPay2 where  client_id=:client_id  ");   
                        $stmt->bindValue(':client_id', $Job2_ncode2->client_id, PDO::PARAM_STR); 
                        $stmt->execute();   
                        
                        if($stmt->rowCount()>0)   
                        {    
                            if( ($Job2_ncode2->status_id==1) || ($Job2_ncode2->status_id==0) )
                            {    
                                $stmt=$conn->prepare("update UI__TxnFailUsersPay2 set status=1,paidDateTime=:paidDate,UTR=:UTR  where client_id=:client_id  ");   
                                $stmt->bindValue(':paidDate', date("d-M-Y H:i") , PDO::PARAM_STR);
                                $stmt->bindValue(':client_id', $Job2_ncode2->client_id, PDO::PARAM_STR);  
                                $stmt->bindValue(':UTR', $Job2_ncode2->utr, PDO::PARAM_STR);   
                                $stmt->execute();         
                            }else if( ($Job2_ncode2->status_id==2) || ($Job2_ncode2->status_id==4))
                            {    
                                $stmt =  $conn->prepare("select custId,amt  from   UI__TxnFailUsersPay2  where  client_id=:client_id ");   
                                $stmt->bindValue(':client_id', $Job2_ncode2->client_id  , PDO::PARAM_STR); 
                                $stmt->execute();  
                                $UI__TxnFailUsers = $stmt->fetch(PDO::FETCH_OBJ);     
                                
    
                                $stmt=$conn->prepare("update UI__TxnFailUsersPay2 set status=0,paidDateTime=:paidDate  where client_id=:client_id  ");   
                                $stmt->bindValue(':paidDate', date("d-M-Y H:i") , PDO::PARAM_STR);
                                $stmt->bindValue(':client_id', $Job2_ncode2->client_id, PDO::PARAM_STR);   
                                $stmt->execute();    
                                AddFundNew($UI__TxnFailUsers->custId,($UI__TxnFailUsers->amt),"Refund");  
                            }
                        }
                        
                        
                        // Collection******************
                        
                        
                        

                        $stmt=$conn->prepare("select client_id   from    UI__CollQrWlt where  client_id=:client_id  ");   
                        $stmt->bindValue(':client_id', $Job2_ncode2->client_id, PDO::PARAM_STR); 
                        $stmt->execute();   
                        
                        if($stmt->rowCount()>0)   
                        { 
                            
                                $stmt =  $conn->prepare("select * from   UI__CollQrWlt  where  client_id=:client_id and status=0  ");   
                                $stmt->bindValue(':client_id', $Job2_ncode2->client_id  , PDO::PARAM_STR); 
                                $stmt->execute();  
        
                            
                                if($stmt->rowCount()>0)   
                                { 
                                    $UI__TxnFailUsersPay2 = $stmt->fetch(PDO::FETCH_OBJ);     
                                    if($Job2_ncode2->utr!='')
                                    {    
                                         
                                        AddFundNew($UI__TxnFailUsersPay2->custId,$Job2_ncode2->amount,"Qr Collection");    
                                        $stmt=$conn->prepare("update UI__CollQrWlt set status=1,paidDate=:paidDate  where client_id=:client_id  ");   
                                        $stmt->bindValue(':paidDate', date("d-M-Y H:i") , PDO::PARAM_STR);
                                        $stmt->bindValue(':client_id', $Job2_ncode2->client_id, PDO::PARAM_STR);  
                                        $stmt->execute();   
                                        
                                        
                                       /* $stmt=$conn->prepare("insert into  UI__ConirmQr (custId,Tdate,Amt,client_id,paidDate,status,RecordedDate,upi_string,utr,sender_vpa,sender_name,report_id,balance) values(:custId,:Tdate,:Amt,:client_id,:paidDate,:status,:RecordedDate,:upi_string,:utr,:sender_vpa,:sender_name,:report_id,:balance)   ");   
                                        $stmt->bindValue(':custId', $UI__TxnFailUsersPay2->custId , PDO::PARAM_STR);
                                        $stmt->bindValue(':Tdate', date("d-M-Y"), PDO::PARAM_STR);  
                                        $stmt->bindValue(':Amt',  $UI__TxnFailUsersPay2->Amt, PDO::PARAM_STR);  
                                        $stmt->bindValue(':client_id', $UI__TxnFailUsersPay2->client_id, PDO::PARAM_STR);  
                                        $stmt->bindValue(':paidDate', date("d-M-Y H:i"), PDO::PARAM_STR);  
                                        $stmt->bindValue(':status',1, PDO::PARAM_STR);  
                                        $stmt->bindValue(':RecordedDate', date("d-M-Y H:i"), PDO::PARAM_STR); 
                                        $stmt->bindValue(':upi_string', $UI__TxnFailUsersPay2->upi_string, PDO::PARAM_STR); 
                                        $stmt->bindValue(':utr', $Job2_ncode2->utr, PDO::PARAM_STR);
                                        $stmt->bindValue(':sender_vpa', $Job2_ncode2->sender_vpa, PDO::PARAM_STR);
                                        $stmt->bindValue(':sender_name', $Job2_ncode2->sender_name, PDO::PARAM_STR);
                                        $stmt->bindValue(':report_id', $Job2_ncode2->report_id, PDO::PARAM_STR);  
                                        $stmt->bindValue(':balance', ($Awltwallet-$cllTp) + ($UI__TxnFailUsersPay2->Amt), PDO::PARAM_STR);  
                                        $stmt->execute(); */
                                        
                                    }
                                }
                            
                             
                            /*
                                $stmt =  $conn->prepare("select * from   UI__CollQrWlt  where  client_id=:client_id and status=0  ");   
                                $stmt->bindValue(':client_id', $Job2_ncode2->client_id  , PDO::PARAM_STR); 
                                $stmt->execute();  
        
                            
                                if($stmt->rowCount()>0)   
                                { 
                                    $UI__TxnFailUsersPay2 = $stmt->fetch(PDO::FETCH_OBJ);     
                                    if($Job2_ncode2->utr!='')
                                    {
                                         
                                        
                                        $stmt=$conn->prepare("select * from  UI__ConirmQr   where custId=:custId  and trasnferStatus=0 and tranfredDate='' ");    
                                        $stmt->bindValue(':custId',  $UI__TxnFailUsersPay2->custId , PDO::PARAM_STR);
                                        $stmt->execute(); 
                                        $PAYWAllet = $stmt->fetchAll(PDO::FETCH_OBJ); 
                                        
                                         
                                        
                                        $Awltwallet = 0;
                                        foreach($PAYWAllet as $rmt)
                                            $Awltwallet += $rmt->Amt; 
                                            
                                      
                                    
                                        $stmt=$conn->prepare("select * from  UI__CollTopup   where custId=:custId   and Tdate=:Tdate ");   
                                        $stmt->bindValue(':custId',  $UI__TxnFailUsersPay2->custId , PDO::PARAM_STR);
                                        $stmt->bindValue(':Tdate',  date("d-M-Y"), PDO::PARAM_STR); 
                                        $stmt->execute(); 
                                        $UI__CollTopup = $stmt->fetchAll(PDO::FETCH_OBJ); 
                                    	
                                    	 $cllTp = 0;    
                                    	 if($stmt->rowCount() > 0)
                                    	 {
                                    	    foreach($UI__CollTopup as $mp)
                                    	        $cllTp +=$mp->Amt; 
                                    	 }
                                    	 
                                        // ********************
                                        
                                        $stmt=$conn->prepare("update UI__CollQrWlt set status=1,paidDate=:paidDate  where client_id=:client_id  ");   
                                        $stmt->bindValue(':paidDate', date("d-M-Y H:i") , PDO::PARAM_STR);
                                        $stmt->bindValue(':client_id', $Job2_ncode2->client_id, PDO::PARAM_STR);  
                                        $stmt->execute();       
                                       
                                        
                                        $stmt=$conn->prepare("insert into  UI__ConirmQr (custId,Tdate,Amt,client_id,paidDate,status,RecordedDate,upi_string,utr,sender_vpa,sender_name,report_id,balance) values(:custId,:Tdate,:Amt,:client_id,:paidDate,:status,:RecordedDate,:upi_string,:utr,:sender_vpa,:sender_name,:report_id,:balance)   ");   
                                        $stmt->bindValue(':custId', $UI__TxnFailUsersPay2->custId , PDO::PARAM_STR);
                                        $stmt->bindValue(':Tdate', date("d-M-Y"), PDO::PARAM_STR);  
                                        $stmt->bindValue(':Amt',  $UI__TxnFailUsersPay2->Amt, PDO::PARAM_STR);  
                                        $stmt->bindValue(':client_id', $UI__TxnFailUsersPay2->client_id, PDO::PARAM_STR);  
                                        $stmt->bindValue(':paidDate', date("d-M-Y H:i"), PDO::PARAM_STR);  
                                        $stmt->bindValue(':status',1, PDO::PARAM_STR);  
                                        $stmt->bindValue(':RecordedDate', date("d-M-Y H:i"), PDO::PARAM_STR); 
                                        $stmt->bindValue(':upi_string', $UI__TxnFailUsersPay2->upi_string, PDO::PARAM_STR); 
                                        $stmt->bindValue(':utr', $Job2_ncode2->utr, PDO::PARAM_STR);
                                        $stmt->bindValue(':sender_vpa', $Job2_ncode2->sender_vpa, PDO::PARAM_STR);
                                        $stmt->bindValue(':sender_name', $Job2_ncode2->sender_name, PDO::PARAM_STR);
                                        $stmt->bindValue(':report_id', $Job2_ncode2->report_id, PDO::PARAM_STR);  
                                        $stmt->bindValue(':balance', ($Awltwallet-$cllTp) + ($UI__TxnFailUsersPay2->Amt), PDO::PARAM_STR);  
                                        $stmt->execute(); 
                                        
                                    } 
                                }  
                                */
                                
                                
                        
                        }