<?php
	include_once('../config.php');   
    include_once(ABS_PATH.'/custom_function/default.php');  
          
    	
    if(!isset($_SESSION['userId']))
    { 
         header("Location: ../");
         die;
    }   
    
    
			    
                
        $rew = 0;
        $stmt=$conn->prepare("select *  from UI__Reward    where cuurentId=:cuurentId and Tdate=:Tdate  ");   
        $stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_STR);  
        $stmt->bindValue(':Tdate',  date("d-M-Y"), PDO::PARAM_STR);  
        $stmt->execute(); 
        if($stmt->rowCount()<1)   
		{    
                    
                    $rew = 1;
                    $stmt=$conn->prepare("select rewardPoints  from UI__Rgst  where  cuurentId=:cuurentId   ");   
                    $stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_STR);   
                    $stmt->execute();  
                    $UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ); 
                    $reward =  $UI__Rgst->rewardPoints; 
                     
                    $stmt=$conn->prepare("select  amt,availableFund from  UI__Fundtransfer   where userid=:cuurentId order by id desc");  
                    $stmt->bindValue(':cuurentId', $_SESSION['userId'] , PDO::PARAM_STR);
                    $stmt->execute();  
                    
                    if($stmt->rowCount() > 0)
                    {
                       $AllUsers = $stmt->fetch(PDO::FETCH_OBJ); 
                       $totalAvaib = $AllUsers->availableFund+$UI__Rgst->rewardPoints;  
                    }else
                        $totalAvaib =  $UI__Rgst->rewardPoints; 
                          
                     
        			$stmt=$conn->prepare("insert into  UI__Fundtransfer (userid,Tdate,amt,availableFund) values(:userid,:Tdate,:amt,:availableFund)    "); 
                    $stmt->bindValue(':userid', $_SESSION['userId'], PDO::PARAM_STR); 
                    $stmt->bindValue(':Tdate',date("d-M-Y H:i"), PDO::PARAM_STR); 
                    $stmt->bindValue(':amt',$UI__Rgst->rewardPoints, PDO::PARAM_STR);  
                    $stmt->bindValue(':availableFund', $totalAvaib , PDO::PARAM_STR);  
                    $stmt->execute(); 
                    
                    
                    $stmt=$conn->prepare("insert into    UI__Reward (cuurentId,Tdate,reward) values(:cuurentId,:Tdate,:reward)  ");   
                    $stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_STR);  
                    $stmt->bindValue(':Tdate',  date("d-M-Y"), PDO::PARAM_STR);  
                    $stmt->bindValue(':reward',   $UI__Rgst->rewardPoints , PDO::PARAM_STR);  
                    $stmt->execute(); 
                    LvBal($_SESSION['userId'],$UI__Rgst->rewardPoints,1,"Daily Rewards",$_SESSION['userId']);
                    $stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
                    $stmt->bindValue(':cuurentId',  $_SESSION['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',   14 , PDO::PARAM_STR);   
                    $stmt->bindValue(':bank',  "Wallet" , PDO::PARAM_STR);   
                    $stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
                    $stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
                    $stmt->bindValue(':amountPaid', $UI__Rgst->rewardPoints   , 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', $_SESSION['userId']  , PDO::PARAM_STR);  
                    $stmt->bindValue(':cdId', $_SESSION['LastIntId']  , PDO::PARAM_STR); 
                    $stmt->bindValue(':Topay',   $_SESSION['userId'] , PDO::PARAM_STR); 
                    $stmt->bindValue(':TopayName',   $_SESSION['userId']  , PDO::PARAM_STR);     
                    $stmt->execute();   
                    unset($_SESSION['LastIntId']); 
                    
		}
        
        $stmt=$conn->prepare("select rewardPoints  from UI__Rgst  where  cuurentId=:cuurentId   ");   
        $stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_STR);   
        $stmt->execute();  
        $UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ); 
        $reward =  $UI__Rgst->rewardPoints; 
        
        
include_once("../view/dashboard/rewardCliam.php");
?>