</main>
<!--start overlay-->
    <div class="overlay btn-toggle"></div>
    <!--end overlay-->









    <!-- Bootstrap JS -->
    <script src="<?php echo base_url('assets/js/bootstrap.bundle.min.js'); ?>"></script>

    <!-- Plugins -->
    <script src="<?php echo base_url('assets/js/jquery.min.js'); ?>"></script>    
    <script src="<?php echo base_url('assets/plugins/perfect-scrollbar/js/perfect-scrollbar.js'); ?>"></script>
    <script src="<?php echo base_url('assets/plugins/metismenu/metisMenu.min.js'); ?>"></script>

    <!-- Custom JS 
    <script src="<?php echo base_url('assets/js/index2.js'); ?>"></script>
    -->
    <script src="<?php echo base_url('assets/js/main.js'); ?>"></script>

    <script>


$(document).ready(function() {
    function formatTimestamp(timestamp) {
    const date = new Date(timestamp);
    const now = new Date();

    const isToday = date.toDateString() === now.toDateString();

    if (isToday) {
        // Return only the time part if the date is today
        return date.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', second: '2-digit' });
    } else {
        // Return the full date and time otherwise
        const options = { 
            year: 'numeric', 
            month: 'long', 
            day: 'numeric', 
            hour: '2-digit', 
            minute: '2-digit', 
            second: '2-digit' 
        };
        return date.toLocaleString('en-US', options);
    }
}

    function fetchNotifications() {
                $.ajax({
                    url: '<?php echo base_url().'dashboard/readnotification' ?>', // URL of your PHP script
                    type: 'GET',
                    success: function(data) {
                        $('#notificationsDiv').empty();
                        console.log(data);
                        $("#notification_no").text(data.length);
                        data.forEach(function(notification) {
                            
                            $('#notificationsDiv').append(
                                '<a class="dropdown-item border-bottom py-2" href="javascript:;">' +
                                '<div class="d-flex align-items-center gap-3">' +
                                '<div class="">' +
                                '<img src="http://137.184.111.69/rapidopharmacy/assets/images/apps/14.png" class="rounded-circle" width="45" height="45" alt="" />' +
                                '</div>' +
                                '<div class="">' +
                                '<h5 class="notify-title">' + notification.title + '</h5>' +
                                '<p class="mb-0 notify-desc">' + notification.description + '</p>' +
                                '<p class="mb-0 notify-time">' + formatTimestamp(notification.time) + '</p>' +
                                '</div>' +
                                '<div style="display:none;" class="notify-close position-absolute end-0 me-3">' +
                                '<i class="material-icons-outlined fs-6">close</i>' +
                                '</div>' +
                                '</div>' +
                                '</a>'
                            );
                        });
                    },
                    error: function(error) {
                        console.log('Error fetching notifications:', error);
                    }
                });
            }

            // Fetch notifications on page load
            fetchNotifications();

            // Optionally, set an interval to refresh notifications periodically
            setInterval(fetchNotifications, 60000); // Refresh every 60 seconds

   //secondbutton
   $('.searchInput').on('keyup', function() {
                var query = $(this).val();
                console.log(query);
                if (query.length > 2) { // Start searching after 3 characters
                    $.ajax({
                        url: '<?php echo base_url().'driver/search' ?>', // URL of your PHP script
                        type: 'GET',
                        data: { q: query },
                        success: function(data) {
                            console.log(data);
                            $('#searchResults').empty();
                            data.forEach(function(user) {
                                $('#searchResults').append(
                                    '<div class="search-list-item d-flex align-items-center gap-3">' +
                                    '<div class="member-img">' +
                                    '<img src="' + user.image+'" width="32" height="32" class="rounded-circle" alt="">' +
                                    '</div>' +
                                    '<div>' +
                                    '<h5 class="mb-0 search-list-title">' + user.firstName + ' ' + user.lastName + '</h5>' +
                                    '</div>' +
                                    '</div>'
                                );
                            });
                        }
                    });
                } else {
                    $('#searchResults').empty();
                }
            });
   //
   $('#submitorder').click(function() {
    const OrderId= $("#orderid").val();
    const driverid= $("#driverid").val();
    const doctorid= $("#doctorid").val();
    const comments= $("#comments").val();
    var medicineItems = [];
    var medicineChecked = [];
    $('input[name="medicineItem[]"]').each(function() {
        medicineItems.push($(this).val());
        });

    $('input[name="medicinechecked[]"]').each(function() {
        medicineChecked.push($(this).is(':checked') ? true : false);
        });

        console.log("Medicine Items:", medicineItems);
        console.log("Medicine Checked:", medicineChecked);
        console.log("OrderId",OrderId);
        console.log("driverid",driverid);
        console.log("doctorid",doctorid);
        console.log("comments",comments);
        $.ajax({
            url: '<?php echo base_url().'order/posttheorder' ?>', // Replace with your endpoint URL
            method: 'POST', // Change to GET if you are making a GET request
            data: {
                OrderId: OrderId,
                driverid:driverid,
                doctorid:doctorid,
                comments:comments,
                medicineItems:medicineItems,
                medicineChecked:medicineChecked



            },
            success: function(response) {
                console.log(response)      
                if(response=="success"){
                    location.reload();
                }           
            },
            error: function(error) {
                // Handle any errors here
                console.error("AJAX call failed:", error);
            }

    });




   });
   $('.secondbutton').click(function() {
    console.log("second step");
    var medicineItems = [];
    var medicineChecked = [];
    $('input[name="medicineItem[]"]').each(function() {
        medicineItems.push($(this).val());
        });

                $('input[name="medicinechecked[]"]').each(function() {
                    medicineChecked.push($(this).is(':checked') ? true : false);
                });

                console.log("Medicine Items:", medicineItems);
                console.log("Medicine Checked:", medicineChecked);

                for (var i = 0; i < medicineItems.length; i++) {
                    var itemHtml = '<div class="oCard d-flex justify-content-between align-items-center p-1">' +
                                   '<p class="m-0 fmon fs15">' + medicineItems[i] + '</p>';

                    if (medicineChecked[i]) {
                        itemHtml += '<button class="btn crBtn fs14 fmon">Monitored Medicine</button>';
                    }

                    itemHtml += '</div>';
                    $('#medicineDisplayContainer').empty();
                    $('#medicineDisplayContainer').append(itemHtml);
                }
           //exampleModalToggle2    
           $('#exampleModalToggle2').modal('show'); 


   });
    $('.myButton').click(function() {
        // Get the data-id attribute of the clicked button
        var dataId = $(this).data('id');
        $("#orderid").val(dataId);

        $.ajax({
            url: '<?php echo base_url().'order/getorderinfo' ?>', // Replace with your endpoint URL
            method: 'POST', // Change to GET if you are making a GET request
            data: {
                id: dataId
            },
            success: function(response) {
                $('#exampleModalToggle2').modal('show');
                // Handle the successful response here
                console.log("AJAX call successful:", response);
                console.log(typeof response);
                const obj=JSON.parse(response);
                console.log(obj.orderdata);
                console.log(obj.patient_info);
                const orderData=obj.orderdata;
                const patient=obj.patient_info;
                if(orderData.status=="Complete"){
                    $("#driversignatureinfo").show();
                    
                    $('#descriptionImage').attr('src', orderData.parsalImage);
                    $('#signatureImage').attr('src', orderData.signatureImage);

                }else{
                    $("#driversignatureinfo").hide();
                }
                $("#text_patient_name").text(patient.firstName + " "+patient.lastName);
                $("#text_ptext_patient_idatient_name").text(orderData.patientID);
                $("#text_reciver").text(patient.firstName + " "+patient.lastName);
                $("#text_address").text(orderData.address);
                $("#text_address").text(orderData.address);
                $("#text_phone").text(patient.phoneNumber);
                $("#text_email").text(patient.email);

                if(patient.image !=""){
                    $('#text_patient_image').attr('src', patient.image);
                    $('#text_reciver_image').attr('src', patient.image);
                }
                const medicine=orderData.medicine;
                const medicineItems = Object.keys(medicine);
            const medicineChecked = Object.values(medicine);
            $('#medicineDisplayContainer').empty();
           
               //console.log(medicine ); 
               for (var i = 0; i < medicineItems.length; i++) {
                    var itemHtml = '<div class="oCard d-flex justify-content-between align-items-center p-1">' +
                                   '<p class="m-0 fmon fs15">' + medicineItems[i] + '</p>';

                    if (medicineChecked[i]) {
                        itemHtml += '<button class="btn crBtn fs14 fmon">Monitored Medicine</button>';
                    }

                    itemHtml += '</div>';

                    $('#medicineDisplayContainer').append(itemHtml);
                }
                
////text_reciver
                



            },
            error: function(error) {
                // Handle any errors here
                console.error("AJAX call failed:", error);
            }

    });
});
});
</script>
</body>


<!-- Mirrored from codervent.com/matoxi/demo/vertical-menu/index2.html by HTTrack Website Copier/3.x [XR&CO'2014], Tue, 09 Jan 2024 16:36:47 GMT -->

</html>