<?php
session_start();
include '../class/ClassForm.php';

$query = "select * from qr_invdetails where remarks = '".$_SESSION['user_id']."'";
$result = $ClassForm->Fetch_Result_Set($query);
?>

<table class="table  tesla" id="inv_table">
    <thead>
        <tr>
            <th> Buyer GSTIN
            </th>
            <th> Invoice No
            </th>
            <th> Invoice Date
            </th>
            <th> Total Amount
            </th>
            <th> Download QR
            </th>
            <th> Download Excel
            </th>
            <?php 
                if($_SESSION['user'] == "Rane"){
            ?>
            <th> Download PDF
            </th>
            
            <?php 
                }
            ?>
            <th> Time of Import
            </th>
            <th> Download JsonFile
            </th>
            
        </tr>
    </thead>
    <tbody>
    <?php
    while($row = mysqli_fetch_assoc($result)){
        ?>
        <tr>
            <td> <?php echo $row['buy_gstin']; ?> </td>
            <td> <?php echo $row['inv_no']; ?> </td>
            <td> <?php echo $row['inv_date']; ?> </td>
            <td> <?php echo $row['tot_amount']; ?> </td>
            <td> <a href="<?php echo $row['qr_url']; ?>" target="_blank">Download QR Image</a> </td>
            <td> <a href="<?php echo $row['excel_url']; ?>" target="_blank">Download File</a></td>
            <?php 
                $pdfUrl = str_replace('.xlsx','.PDF',$row['excel_url']);
                if($_SESSION['user'] == "Rane" && $row['inv_no'] == "6601383850"){
            ?>
            <td> <a href="http://elearn.stvat.com/E-Invoice1/uploads/Excel/Rane_.pdf" target="_blank">Download PDF File</a></td>
            <?php
                }
                else if(file_exists("../".$pdfUrl)){
                    ?>
                    <td> <a href="<?php echo $pdfUrl;?>" target="_blank">Download PDF File</a></td>
                    <?php
                }
                else{
                    ?>
                    <td></td>
                    <?php
                }
            ?>
            <td><?php echo substr($row['date_ref'],10,6); ?></td>
            <td> <a href="<?php echo $row['json_url']; ?>" download="<?php echo $row['buy_gstin']; ?>.json" target="_blank">Download Json</a></td>
            
        </tr>
        <?php
    }
    ?>
    </tbody>    
</table>