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

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

if(isset($_POST["export"]))
{
        $query="SELECT * FROM wallet WHERE Transactiontype='Generate_Amount' AND Date>='$fdate' AND Date<='$ldate' OR TxnType='Generate_Amount' 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>W.Id</th>
						<th>Date</th>
						<th>Time</th>
						<th>TxnType</th>
						<th>TxnWith</th>
						<th>TxnId</th>
						<th>TxnBy</th>
						<th>Txn</th>
						<th>Remarks</th>
						<th>Credit</th>
						<th>Paymentfrom</th>
						<th>Payfromname</th>
						<th>Paymentto</th>
						<th>Paytoname</th>
						<th>Paynrechid</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["TxnType"].'</td>  
                    <td>'.$row["TxnWith"].'</td>  
                    <td>'.$row["TxnId"].'</td>
                    <td>'.$row["TxnBy"].'</td>
                    <td>'.$row["Txn"].'</td>
                    <td>'.$row["Remarks"].'</td>
                    <td>'.$row["Credit"].'</td>
                    <td>'.$row["Paymentfrom"].'</td>
                    <td>'.$row["Payfromname"].'</td>
                    <td>'.$row["Paymentto"].'</td>
                    <td>'.$row["Paytoname"].'</td>
                    <td>'.$row["Paynrechid"].'</td>
                </tr>';
            }
            $output .= '</table>';
            $fdate=date_create($fdate);
            $fdate=date_format($fdate,"d/M/Y");
            $ldate=date_create($ldate);
            $ldate=date_format($ldate,"d/M/Y");
            $fnFdate="GenerateAmount_$fdate";
            $fnLdate="_To_".$ldate;
            $filename=$fnFdate.$fnLdate;
            header('Content-Type: application/xls');
            header("Content-Disposition: attachment; filename=$filename.xls");
            echo $output;
        }
        else
        {
            echo "<h2 style='color:red;'>Data Not Found !</h2>";
        }
    
}
?>
