<?php
	include_once('../config.php');    
	include_once(ABS_PATH.'/custom_function/default.php');  
	       
 
            $set = 0;
            if(date("H:i")=="00:30")
            $set = 1;     
 							
           function sendMl($eml,$amount)
           {
                $subject = "Level income generated on ".$SITE_NAME;  
                $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 daily income generated. Details are as follows </h5> 
                <h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'>Amount: $amount   </h5>
                
                </td>
                </tr>";   
                SendMail($Str->eml,$subject,$message,$template_type,$attachment);  
               
           }
                
  
	          if(($_REQUEST['Ffnvwvbv']=='NEUIEUBNDDOUIOEIONKLV6897634fnfvBVKV34') && ($set==1)) 
	           { 
                    $stmt=$conn->prepare("select  cuurentId from  UI__Rgst  order by id");   
                    $stmt->execute(); 
                    $Repoints = $stmt->fetchAll(PDO::FETCH_OBJ); 
                    $sr = 1;
                    foreach($Repoints as $usersFetch)
                    { 
                        $stmt=$conn->prepare("update  UI__Rgst set  rewardPoints=:rewardPoints   where cuurentId=:cuurentId  and sp100=0 ");  
                        $stmt->bindValue(':cuurentId', $usersFetch->cuurentId , PDO::PARAM_STR);
                        $stmt->bindValue(':rewardPoints', $random_number = mt_rand(1, 10) , PDO::PARAM_STR);
                        $stmt->execute();  
                    }
			        
								       
                    $stmt=$conn->prepare("select  *   from  UI__DChstr where typ=1  and Rid!='DP112233' and specialUser=0 ");   
                    $stmt->execute();  
                    $UI__DailyROIGeneCt = $stmt->fetchAll(PDO::FETCH_OBJ);  
                    //echo '<pre>'; print_r($UI__DailyROIGeneCt); die; 
                    
                    
                    foreach($UI__DailyROIGeneCt as $dmt)
                    {      
						
						$stmt=$conn->prepare("select   is_active,id  from  UI__Rgst where  cuurentId=:cuurentId   ");
						$stmt->bindValue(':cuurentId', $dmt->Rid , PDO::PARAM_STR);   								
						$stmt->execute();  
						$is_active = $stmt->fetch(PDO::FETCH_OBJ); 
						$MyctId = $is_active->id; 
							
                        //if($is_active->is_active==1)
						{
								$stmt=$conn->prepare(" select phm  from  UI__Rgst where  cuurentId=:cuurentId   ");
								$stmt->bindValue(':cuurentId', $dmt->Rid , PDO::PARAM_STR);   								
								$stmt->execute();  
								$phm = $stmt->fetch(PDO::FETCH_OBJ);     

                                    
                                $abb[] = $dmt->Rid;  
                                if(in_array($dmt->Rid,$abb ) )
                                {
                                 
                                    ///
                                    
                                }else
                                {
                                    
    								$cuurentId =  $dmt->Rid;
    								$mob = $phm->phm;
    								$msg = urlencode('Dear '.$cuurentId.', your payout has been credited in DP account. DailyPay team.'); 
    								$URL  = 'http://mobicomm.dove-sms.com//submitsms.jsp?user=DailyPAY&key=d92eabc025XX&mobile=+91'.$mob.'&message='.$msg.'&senderid=DAYPAY&accusage=1&entityid=1201169824017740929&tempid=1207169883670529224';
    								 
    
    								$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);
                                }
                                
                                $originalDate = $dmt->Tdate;
                                $OldD = date("d-m-Y", strtotime($originalDate)); 
                                //$OldD = date("d-m-Y", strtotime($originalDate. ' -1 day')); 
                                
                                $newDate = date("d-m-Y");
                                $date1 = new DateTime($OldD);
                                $date2 = new DateTime($newDate);
                                $interval = $date1->diff($date2);
                                
                                             
                                  
                                if($interval->d <=$dmt->dys)
                                {     	
										$Tdt = date("d-M-Y", strtotime($dmt->Tdate));   
                                        $amount = ($dmt->amt*2)/$dmt->dys;   
                                        $amount = number_format((float)$amount, 2, '.', '');
                                        
                                        $stmt=$conn->prepare("select   id  from  UI__Rgst where  cuurentId=:cuurentId   ");
                                        $stmt->bindValue(':cuurentId', $dmt->Rid , PDO::PARAM_STR);   								
                                        $stmt->execute();  
                                        $is_activeXX = $stmt->fetch(PDO::FETCH_OBJ); 

                                        if($is_activeXX->id < 877 )
										{ 
                                        
                                        $stmt=$conn->prepare("insert into UI__DailyROIGene(custId,amount,Tdate,TopUpdate) values(:custId,:amount,:Tdate,:TopUpdate)"); 
                                        $stmt->bindValue(':custId', $dmt->Rid , PDO::PARAM_INT);   
                                        $stmt->bindValue(':amount', $amount , PDO::PARAM_INT);    
                                        $stmt->bindValue(':Tdate',  date("d-M-Y") , PDO::PARAM_STR);   
                                        $stmt->bindValue(':TopUpdate',  $Tdt , PDO::PARAM_STR);      
                                        $stmt->execute();  
                                        
                                        $stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
                                        $stmt->bindValue(':cuurentId', $dmt->Rid, PDO::PARAM_STR);  
                                        $stmt->execute();  
                                        $Str = $stmt->fetch(PDO::FETCH_OBJ); 
                                        
                                        /// 
                                                            				
                    					$stmt=$conn->prepare("select *  from UI__DailyROIGene    where custId=:sId     ");   
                    					$stmt->bindValue(':sId', $dmt->Rid , PDO::PARAM_INT);  
                    					$stmt->execute(); 
                    					$XUI__DailyROIGene = $stmt->fetchAll(PDO::FETCH_OBJ);  
                    					
                    					$Tamnt = 0;
                    					foreach($XUI__DailyROIGene as $xx)
                    					{
                    						$Tamnt +=$xx->amount;
                    					}      
                    					
                    					
                    					 $stmt=$conn->prepare("select *  from UI__Bns    where Rid =:sId   ");   
                    						$stmt->bindValue(':sId',  $dmt->Rid , PDO::PARAM_INT);  
                    						$stmt->execute(); 
                    						$UI__Bns = $stmt->fetchAll(PDO::FETCH_OBJ); 
                    						
                    						 $LevelI = 0;
                    						 foreach($UI__Bns as $dddm)
                    						 {
                    							 $LevelI +=$dddm->Tamt;
                    						 }
                    						 
                    				 
                    							$stmt=$conn->prepare("select Amt   from UI__Tpm where TopUpId=:refId   ");   
                    							$stmt->bindValue(':refId',  $dmt->Rid , PDO::PARAM_INT);  
                    							$stmt->execute(); 
                    							$MdirectB = $stmt->fetchAll(PDO::FETCH_OBJ);  
                    							
                    							$directIncome = 0;
                    							foreach($MdirectB as $dmm)
                    								$directIncome += $dmm->Amt;                
                    						
                    						
                    					
                    					
                    					$stmt=$conn->prepare("select *  from UI__WithDraw    where userid=:sId and (accept=1 ||accept=2)  ");   
                    					$stmt->bindValue(':sId',  $dmt->Rid, PDO::PARAM_INT);  
                    					$stmt->execute(); 
                    					$UI__WithDraw = $stmt->fetchAll(PDO::FETCH_OBJ); 
                    					
                    					
                    					$totalWithdrwa = 0;
                    					foreach($UI__WithDraw as $tl)
                    					{
                    					$totalWithdrwa +=$tl->amt;
                    					}
                    					
                    					
                    					
                    					
                    					$stmt=$conn->prepare("select availableFund from UI__Fundtransfer  where  userid=:userid  order by id desc  ");   
                    					$stmt->bindValue(':userid',  $dmt->Rid , PDO::PARAM_INT);  
                    					$stmt->execute(); 
                    					$UI__Fundtransfer = $stmt->fetch(PDO::FETCH_OBJ); 
                    					
                    					 
                        						
                        				$stmt=$conn->prepare("select nm  from UI__Rgst    where cuurentId=:cuurentId     ");   
                        				$stmt->bindValue(':cuurentId',  $dmt->Rid , PDO::PARAM_INT);  
                        				$stmt->execute(); 
                        				$UI__nm = $stmt->fetch(PDO::FETCH_OBJ);     
                        				$BY = $UI__nm->nm;
                        				
                        				$PAYWAllet =  ($Tamnt+$LevelI+$directIncome+$UI__Fundtransfer->availableFund)-($totalWithdrwa);        
                        				 
                    				
                                        $stmt=$conn->prepare("insert into  UI__DebitCredit (custId,addDel,availableBal,Tdate,type,Intype) values(:custId,:addDel,:availableBal,:Tdate,:type,'Daily Balance')    "); 
                                        $stmt->bindValue(':custId',$dmt->Rid, PDO::PARAM_STR); 
                                        $stmt->bindValue(':addDel',$amount, PDO::PARAM_STR); 
                                        $stmt->bindValue(':availableBal',($PAYWAllet), PDO::PARAM_STR);  
                                        $stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);  
                                        $stmt->bindValue(':type', 1 , PDO::PARAM_STR);  
                                        $stmt->execute();
                                        $_SESSION['LastIntId'] = $conn->lastInsertId();;
                                        
                                                
                            			$subject = "Daily income generated on ".$SITE_NAME;  
                            			$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 daily income generated. Details are as follows </h5> 
                            			<h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'>Amount: $amount   </h5>
                            
                            			</td>
                            			</tr>";   
                            			SendMail($Str->eml,$subject,$message,$template_type,$attachment);     
                            			
                                        
                                        $stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
                                        $stmt->bindValue(':cuurentId',  $dmt->Rid , PDO::PARAM_STR);  
                                        $stmt->execute();
                                        $UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);   
                                        unset($_SESSION['LastIntId']);
                                        }else
										{ 	
											if( (date("D")!="Sat") && (date("D")!="Sun"))
											{  			
													
													$stmt=$conn->prepare("insert into UI__DailyROIGene(custId,amount,Tdate,TopUpdate) values(:custId,:amount,:Tdate,:TopUpdate)"); 
													$stmt->bindValue(':custId', $dmt->Rid , PDO::PARAM_INT);   
													$stmt->bindValue(':amount', $amount , PDO::PARAM_INT);    
													$stmt->bindValue(':Tdate',  date("d-M-Y") , PDO::PARAM_STR);   
													$stmt->bindValue(':TopUpdate',  $Tdt , PDO::PARAM_STR);      
													$stmt->execute();  
													
													$stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
													$stmt->bindValue(':cuurentId', $dmt->Rid, PDO::PARAM_STR);  
													$stmt->execute();  
													$Str = $stmt->fetch(PDO::FETCH_OBJ); 
													
													/// 
																						
													$stmt=$conn->prepare("select *  from UI__DailyROIGene    where custId=:sId     ");   
													$stmt->bindValue(':sId', $dmt->Rid , PDO::PARAM_INT);  
													$stmt->execute(); 
													$XUI__DailyROIGene = $stmt->fetchAll(PDO::FETCH_OBJ);  
													
													$Tamnt = 0;
													foreach($XUI__DailyROIGene as $xx)
													{
														$Tamnt +=$xx->amount;
													}      
													
													
													 $stmt=$conn->prepare("select *  from UI__Bns    where Rid =:sId   ");   
														$stmt->bindValue(':sId',  $dmt->Rid , PDO::PARAM_INT);  
														$stmt->execute(); 
														$UI__Bns = $stmt->fetchAll(PDO::FETCH_OBJ); 
														
														 $LevelI = 0;
														 foreach($UI__Bns as $dddm)
														 {
															 $LevelI +=$dddm->Tamt;
														 }
														 
												 
															$stmt=$conn->prepare("select Amt   from UI__Tpm where TopUpId=:refId   ");   
															$stmt->bindValue(':refId',  $dmt->Rid , PDO::PARAM_INT);  
															$stmt->execute(); 
															$MdirectB = $stmt->fetchAll(PDO::FETCH_OBJ);  
															
															$directIncome = 0;
															foreach($MdirectB as $dmm)
																$directIncome += $dmm->Amt;                
														
														
													
													
													$stmt=$conn->prepare("select *  from UI__WithDraw    where userid=:sId and (accept=1 ||accept=2)  ");   
													$stmt->bindValue(':sId',  $dmt->Rid, PDO::PARAM_INT);  
													$stmt->execute(); 
													$UI__WithDraw = $stmt->fetchAll(PDO::FETCH_OBJ); 
													
													
													$totalWithdrwa = 0;
													foreach($UI__WithDraw as $tl)
													{
													$totalWithdrwa +=$tl->amt;
													}
													
													
													
													
													$stmt=$conn->prepare("select availableFund from UI__Fundtransfer  where  userid=:userid  order by id desc  ");   
													$stmt->bindValue(':userid',  $dmt->Rid , PDO::PARAM_INT);  
													$stmt->execute(); 
													$UI__Fundtransfer = $stmt->fetch(PDO::FETCH_OBJ); 
													
													 
															
													$stmt=$conn->prepare("select nm  from UI__Rgst    where cuurentId=:cuurentId     ");   
													$stmt->bindValue(':cuurentId',  $dmt->Rid , PDO::PARAM_INT);  
													$stmt->execute(); 
													$UI__nm = $stmt->fetch(PDO::FETCH_OBJ);     
													$BY = $UI__nm->nm;
													
													$PAYWAllet =  ($Tamnt+$LevelI+$directIncome+$UI__Fundtransfer->availableFund)-($totalWithdrwa);        
													 
												
													$stmt=$conn->prepare("insert into  UI__DebitCredit (custId,addDel,availableBal,Tdate,type,Intype) values(:custId,:addDel,:availableBal,:Tdate,:type,'Daily Balance')    "); 
													$stmt->bindValue(':custId',$dmt->Rid, PDO::PARAM_STR); 
													$stmt->bindValue(':addDel',$amount, PDO::PARAM_STR); 
													$stmt->bindValue(':availableBal',($PAYWAllet), PDO::PARAM_STR);  
													$stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);  
													$stmt->bindValue(':type', 1 , PDO::PARAM_STR);  
													$stmt->execute();
													$_SESSION['LastIntId'] = $conn->lastInsertId();;
													
															
													$subject = "Daily income generated on ".$SITE_NAME;  
													$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 daily income generated. Details are as follows </h5> 
													<h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'>Amount: $amount   </h5>
										
													</td>
													</tr>";   
													SendMail($Str->eml,$subject,$message,$template_type,$attachment);     
													
													
													$stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
													$stmt->bindValue(':cuurentId',  $dmt->Rid , PDO::PARAM_STR);  
													$stmt->execute();
													$UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);   
													unset($_SESSION['LastIntId']);	
												
											}
										}     
                                }
                                else
                                {     
                                    $stmt=$conn->prepare("update UI__DChstr set status=1 where id=:id"); 
                                    $stmt->bindValue(':id', $dmt->id , PDO::PARAM_STR);    
                                    $stmt->execute();   
                                }   
                                
                        if($dmt->id > 5256)        
                        {
                            $levelDays = 120;      
                            $leftdays = 118;      
                        }else
                        {
                            $levelDays = 60;      
                            $leftdays = 58; 
                        }
						
						$NewLevel = 0; 		
						
						if($MyctId>932)
						 $NewLevel = 1; 		
                        
                        if($dmt->bnsStatus==0) // level cond staRT
                        {
                
                				$_POST['cuurentId'] = $dmt->Rid;    
                				$MrefId= $dmt->id;
                				$stmt=$conn->prepare("select refId,custId   from UI__Rgst where cuurentId =:cuurentId ");   
                				$stmt->bindValue(':cuurentId',  $_POST['cuurentId'] , PDO::PARAM_INT);  
                				$stmt->execute();  
                                if($stmt->rowCount() > 0)
                                {     
                                    $ard = null;
                                    $ard = [];
                                    $Result = $stmt->fetch(PDO::FETCH_OBJ);   
                                    $CC = $Result->refId;
                                    $MyCust =  $Result->custId;
                                    $ard[] = $CC;
                                    for($i=0;$i<=9;$i++)
                                    {
                                        $stmt=$conn->prepare("select refId from UI__Rgst where cuurentId =:cuurentId ");   
                                        $stmt->bindValue(':cuurentId',$CC, PDO::PARAM_INT);  
                                        $stmt->execute();  
                                        if($stmt->rowCount() > 0)
                                        { 
                                            $Result = $stmt->fetch(PDO::FETCH_OBJ);   
                                            $CC = $Result->refId;
                                            $ard[] = $CC;
                                        }
                                    }  
                                }
				
				
				     
				                
				 $data['Data'] = $dmt->amt;   
				 if(end($ard)==0)
                 {  
                    for($j1=0;$j1<(count($ard)-1);$j1++)
                    {
                      
                        $Ssprcl100 = 1; 
                        if (strpos($ard[$j1], 'SP') !== false)   
                            $Ssprcl100=0;     
                        
                        if( ($j1==0) && ($Ssprcl100==1))
                        {       
                                
								$MYtotalCt=1;
								if($NewLevel==1)
								{
										$stmt=$conn->prepare("select cuurentId from UI__Rgst where refId=:refId  ");   
										$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
										$stmt->execute();  
										$MYtotalCt = $stmt->rowCount();
								}
									
								$CoinVal = ($data['Data']*0.1)/100;    
                                $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1 and status=0 ");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                if( ($stmt->rowCount() > 0) && ($MYtotalCt>0) ) 
                                {     
                                    
                                    $stmt=$conn->prepare("select  cct  from UI__LevlCt where tblId=:tblId and custId=:custId  ");   
                                    $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                    $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                    $stmt->execute(); 
                                    $IeerCt = $stmt->fetch(PDO::FETCH_OBJ); 
                                    if($IeerCt->cct <= $levelDays) 
                                    {    
                                        $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
                                        $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                        $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                        $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                        $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                        $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                        $stmt->bindValue(':level', 1  , PDO::PARAM_STR); 
                                        $stmt->bindValue(':DaysLeft', ($leftdays-$IeerCt->cct) , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                        
                                        $stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
                                        $stmt->bindValue(':cuurentId', $ard[$j1], PDO::PARAM_STR);  
                                        $stmt->execute();  
                                        $Str = $stmt->fetch(PDO::FETCH_OBJ); 
                                        
                                        sendMl($Str->eml,$CoinVal);
                                        
                                        $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                        $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                        $stmt->execute();  
                                        $custId = $stmt->fetch(PDO::FETCH_OBJ); 
                                        
                                        if($ard[$j1]!='DP112233') 
										{
                                            LvBal_new($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                            unset($_SESSION['LastIntId']);
                                        } 
										
                                        $stmt=$conn->prepare("update   UI__LevlCt set cct=cct+1 where tblId=:tblId and custId=:custId  ");   
                                        $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                        $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                        $stmt->execute();  
                                    }else
                                    {
                                        $stmt=$conn->prepare("update   UI__DChstr set  bnsStatus=1  where id=:id ");   
                                        $stmt->bindValue(':id', $MrefId , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                    }
                                    
                                }
                        }
                        else if( ($j1==1) && ($Ssprcl100==1))
                        { 
                            
							$MYtotalCt=2;
							if($NewLevel==1)
							{
									$stmt=$conn->prepare("select cuurentId from UI__Rgst where refId=:refId  ");   
									$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
									$stmt->execute();  
									$MYtotalCt = $stmt->rowCount();
							}
								
							$CoinVal = ($data['Data']*0.05)/100;    
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1  and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if( ($stmt->rowCount() > 0) && ($MYtotalCt>1) ) 
                            {
                                
                                $stmt=$conn->prepare("select  cct  from UI__LevlCt where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                $IeerCt = $stmt->fetch(PDO::FETCH_OBJ); 
                                if($IeerCt->cct <= $levelDays) 
                                {
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 2  , PDO::PARAM_STR);      
                                $stmt->bindValue(':DaysLeft', ($leftdays-$IeerCt->cct) , PDO::PARAM_STR);    
                                $stmt->execute();   
                                
                                
                                $stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $ard[$j1], PDO::PARAM_STR);  
                                $stmt->execute();  
                                $Str = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                sendMl($Str->eml,$CoinVal);
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                               if($ard[$j1]!='DP112233') {
                                            LvBal_new($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                            unset($_SESSION['LastIntId']);
                                        }
                                         
                                                                 
                                $stmt=$conn->prepare("update   UI__LevlCt set cct=cct+1 where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                
                                }else
                                    {
                                        $stmt=$conn->prepare("update   UI__DChstr set  bnsStatus=1  where id=:id ");   
                                        $stmt->bindValue(':id', $MrefId , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                    }
                            }
                             
 					    }else if( ($j1==2) && ($Ssprcl100==1))
                        { 
                            $MYtotalCt=3;
							if($NewLevel==1)
							{
									$stmt=$conn->prepare("select cuurentId from UI__Rgst where refId=:refId  ");   
									$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
									$stmt->execute();  
									$MYtotalCt = $stmt->rowCount();
							}
							
							
							$CoinVal = ($data['Data']*(0.03))/100;   
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1  and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if( ($stmt->rowCount() > 0) && ($MYtotalCt>2) ) 
                            {
                               
                                $stmt=$conn->prepare("select  cct  from UI__LevlCt where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                $IeerCt = $stmt->fetch(PDO::FETCH_OBJ); 
                                if($IeerCt->cct <= $levelDays) 
                                {
                                
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 3  , PDO::PARAM_STR);
                                $stmt->bindValue(':DaysLeft', ($leftdays-$IeerCt->cct) , PDO::PARAM_STR);    
                                $stmt->execute();   
                                
                                
                                $stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $ard[$j1], PDO::PARAM_STR);  
                                $stmt->execute();  
                                $Str = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                sendMl($Str->eml,$CoinVal);
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                                if($ard[$j1]!='DP112233') {
                                            LvBal_new($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                            unset($_SESSION['LastIntId']);
                                        }
                                         
                                                                        
                                $stmt=$conn->prepare("update   UI__LevlCt set cct=cct+1 where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                }else
                                    {
                                        $stmt=$conn->prepare("update   UI__DChstr set  bnsStatus=1  where id=:id ");   
                                        $stmt->bindValue(':id', $MrefId , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                    }
                            }
                             
 					    }else if( ($j1==3) && ($Ssprcl100==1))
                        { 
                            $MYtotalCt=4;
							if($NewLevel==1)
							{
									$stmt=$conn->prepare("select cuurentId from UI__Rgst where refId=:refId  ");   
									$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
									$stmt->execute();  
									$MYtotalCt = $stmt->rowCount();
							}
							
							$CoinVal = ($data['Data']*(0.02))/100;       
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1  and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if( ($stmt->rowCount() > 0) && ($MYtotalCt>3) ) 
                            {
                                
                                $stmt=$conn->prepare("select  cct  from UI__LevlCt where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                $IeerCt = $stmt->fetch(PDO::FETCH_OBJ); 
                                if($IeerCt->cct <= $levelDays) 
                                {
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 4  , PDO::PARAM_STR);   
                                $stmt->bindValue(':DaysLeft', ($leftdays-$IeerCt->cct) , PDO::PARAM_STR);    
                                $stmt->execute();   
                                
                                
                            
                                $stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $ard[$j1], PDO::PARAM_STR);  
                                $stmt->execute();  
                                $Str = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                sendMl($Str->eml,$CoinVal);
                                    
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                                if($ard[$j1]!='DP112233') {
                                            LvBal_new($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                            unset($_SESSION['LastIntId']);
                                        }
                                        
                                        
                                
                                $stmt=$conn->prepare("update   UI__LevlCt set cct=cct+1 where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                }else
                                    {
                                        $stmt=$conn->prepare("update   UI__DChstr set  bnsStatus=1  where id=:id ");   
                                        $stmt->bindValue(':id', $MrefId , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                    }
                            }
                             
 					    }else if( ($j1==4) && ($Ssprcl100==1))
                        { 
                            $MYtotalCt=5;
							if($NewLevel==1)
							{
									$stmt=$conn->prepare("select cuurentId from UI__Rgst where refId=:refId  ");   
									$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
									$stmt->execute();  
									$MYtotalCt = $stmt->rowCount();
							}
							
							$CoinVal = ($data['Data']*(0.01))/100;     
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1 and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if( ($stmt->rowCount() > 0) && ($MYtotalCt>4) ) 
                            {
                                
                                $stmt=$conn->prepare("select  cct  from UI__LevlCt where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                $IeerCt = $stmt->fetch(PDO::FETCH_OBJ); 
                                if($IeerCt->cct <= $levelDays) 
                                {
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 5 , PDO::PARAM_STR);  
                                $stmt->bindValue(':DaysLeft', ($leftdays-$IeerCt->cct) , PDO::PARAM_STR);    
                                $stmt->execute();   
                                
                                
                                $stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $ard[$j1], PDO::PARAM_STR);  
                                $stmt->execute();  
                                $Str = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                sendMl($Str->eml,$CoinVal);
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                               if($ard[$j1]!='DP112233') {
                                            LvBal_new($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                            unset($_SESSION['LastIntId']);
                                        }
                                        
                                         
                                $stmt=$conn->prepare("update   UI__LevlCt set cct=cct+1 where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                }else
                                    {
                                        $stmt=$conn->prepare("update   UI__DChstr set  bnsStatus=1  where id=:id ");   
                                        $stmt->bindValue(':id', $MrefId , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                    }
                            } 
 					      }else if( ($j1==5) && ($Ssprcl100==1))
                        { 
                            $MYtotalCt=6;
							if($NewLevel==1)
							{
									$stmt=$conn->prepare("select cuurentId from UI__Rgst where refId=:refId  ");   
									$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
									$stmt->execute();  
									$MYtotalCt = $stmt->rowCount();
							}
							
							$CoinVal = ($data['Data']*(0.01))/100;     
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1 and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if( ($stmt->rowCount() > 0) && ($MYtotalCt>5) ) 
                            {
                                $stmt=$conn->prepare("select  cct  from UI__LevlCt where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                $IeerCt = $stmt->fetch(PDO::FETCH_OBJ); 
                                if($IeerCt->cct <= $levelDays) 
                                {
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 6 , PDO::PARAM_STR);    
                                $stmt->bindValue(':DaysLeft', ($leftdays-$IeerCt->cct) , PDO::PARAM_STR);    
                                $stmt->execute();   
                                
                            
                                $stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $ard[$j1], PDO::PARAM_STR);  
                                $stmt->execute();  
                                $Str = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                sendMl($Str->eml,$CoinVal);
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                                if($ard[$j1]!='DP112233') {
                                            LvBal_new($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                            unset($_SESSION['LastIntId']);
                                        }
                                        
                                        
                                $stmt=$conn->prepare("update   UI__LevlCt set cct=cct+1 where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                }else
                                    {
                                        $stmt=$conn->prepare("update   UI__DChstr set  bnsStatus=1  where id=:id ");   
                                        $stmt->bindValue(':id', $MrefId , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                    }
                            }
                             
 					      }else if( ($j1==6) && ($Ssprcl100==1))
                        { 
                           
							$MYtotalCt=7;
							if($NewLevel==1)
							{
									$stmt=$conn->prepare("select cuurentId from UI__Rgst where refId=:refId  ");   
									$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
									$stmt->execute();  
									$MYtotalCt = $stmt->rowCount();
							}

							$CoinVal = ($data['Data']*(0.01))/100;     
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1 and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if( ($stmt->rowCount() > 0) && ($MYtotalCt>6) ) 
                            {
                                $stmt=$conn->prepare("select  cct  from UI__LevlCt where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                $IeerCt = $stmt->fetch(PDO::FETCH_OBJ); 
                                if($IeerCt->cct <= $levelDays) 
                                {
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 7 , PDO::PARAM_STR); 
                                $stmt->bindValue(':DaysLeft', ($leftdays-$IeerCt->cct) , PDO::PARAM_STR);    
                                $stmt->execute();   
                                
                            
                                $stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $ard[$j1], PDO::PARAM_STR);  
                                $stmt->execute();  
                                $Str = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                sendMl($Str->eml,$CoinVal);
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                                if($ard[$j1]!='DP112233') {
                                            LvBal_new($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                            unset($_SESSION['LastIntId']);
                                        }
                                        
                                        
                                $stmt=$conn->prepare("update   UI__LevlCt set cct=cct+1 where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                }else
                                    {
                                        $stmt=$conn->prepare("update   UI__DChstr set  bnsStatus=1  where id=:id ");   
                                        $stmt->bindValue(':id', $MrefId , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                    }
                            }
                             
 					      }else if( ($j1==7) && ($Ssprcl100==1))
                        { 
                            
							$MYtotalCt=8;
							if($NewLevel==1)
							{
									$stmt=$conn->prepare("select cuurentId from UI__Rgst where refId=:refId  ");   
									$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
									$stmt->execute();  
									$MYtotalCt = $stmt->rowCount();
							}
							
							$CoinVal = ($data['Data']*(0.01))/100;     
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1 and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if( ($stmt->rowCount() > 0) && ($MYtotalCt>7) ) 
                            {
                                $stmt=$conn->prepare("select  cct  from UI__LevlCt where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                $IeerCt = $stmt->fetch(PDO::FETCH_OBJ); 
                                if($IeerCt->cct <= $levelDays) 
                                {
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 8 , PDO::PARAM_STR);
                                $stmt->bindValue(':DaysLeft', ($leftdays-$IeerCt->cct) , PDO::PARAM_STR);    
                                $stmt->execute();   
                                
                                
                                $stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $ard[$j1], PDO::PARAM_STR);  
                                $stmt->execute();  
                                $Str = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                sendMl($Str->eml,$CoinVal);
                            
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                               if($ard[$j1]!='DP112233') {
                                            LvBal_new($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                            unset($_SESSION['LastIntId']);
                                        }
                                        
                                                 
                                $stmt=$conn->prepare("update   UI__LevlCt set cct=cct+1 where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                }else
                                    {
                                        $stmt=$conn->prepare("update   UI__DChstr set  bnsStatus=1  where id=:id ");   
                                        $stmt->bindValue(':id', $MrefId , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                    }
                            }
                             
 					      }else if( ($j1==8) && ($Ssprcl100==1))
                        { 
                            
							$MYtotalCt=9;
							if($NewLevel==1)
							{
									$stmt=$conn->prepare("select cuurentId from UI__Rgst where refId=:refId  ");   
									$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
									$stmt->execute();  
									$MYtotalCt = $stmt->rowCount();
							}
							
							$CoinVal = ($data['Data']*(0.005))/100;     
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1 and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if( ($stmt->rowCount() > 0) && ($MYtotalCt>8) ) 
                            {
                                $stmt=$conn->prepare("select  cct  from UI__LevlCt where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                $IeerCt = $stmt->fetch(PDO::FETCH_OBJ); 
                                if($IeerCt->cct <= $levelDays) 
                                {
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 9 , PDO::PARAM_STR);  
                                $stmt->bindValue(':DaysLeft', ($leftdays-$IeerCt->cct) , PDO::PARAM_STR);    
                                $stmt->execute();   
                                
                                
                            
                                $stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $ard[$j1], PDO::PARAM_STR);  
                                $stmt->execute();  
                                $Str = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                sendMl($Str->eml,$CoinVal);
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                               if($ard[$j1]!='DP112233') {
                                            LvBal_new($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                            unset($_SESSION['LastIntId']);
                                        }
                                        
                                                 
                                $stmt=$conn->prepare("update   UI__LevlCt set cct=cct+1 where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                }else
                                    {
                                        $stmt=$conn->prepare("update   UI__DChstr set  bnsStatus=1  where id=:id ");   
                                        $stmt->bindValue(':id', $MrefId , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                    }
                            }
                             
 					      }else if( ($j1==9) && ($Ssprcl100==1))
                        { 
                            $MYtotalCt=10;
							if($NewLevel==1)
							{
									$stmt=$conn->prepare("select cuurentId from UI__Rgst where refId=:refId  ");   
									$stmt->bindValue(':refId', $ard[$j1] , PDO::PARAM_STR);   
									$stmt->execute();  
									$MYtotalCt = $stmt->rowCount();
							}
							
							$CoinVal = ($data['Data']*(0.005))/100;     
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1 and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if( ($stmt->rowCount() > 0) && ($MYtotalCt>9) ) 
                            {
                                $stmt=$conn->prepare("select  cct  from UI__LevlCt where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                $IeerCt = $stmt->fetch(PDO::FETCH_OBJ); 
                                if($IeerCt->cct <= $levelDays) 
                                {
                                $stmt=$conn->prepare("insert into  UI__Bns (Rid,Brid,Tdate,Tamt,BAmt,level,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 10 , PDO::PARAM_STR);        
                                $stmt->bindValue(':DaysLeft', ($leftdays-$IeerCt->cct) , PDO::PARAM_STR);    
                                $stmt->execute();   
                                
                                
                                
                                $stmt=$conn->prepare("select eml from UI__Rgst where cuurentId =:cuurentId ");   
                                $stmt->bindValue(':cuurentId', $ard[$j1], PDO::PARAM_STR);  
                                $stmt->execute();  
                                $Str = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                sendMl($Str->eml,$CoinVal);
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                               if($ard[$j1]!='DP112233') 
                               {
                                            LvBal_new($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                            unset($_SESSION['LastIntId']);
                                        }
                                        
                                                 
                                $stmt=$conn->prepare("update   UI__LevlCt set cct=cct+1 where tblId=:tblId and custId=:custId  ");   
                                $stmt->bindValue(':tblId', $MrefId , PDO::PARAM_STR);   
                                $stmt->bindValue(':custId', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                }else
                                    {
                                        $stmt=$conn->prepare("update   UI__DChstr set  bnsStatus=1  where id=:id ");   
                                        $stmt->bindValue(':id', $MrefId , PDO::PARAM_STR);    
                                        $stmt->execute();   
                                    }
                                
                               } 
 					        }
 					        
                                $stmt=$conn->prepare("insert test   (name) values(:Rname) ");   
                                $stmt->bindValue(':Rname', $_POST['cuurentId']."::".$ard[$j1] , PDO::PARAM_STR);  
                                $stmt->execute();   
 					        
                         }
                         
                      }   
                       
                      
						}//level condotion end 
                    }// if end
                       
					}// for end     
					      
        			$stmt=$conn->prepare("insert test   (name) values(:Rname) ");   
        			$stmt->bindValue(':Rname', "Completed..".date("d-M-Y H:i") , PDO::PARAM_STR);  
        			$stmt->execute();  
	            }
	            
	       
    //	       echo "The";
	      
