<?php 
	include_once('../config.php');   
	include_once(ABS_PATH.'/custom_function/default.php'); 
    if(!isset($_SESSION['userId']))
    { 
         header("Location: ../");
         die;
    }
       
       
       
       
                        
                      
                           
                         
          /*
                      
                    $_POST['cuurentId'] = "AP640920";
					$MrefId= $dmt->id;
					$stmt=$conn->prepare("select * from  UI__PoolPlan where custId =:custId ");   
					$stmt->bindValue(':custId',  $_POST['cuurentId'] , PDO::PARAM_STR);  
					$stmt->execute();  
					 
					     
				$Result = $stmt->fetch(PDO::FETCH_OBJ);  
			    $stmt=$conn->prepare("select  refId from  UI__Rgst where  cuurentId=:refId ");   
				$stmt->bindValue(':refId', $Result->refId, PDO::PARAM_INT);  
				$stmt->execute();  
				  
				// level 1.....
                $Result = $stmt->fetch(PDO::FETCH_OBJ);  
                
                echo '<pre>'; print_r($Result);
                die;
                $stmt=$conn->prepare("select  refId from  UI__Rgst where  cuurentId=:refId ");   
                $stmt->bindValue(':refId', $Result->refId, PDO::PARAM_INT);  
                $stmt->execute();  
                if($stmt->rowCount() > 0) 
                {    
                    
                                                   
                        $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level) ");   
						$stmt->bindValue(':Rid', $Result->refId , PDO::PARAM_STR); 
						$stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
						$stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
						$stmt->bindValue(':Tamt', 100 , PDO::PARAM_STR);   
						$stmt->bindValue(':BAmt', 10000 , PDO::PARAM_STR);      
						$stmt->bindValue(':level', 1  , PDO::PARAM_STR);  
					 	$stmt->execute();   
						
						$level1 = $Result->refId; 
						if($Result->refId!='DP112233') 
						{
							LvBal_new($Result->refId,100,1,"PoolLevel Balance",$_POST['cuurentId']);  
							unset($_SESSION['LastIntId']);
						}
						  
                }  
					      
				        
						// level 2 
                        $stmt=$conn->prepare("select  refId from  UI__Rgst where  cuurentId=:refId ");   
                        $stmt->bindValue(':refId', $level1 , PDO::PARAM_INT);  
                        $stmt->execute();  
                        if($stmt->rowCount() > 0) 
                        {        
                            $Result = $stmt->fetch(PDO::FETCH_OBJ); 
                            $stmt=$conn->prepare("select  id from   UI__PoolPlan where  idRef=:idRef ");   
                            $stmt->bindValue(':idRef', $Result->refId , PDO::PARAM_INT);  
                            $stmt->execute();  
                            if($stmt->rowCount() > 1) 
                            {   
                                   
                                    $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level) ");   
    								$stmt->bindValue(':Rid', $Result->refId , PDO::PARAM_STR); 
    								$stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
    								$stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
    								$stmt->bindValue(':Tamt', 80 , PDO::PARAM_STR);   
    								$stmt->bindValue(':BAmt', 10000 , PDO::PARAM_STR);      
    								$stmt->bindValue(':level', 2  , PDO::PARAM_STR);  
    								$stmt->execute();   
    								
    								$level2 = $Result->refId; 
    								if($Result->refId!='DP112233') 
    								{
        								LvBal_new($Result->refId,80,1,"PoolLevel Balance",$_POST['cuurentId']);  
        								unset($_SESSION['LastIntId']);
    								} 
    							
    							  
                            }else
                            {     
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level) ");   
                                $stmt->bindValue(':Rid', $Result->refId , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', 0 , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', 10000 , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 2  , PDO::PARAM_STR);  
                                $stmt->execute();   
                                
                                $level2 = $Result->refId; 
                                if($Result->refId!='DP112233') 
                                {
                                LvBal_new($Result->refId,0,1,"Laps PoolLevel Balance",$_POST['cuurentId']);  
                                unset($_SESSION['LastIntId']);
                                } 

                                $stmt=$conn->prepare("select  eml from     UI__Rgst  where  cuurentId=:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $Result->refId , PDO::PARAM_INT);  
                                $stmt->execute(); 
                                $eml = $stmt->fetch(PDO::FETCH_OBJ); 
                                              
                                $subject = "You have laps your level amount on dailypay: ".time("d-M-Y H:i");  
                                $template_type = 1;
                                $attachment = '';  
                                
                                $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;'>Your  Rs 80 laps in pool income due  not adding 2 direct reference in daily pay pool </h5>   
                                </td>
                                </tr>";   
                                SendMail($eml->eml,$subject,$message,$template_type,$attachment);
                            }
                            
                        }  
                        
                        
                        
                        // level 3 
                        $stmt=$conn->prepare("select  refId from  UI__Rgst where  cuurentId=:refId ");   
                        $stmt->bindValue(':refId', $level2 , PDO::PARAM_INT);  
                        $stmt->execute();  
                        if($stmt->rowCount() > 0) 
                        {        
                            $Result = $stmt->fetch(PDO::FETCH_OBJ); 
                            $stmt=$conn->prepare("select  id from   UI__PoolPlan where  idRef=:idRef ");   
                            $stmt->bindValue(':idRef', $Result->refId , PDO::PARAM_INT);  
                            $stmt->execute();  
                            if($stmt->rowCount() > 2) 
                            {   
                                   
                                    $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level) ");   
    								$stmt->bindValue(':Rid', $Result->refId , PDO::PARAM_STR); 
    								$stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
    								$stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
    								$stmt->bindValue(':Tamt', 70 , PDO::PARAM_STR);   
    								$stmt->bindValue(':BAmt', 10000 , PDO::PARAM_STR);      
    								$stmt->bindValue(':level', 3  , PDO::PARAM_STR);  
    								$stmt->execute();   
    								
    								$level3 = $Result->refId; 
    								if($Result->refId!='DP112233') 
    								{
        								LvBal_new($Result->refId,70,1,"PoolLevel Balance",$_POST['cuurentId']);  
        								unset($_SESSION['LastIntId']);
    								} 
    							
    							  
                            }else
                            {     
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level) ");   
                                $stmt->bindValue(':Rid', $Result->refId , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', 0 , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', 10000 , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 3  , PDO::PARAM_STR);  
                                $stmt->execute();   
                                
                                $level3 = $Result->refId; 
                                if($Result->refId!='DP112233') 
                                {
                                LvBal_new($Result->refId,0,1,"Laps PoolLevel Balance",$_POST['cuurentId']);  
                                unset($_SESSION['LastIntId']);
                                } 

                                $stmt=$conn->prepare("select  eml from     UI__Rgst  where  cuurentId=:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $Result->refId , PDO::PARAM_INT);  
                                $stmt->execute(); 
                                $eml = $stmt->fetch(PDO::FETCH_OBJ); 
                                              
                                $subject = "You have laps your level amount on dailypay: ".time("d-M-Y H:i");  
                                $template_type = 1;
                                $attachment = '';  
                                
                                $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;'>Your  Rs 70 laps in pool income due  not adding 2 direct reference in daily pay pool </h5>   
                                </td>
                                </tr>";   
                                SendMail($eml->eml,$subject,$message,$template_type,$attachment);
                            }
                            
                        }
                        
                        
                        // level 4 
                        $stmt=$conn->prepare("select  refId from  UI__Rgst where  cuurentId=:refId ");   
                        $stmt->bindValue(':refId', $level3 , PDO::PARAM_INT);  
                        $stmt->execute();  
                        if($stmt->rowCount() > 0) 
                        {        
                            $Result = $stmt->fetch(PDO::FETCH_OBJ); 
                            $stmt=$conn->prepare("select  id from   UI__PoolPlan where  idRef=:idRef ");   
                            $stmt->bindValue(':idRef', $Result->refId , PDO::PARAM_INT);  
                            $stmt->execute();  
                            if($stmt->rowCount() > 3) 
                            {   
                                   
                                    $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level) ");   
    								$stmt->bindValue(':Rid', $Result->refId , PDO::PARAM_STR); 
    								$stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
    								$stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
    								$stmt->bindValue(':Tamt', 60 , PDO::PARAM_STR);   
    								$stmt->bindValue(':BAmt', 10000 , PDO::PARAM_STR);      
    								$stmt->bindValue(':level', 4  , PDO::PARAM_STR);  
    								$stmt->execute();   
    								
    								$level4 = $Result->refId; 
    								if($Result->refId!='DP112233') 
    								{
        								LvBal_new($Result->refId,60,1,"PoolLevel Balance",$_POST['cuurentId']);  
        								unset($_SESSION['LastIntId']);
    								} 
    							
    							  
                            }else
                            {     
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level) ");   
                                $stmt->bindValue(':Rid', $Result->refId , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', 0 , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', 10000 , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 4  , PDO::PARAM_STR);  
                                $stmt->execute();   
                                
                                $level4 = $Result->refId; 
                                if($Result->refId!='DP112233') 
                                {
                                LvBal_new($Result->refId,0,1,"Laps PoolLevel Balance",$_POST['cuurentId']);  
                                unset($_SESSION['LastIntId']);
                                } 

                                $stmt=$conn->prepare("select  eml from     UI__Rgst  where  cuurentId=:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $Result->refId , PDO::PARAM_INT);  
                                $stmt->execute(); 
                                $eml = $stmt->fetch(PDO::FETCH_OBJ); 
                                              
                                $subject = "You have laps your level amount on dailypay: ".time("d-M-Y H:i");  
                                $template_type = 1;
                                $attachment = '';  
                                
                                $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;'>Your  Rs 60 laps in pool income due  not adding 2 direct reference in daily pay pool </h5>   
                                </td>
                                </tr>";   
                                SendMail($eml->eml,$subject,$message,$template_type,$attachment);
                            }
                            
                        }
                        
                        
                        
                        // level 5 
                        $stmt=$conn->prepare("select  refId from  UI__Rgst where  cuurentId=:refId ");   
                        $stmt->bindValue(':refId', $level4 , PDO::PARAM_INT);  
                        $stmt->execute();  
                        if($stmt->rowCount() > 0) 
                        {        
                            $Result = $stmt->fetch(PDO::FETCH_OBJ); 
                            $stmt=$conn->prepare("select  id from   UI__PoolPlan where  idRef=:idRef ");   
                            $stmt->bindValue(':idRef', $Result->refId , PDO::PARAM_INT);  
                            $stmt->execute();  
                            if($stmt->rowCount() > 4) 
                            {   
                                   
                                    $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level) ");   
    								$stmt->bindValue(':Rid', $Result->refId , PDO::PARAM_STR); 
    								$stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
    								$stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
    								$stmt->bindValue(':Tamt', 50 , PDO::PARAM_STR);   
    								$stmt->bindValue(':BAmt', 10000 , PDO::PARAM_STR);      
    								$stmt->bindValue(':level', 5  , PDO::PARAM_STR);  
    								$stmt->execute();   
    								
    								$level5 = $Result->refId; 
    								if($Result->refId!='DP112233') 
    								{
        								LvBal_new($Result->refId,50,1,"PoolLevel Balance",$_POST['cuurentId']);  
        								unset($_SESSION['LastIntId']);
    								} 
    							
    							  
                            }else
                            {     
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level) ");   
                                $stmt->bindValue(':Rid', $Result->refId , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', 0 , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', 10000 , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 5  , PDO::PARAM_STR);  
                                $stmt->execute();   
                                
                                $level5 = $Result->refId; 
                                if($Result->refId!='DP112233') 
                                {
                                LvBal_new($Result->refId,0,1,"Laps PoolLevel Balance",$_POST['cuurentId']);  
                                unset($_SESSION['LastIntId']);
                                } 

                                $stmt=$conn->prepare("select  eml from     UI__Rgst  where  cuurentId=:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $Result->refId , PDO::PARAM_INT);  
                                $stmt->execute(); 
                                $eml = $stmt->fetch(PDO::FETCH_OBJ); 
                                              
                                $subject = "You have laps your level amount on dailypay: ".time("d-M-Y H:i");  
                                $template_type = 1;
                                $attachment = '';  
                                
                                $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;'>Your  Rs 50 laps in pool income due  not adding 2 direct reference in daily pay pool </h5>   
                                </td>
                                </tr>";   
                                SendMail($eml->eml,$subject,$message,$template_type,$attachment);
                            }
                            
                        }     
                        die;
                        
             */          
				       
                                                          
				        
        /*
           for($i=0;$i<=10;$i++)                    
           {
                $digits = 10;
                $cuurentId = "AP".rand(pow(10, $digits-1), pow(10, $digits)-1);  
                $stmt=$conn->prepare("insert into  UI__PoolPlan (custId,amount,refId) values(:custId,:amount,:refId) ");    
                $stmt->bindValue(':custId', $cuurentId , PDO::PARAM_INT);    
                $stmt->bindValue(':amount', 10000 , PDO::PARAM_INT);    
                $stmt->bindValue(':refId', 'DP457500' , PDO::PARAM_INT);    
                $stmt->execute();     
            } 
                            
         $stmt=$conn->prepare("SELECT  *   FROM UI__PoolPlan  where  id>1111394   ");   
        //$stmt->bindValue(':custId',  'AP8829354506' , PDO::PARAM_INT);  
        $stmt->execute(); 
        $Result = $stmt->fetchAll(PDO::FETCH_OBJ);  
        
       
        
        for($i=0;$i<=11380;$i++)
        {
        $digits = 10;
        $cuurentId = "AP".rand(pow(10, $digits-1), pow(10, $digits)-1);  
        $stmt=$conn->prepare("insert into  UI__PoolPlan (custId) values(:custId) ");    
        $stmt->bindValue(':custId', $cuurentId , PDO::PARAM_INT);    
        $stmt->execute();  
        
        
        } 
        die;
        */
             
             
        $stmt=$conn->prepare("SELECT  *   FROM  UI__PoolCoupon  where   custId=:custId ");   
        $stmt->bindValue(':custId',    $_REQUEST['poolId'] , PDO::PARAM_INT);  
        $stmt->execute(); 
        $myCt = $stmt->rowCount();
        
        
        
        
        
        $stmt=$conn->prepare("SELECT  *   FROM  UI__PoolPlan  where   custId=:custId ");   
        $stmt->bindValue(':custId',  $_REQUEST['poolId'] , PDO::PARAM_INT);  
        $stmt->execute(); 
        $Result = $stmt->fetch(PDO::FETCH_OBJ);   
        $Id = $Result->custId; 

        
        $originalDate = $Result->Tdate;
        $newDate = date("Y-m-d", strtotime($originalDate));   
        $Ndate =  strtotime($newDate);
        
        $stmt=$conn->prepare("SELECT  id   FROM  UI__PoolPlan  ");    
        $stmt->execute(); 
        $Invest = $stmt->rowCount();
        
        
        $stmt=$conn->prepare("SELECT  *   FROM  UI__Tpm   where poolSpoat=1");    
        $stmt->execute(); 
        $UI__Tpm = $stmt->fetchAll(PDO::FETCH_OBJ);   
        
        $poolSpoat = 0;
        foreach($UI__Tpm as $mpp)
            $poolSpoat +=$mpp->Amt;    
        
         
        $stmt=$conn->prepare("SELECT  id   FROM  UI__PoolPlan  where is_active=1 ");    
        $stmt->execute(); 
        $is_active = $stmt->rowCount();
           
           
         
        $stmt=$conn->prepare("SELECT  id   FROM  UI__PoolCoupon   ");    
        $stmt->execute(); 
        $UI__PoolCoupon = $stmt->rowCount();
        $PerfTotal = ($is_active*10000) + ($UI__PoolCoupon*1000);
           
         
                 
include_once("../view/dashboard/viewCoupons.php");
?>