MMCT TEAM
Server IP : 162.214.80.37  /  Your IP : 216.73.216.83
Web Server : Apache
System : Linux sh013.webhostingservices.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
User : imyrqtmy ( 2189)
PHP Version : 8.2.18
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home2/imyrqtmy/public_html/Quickex/builty/admin/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home2/imyrqtmy/public_html/Quickex/builty/admin/view-invoice copy.php
<?php
session_start();
$se = $_SESSION["id"];
if (!isset($_SESSION['id'])) {
    header("Location: login.php");
}
include("inc/config.php");
 
?>

<!DOCTYPE html>
<html lang="en">

<?php require "inc/head.php"; ?>

    <body>
        <!-- header-->
    <?php require "inc/header.php"; ?>
        <!-- End Main-content Top bar-->

        <!-- main-content-->
        <div class="wrapper">
        <?php require "inc/sidebar.php"; ?>
            <div id="content">
                <div class="row">
                    <div class="col-12 col-sm-12">
                        <div class="row mb-4">
                            <div class="col-12 col-md-12">
                                <div class="card redial-border-light redial-shadow mb-4">
                                    <div class="card-body">
                                        <h6 class="header-title pl-3 redial-relative">Data Table</h6>
                                       
                                        <?php
include("inc/config.php"); // Include database connection
$se = $_SESSION["id"]; // Logged-in employee ID
$invoice_folder = "invoices/"; // Folder where invoices are stored
?>
<table id="example" class="table table-bordered" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>#</th>
            <th>Gr No.</th>
            <th>Invoice File</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody>
        <?php
        // Check if the folder exists before scanning
        if (file_exists($invoice_folder)) {
            $files = glob($invoice_folder . "invoice_*.pdf"); // Get all invoice files

            if (!empty($files)) {
                foreach ($files as $file) {
                    // Extract invoice ID from filename (e.g., invoice_1.pdf -> 1)
                    preg_match('/invoice_(\d+)\.pdf$/', basename($file), $matches);
                    if (isset($matches[1])) {
                        $invoice_id = intval($matches[1]);

                        // Fetch only invoices that match the logged-in employee
                        $query = "SELECT grno FROM builties WHERE id = '$invoice_id' AND emp_id = '$se'";
                        $result = mysqli_query($conn, $query);
                        $data = mysqli_fetch_assoc($result);

                        if ($data) {
                            echo "<tr>
                                    <td>{$invoice_id}</td>
                                    <td>{$data['grno']}</td>
                                    <td><a href='{$file}' class='btn btn-primary' target='_blank'>View Invoice</a></td>
                                    <td>
                                        <button class='btn btn-danger delete-invoice' data-file='{$file}'><i class='fa fa-trash'></i></button>
                                    </td>
                                  </tr>";
                        }
                    }
                }
            } else {
                echo "<tr><td colspan='4' class='text-center'>No invoices found</td></tr>";
            }
        } else {
            echo "<tr><td colspan='4' class='text-center'>Invoices folder does not exist</td></tr>";
        }
        ?>
    </tbody>
</table>


<!-- jQuery for handling the delete button -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
    $(".delete-invoice").click(function() {
        var filePath = $(this).data("file");

        if (confirm("Are you sure you want to delete this invoice?")) {
            $.ajax({
                url: "delete_invoice.php",
                type: "POST",
                data: { file: filePath },
                success: function(response) {
                    alert(response);
                    location.reload(); // Refresh the page after deletion
                }
            });
        }
    });
});
</script>




                                     
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>    
            </div>
        </div>
        <!-- End main-content-->

        <!-- Top To Bottom-->
        <a href="#" class="scrollup text-center redial-bg-primary redial-rounded-circle-50"> 
            <h4 class="text-white mb-0"><i class="icofont icofont-long-arrow-up"></i></h4>
        </a>
        <!-- End Top To Bottom-->

     
        <script>
            function confirmInvoice(id) {
                if (confirm("Are you sure you want to create an Invoice?")) {
                    window.location.href = "invoice.php?id=" + id;
                }
            }
        </script>

        <!-- jQuery -->
        <script src="dist/js/plugins.min.js"></script>        
        <script src="dist/js/common.js"></script>
    </body>

</html>

MMCT - 2023