<?php
session_start();
include '../class/ClassForm.php';
$date = new DateTime();
$timeZone = $date->getTimezone();
$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)){
        date_default_timezone_set($timeZone->getName());
        $datetime = new DateTime($row['date_ref']);
        $minutes_to_add = 630;
        $datetime->add(new DateInterval('PT' . $minutes_to_add . 'M'));
        //$la_time = new DateTimeZone('Asia/Kolkata');
        //$datetime->setTimezone($la_time);
        
        ?>
        <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{
                    ?>
                    
                    <?php
                }
            ?>
            <td><?php echo $datetime->format('Y-m-d H:i:s'); ?></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>