<?php 	include_once('../../config.php'); 

                     header('Content-type: text/csv');
                    $date = date("d-M-Y")." Report";
                    header('Content-Disposition: attachment; filename=""'.$date.'".csv"');
                    
                    // do not cache the file
                    header('Pragma: no-cache');
                    header('Expires: 0');
                    $lst =  $_REQUEST['Tdate'];     
                
                if($_REQUEST['type']==1)
                {   
                        $file = fopen('php://output', 'w'); 
                        // send the column headers
                        fputcsv($file, array('Name','UserId','Amount', 'Date'));   
                        $stmt=$conn->prepare("SELECT custId,Amt,Tdate FROM `UI__AtwReserse`  where  `Tdate` like '%$lst%' ");   
                        //$stmt->bindValue(':Tdate',  date("d-M-Y") , PDO::PARAM_STR);  
                        $stmt->execute();  
                        $AllUsers = $stmt->fetchAll(PDO::FETCH_ASSOC);   
                    
                        foreach ($AllUsers as $dt)
                        {       
                                
                                $stmt=$conn->prepare("select nm  from   UI__Rgst where cuurentId=:cuurentId ");  
                                $stmt->bindValue(':cuurentId', $dt['custId'] , PDO::PARAM_STR);
                                $stmt->execute();  
                                $Mnnnt = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                $Disk = null;
                                $Disk['nm'] = $Mnnnt->nm;   
                                $Disk['custId'] = $dt['custId'];
                                $Disk['Amt'] = $dt['Amt'];
                                $Disk['Tdate'] = $dt['Tdate']; 
                                fputcsv($file, $Disk);    
                                
                        } 
                        fclose($fp); 
                }
                
                if($_REQUEST['type']==2)
                {        
                        $file = fopen('php://output', 'w');  
                        fputcsv($file, array('Name','UserId','Amount', 'Date'));   
                        $stmt=$conn->prepare("SELECT  * FROM `UI__Atw`   where    status!=1 and   `Tdate` like '%$lst%'  ");    
                        $stmt->execute();  
                        $AllUsers = $stmt->fetchAll(PDO::FETCH_ASSOC);   
                    
                        foreach ($AllUsers as $dt)
                        {       
                                
                                $stmt=$conn->prepare("select nm  from   UI__Rgst where cuurentId=:cuurentId ");  
                                $stmt->bindValue(':cuurentId', $dt['custId'] , PDO::PARAM_STR);
                                $stmt->execute();  
                                $Mnnnt = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                $Disk = null;
                                $Disk['nm'] = $Mnnnt->nm;   
                                $Disk['custId'] = $dt['custId'];
                                $Disk['Amt'] = $dt['Amt'];
                                $Disk['Tdate'] = $dt['Tdate']; 
                                fputcsv($file, $Disk);    
                                
                        } 
                        fclose($fp);   
                }
                
                if($_REQUEST['type']==3)
                {  
                        
                        $file = fopen('php://output', 'w');  
                        fputcsv($file, array('Name','UserId','Amount', 'Date'));   
                        $stmt=$conn->prepare("SELECT  * from  `UI__WithDraw`  where TWhm!=''  and `Tdate` like '%$lst%'  ");   
                        $stmt->execute();  
                        $AllUsers = $stmt->fetchAll(PDO::FETCH_ASSOC);   
                    
                        foreach ($AllUsers as $dt)
                        {       
                                
                                $stmt=$conn->prepare("select nm  from   UI__Rgst where cuurentId=:cuurentId ");  
                                $stmt->bindValue(':cuurentId', $dt['userid'] , PDO::PARAM_STR);
                                $stmt->execute();  
                                $Mnnnt = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                $Disk = null;
                                $Disk['nm'] = $Mnnnt->nm;   
                                $Disk['custId'] = $dt['userid'];
                                $Disk['Amt'] = $dt['amt'];
                                $Disk['Tdate'] = $dt['Tdate']; 
                                fputcsv($file, $Disk);    
                                
                        } 
                        fclose($fp);     
                }
                
                if($_REQUEST['type']==4)
                {  
                        
                        $lst1 = $_REQUEST['Tdate1'];
                        $file = fopen('php://output', 'w');  
                        fputcsv($file, array('Name','UserId','Amount', 'Date'));   
                         $stmt=$conn->prepare("SELECT * FROM `moneytransfer`  where bankTrnfer= 1 and (`last_update` like '%$lst%'  || `last_update` like '%$lst1%'  ) ");   
                        $stmt->execute();  
                        $AllUsers = $stmt->fetchAll(PDO::FETCH_ASSOC);   
                    
                        foreach ($AllUsers as $dt)
                        {       
                                
                                $stmt=$conn->prepare("select nm  from   UI__Rgst where cuurentId=:cuurentId ");  
                                $stmt->bindValue(':cuurentId', $dt['cust_id'] , PDO::PARAM_STR);
                                $stmt->execute();  
                                $Mnnnt = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                $Disk = null;
                                $Disk['nm'] = $Mnnnt->nm;   
                                $Disk['custId'] = $dt['cust_id'];
                                $Disk['Amt'] = $dt['amount'];
                                $Disk['Tdate'] = $dt['last_update']; 
                                fputcsv($file, $Disk);    
                                
                        } 
                        fclose($fp);     
                }
     
                
               
 
                if($_REQUEST['type']==5)
                {  
                        
                        $file = fopen('php://output', 'w');  
                        fputcsv($file, array('Name','Id','RefId','Phone','Date'));   
                        $stmt=$conn->prepare("select  * from  UI__Rgst   where RegOn like '$lst' ");   
                        $stmt->execute();  
                        $AllUsers = $stmt->fetchAll(PDO::FETCH_ASSOC);   
                    
                        foreach ($AllUsers as $dt)
                        {       
                                
                                $stmt=$conn->prepare("select nm  from   UI__Rgst where cuurentId=:cuurentId ");  
                                $stmt->bindValue(':cuurentId', $dt['cuurentId'] , PDO::PARAM_STR);
                                $stmt->execute();  
                                $Mnnnt = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                $Disk = null;
                                $Disk['nm'] = $Mnnnt->nm;   
                                $Disk['custId'] = $dt['cuurentId'];
                                $Disk['refId'] = $dt['refId'];
                                $Disk['Ph'] = $dt['phm']; 
                                $Disk['Tdate'] = $dt['RegOn']; 
                                fputcsv($file, $Disk);    
                                
                        } 
                        fclose($fp);     
                }
                
                 if($_REQUEST['type']==6)
                {  
                        
                        $file = fopen('php://output', 'w');  
                        fputcsv($file, array('Name','Id','Amount','Date'));   
                        $stmt=$conn->prepare("SELECT Tamt,Rid,Tdate FROM `UI__Bns`  where  `Tdate` like '%$lst%'  "); 
                        $stmt->execute();  
                        $AllUsers = $stmt->fetchAll(PDO::FETCH_ASSOC);   
                    
                        foreach ($AllUsers as $dt)
                        {       
                                
                                $stmt=$conn->prepare("select nm  from   UI__Rgst where cuurentId=:cuurentId ");  
                                $stmt->bindValue(':cuurentId', $dt['Rid'] , PDO::PARAM_STR);
                                $stmt->execute();  
                                $Mnnnt = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                $Disk = null;
                                $Disk['nm'] = $Mnnnt->nm;   
                                $Disk['custId'] = $dt['Rid'];
                                $Disk['Amt'] = $dt['Tamt']; 
                                $Disk['Tdate'] = $dt['Tdate']; 
                                fputcsv($file, $Disk);    
                                
                        } 
                        fclose($fp);     
                }
                
                
                if($_REQUEST['type']==7)
                {  
                        
                        $lst1 = $_REQUEST['Tdate1'];
                        $file = fopen('php://output', 'w');  
                        fputcsv($file, array('Name','UserId','Amount', 'Date'));   
                         $stmt=$conn->prepare("SELECT * FROM `moneytransfer` where bankTrnfer= 0 and (`last_update` like '%$lst%'  || `last_update` like '%$lst1%'  ) ");   
                        $stmt->execute();  
                        $AllUsers = $stmt->fetchAll(PDO::FETCH_ASSOC);   
                    
                        foreach ($AllUsers as $dt)
                        {       
                                
                                $stmt=$conn->prepare("select nm  from   UI__Rgst where cuurentId=:cuurentId ");  
                                $stmt->bindValue(':cuurentId', $dt['cust_id'] , PDO::PARAM_STR);
                                $stmt->execute();  
                                $Mnnnt = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                $Disk = null;
                                $Disk['nm'] = $Mnnnt->nm;   
                                $Disk['custId'] = $dt['cust_id'];
                                $Disk['Amt'] = $dt['amount'];
                                $Disk['Tdate'] = $dt['last_update']; 
                                fputcsv($file, $Disk);    
                                
                        } 
                        fclose($fp);     
                }
                
                
                if($_REQUEST['type']==10)
                {   
                        $file = fopen('php://output', 'w');  
                        fputcsv($file, array('Name','Id','Amount','Date'));   
                        $stmt=$conn->prepare("SELECT amount,custId,Tdate FROM `UI__DailyROIGene`  where  `Tdate` like '%$lst%'  ");   
                        $stmt->execute();  
                        $AllUsers = $stmt->fetchAll(PDO::FETCH_ASSOC);   
                    
                        foreach ($AllUsers as $dt)
                        {       
                                
                                $stmt=$conn->prepare("select nm  from   UI__Rgst where cuurentId=:cuurentId ");  
                                $stmt->bindValue(':cuurentId', $dt['custId'] , PDO::PARAM_STR);
                                $stmt->execute();  
                                $Mnnnt = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                $Disk = null;
                                $Disk['nm'] = $Mnnnt->nm;   
                                $Disk['custId'] = $dt['custId'];
                                $Disk['Amt'] = $dt['amount']; 
                                $Disk['Tdate'] = $dt['Tdate']; 
                                fputcsv($file, $Disk);    
                                
                        } 
                        fclose($fp);     
                }