<?php
include'session.php';
include'connection.php';

$sarchType = $_POST['sarchType'];
$fdate     = $_POST['fdate'];
$ldate     = $_POST['ldate'];
$output    = '';

if(isset($_POST["export"]))
{
    if($sarchType=="REHARGE_REPORT")
    {
        $query = "SELECT * FROM recharge WHERE Userid='$userid' AND Date>='$fdate' AND Date<='$ldate'";
        $result = mysqli_query($con, $query);
        if(mysqli_num_rows($result) > 0)
        {
            $output .= '<table class="table" Borders="All Borders" cellpadding="10">  
                    <tr>  
                        <th>Date</th>  
                        <th>Time</th> 
                        <th>Order Id</th>  
                        <th>API Partner Id</th>  
                        <th>Mobile No.</th>  
                        <th>Operator</th>  
                        <th>Amount</th>    
                        <th>Status</th>
                        <th>Op Id</th>
                    </tr>';
            while($row = mysqli_fetch_array($result))
            {
                $output .= ' <tr>  
                    <td>'.$row["Date"].'</td>  
                    <td>'.$row["Time"].'</td>
                    <td>'.$row["Id"].'</td>  
                    <td>'.$row["Partnerid"].'</td>  
                    <td>'.$row["Mobile"].'</td>  
                    <td>'.$row["OpName"].'</td>  
                    <td>'.$row["Amount"].'</td>
                    <td>'.$row["Status"].'</td>
                    <td>'.$row["OpId"].'</td>
                </tr>';
            }
            $output .= '</table>';
            header('Content-Type: application/xls');
            header('Content-Disposition: attachment; filename=LLP_RECHARGE.xls');
            echo $output;
        }
        else
        {
            echo "<h2 style='color:red;'>Data Not Found !</h2>";
        }
    }
    elseif($sarchType=="TOPUP_REPORT")
    {
        $query="SELECT * FROM order_req WHERE Userid='$userid' AND Date>='$fdate' AND Date<='$ldate'";
        $result = mysqli_query($con, $query);
        if(mysqli_num_rows($result) > 0)
        {
            $output .= '<table class="table" Borders="All Borders" cellpadding="10">  
                    <tr>  
                        <th>Req.Id</th>
						<th>Date</th>
						<th>Time</th>
						<th>Amount</th>
						<th>Bank</th>
						<th>Txn No.</th>
						<th>Mode</th>
						<th>Status</th>
                    </tr>';
            while($row = mysqli_fetch_array($result))
            {
                $txnNo="#".$row['TxnNo'];
                $output .= ' <tr>  
                    <td>'.$row["Id"].'</td>  
                    <td>'.$row["Date"].'</td>
                    <td>'.$row["Time"].'</td>  
                    <td>'.$row["Amount"].'</td>  
                    <td>'.$row["BankName"].'</td>  
                    <td>'.$txnNo.'</td>  
                    <td>'.$row["Mode"].'</td>
                    <td>'.$row["Status"].'</td>
                </tr>';
            }
            $output .= '</table>';
            header('Content-Type: application/xls');
            header("Content-Disposition: attachment; filename=LLP_RECHARGE.xls");
            echo $output;
        }
        else
        {
            echo "<h2 style='color:red;'>Data Not Found !</h2>";
        }
    }
}
?>
