<?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 Rechargedate>='$fdate' AND Rechargedate<='$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>Recharge Id</th>  
                        <th>API Partner Id</th>  
                        <th>Mobile No.</th>  
                        <th>Operator</th>  
                        <th>Amount</th>  
                        <th>Credit Used</th>  
                        <th>Status</th>
                        <th>Operator Id</th>
                    </tr>';
            while($row = mysqli_fetch_array($result))
            {
                $output .= ' <tr>  
                    <td>'.$row["Rechargedate"].'</td>  
                    <td>'.$row["Time"].'</td>
                    <td>'.$row["Id"].'</td>  
                    <td>'.$row["Partnerid"].'</td>  
                    <td>'.$row["Mobile"].'</td>  
                    <td>'.$row["Companyname"].'</td>  
                    <td>'.$row["Amount"].'</td>
                    <td>'.$row["Debitamount"].'</td>
                    <td>'.$row["Status"].'</td>
                    <td>'.$row["Operatorid"].'</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 paymentreq 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>P.Date</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['Txnnumber'];
                $output .= ' <tr>  
                    <td>'.$row["Id"].'</td>  
                    <td>'.$row["Date"].'</td>
                    <td>'.$row["Time"].'</td>
                    <td>'.$row["Paymentdate"].'</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>";
        }
    }
}
?>
