<?php
	include_once('../config.php');   
    
                             
                                $stmt=$conn->prepare("insert into  test (name) values(:name) ");    
                                $stmt->bindValue(':name', date("d-M-y H:i")."COUNTING OUT"  , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                
                    
                            if($_REQUEST['RxxRd']=='bjhjx6349xnksdke3738438ff')
                            {  
                                
                                
                                $stmt=$conn->prepare("insert into  test (name) values(:name) ");    
                                $stmt->bindValue(':name', date("d-M-y H:i")."COUNTING IN"  , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                
                                

                                $stmt=$conn->prepare("select  Cid from UI__Droi group by Cid order by id asc ");    
                                $stmt->execute();    
                                $custIdResultAll = $stmt->fetchAll(PDO::FETCH_OBJ);   
                                
                                foreach($custIdResultAll as $ke=>$dmt)
                                {
                                    
                                   
                                    $stmt=$conn->prepare("select  * from UI__Droi where Cid=:Cid  order by id desc");   
                                    $stmt->bindValue(':Cid', $dmt->Cid, PDO::PARAM_STR);   
                                    $stmt->execute();    
                                    $custIdResult = $stmt->fetch(PDO::FETCH_OBJ);  
                               
                                    
                                    $Roi = ($custIdResult->Tamt*$custIdResult->Perset);
                                    $stmt=$conn->prepare("insert into UI__DailyIcm (Cid,RoiAmt,Tamt,Perset,UpdatedOn)  value(:Cid,:RoiAmt,:Tamt,:Perset,:UpdatedOn) ");   
                                    $stmt->bindValue(':Cid', $custIdResult->Cid, PDO::PARAM_STR);   
                                    $stmt->bindValue(':RoiAmt', $Roi, PDO::PARAM_STR);   
                                    $stmt->bindValue(':Tamt', $custIdResult->Tamt, PDO::PARAM_STR);   
                                    $stmt->bindValue(':Perset', $custIdResult->Perset, PDO::PARAM_STR);   
                                    $stmt->bindValue(':UpdatedOn', date("d-M-Y H:i"), PDO::PARAM_STR);    
                                    $stmt->execute();  
                                   
                                   
                                    $stmt=$conn->prepare("insert into UI__DChstr (typ,amt,Tdate,Rid,sId)  value(typ,amt,Tdate,Rid,sId)  ");   
                                    $stmt->bindValue(':typ',4, PDO::PARAM_STR);   
                                    $stmt->bindValue(':amt', $Roi, PDO::PARAM_STR);   
                                    $stmt->bindValue(':Tdate', date("d-M-Y H:i"), PDO::PARAM_STR);   
                                    $stmt->bindValue(':Rid', 'NA', PDO::PARAM_STR);   
                                    $stmt->bindValue(':sId',$custIdResult->Cid, PDO::PARAM_STR);    
                                    $stmt->execute();  
                                    
                                    $stmt=$conn->prepare("update  UI__Mnt set Mnnnt = Mnnnt+".$Roi."  where sId=:sId");    
                                    $stmt->bindValue(':sId', $custIdResult->Cid, PDO::PARAM_STR);  
                                    $stmt->execute();   
                                    
                                } 
                            
                            } 
        
?>
