var Norecord = '<div class="img-center"><img src="/Content/img/no_record.png" class="img-resposive no_record_img" style="height:65px; width:72px; border-radius:0px;"><br><div class="no_data_content">No data found.</div></div>';

$(document).ready(function () {
        patient_lab_order();
});

function datefun() {
    var d = new Date();

    var month = d.getMonth() + 1;
    var day = d.getDate();

    var output = (day < 10 ? '0' : '') + day + '/' +
        (month < 10 ? '0' : '') + month + '/' +
        d.getFullYear();
    $('#hndtoday').val(output);

    //yesterday
    var d = new Date();

    var month = d.getMonth() + 1;
    var day = d.getDate() - 1;

    var output = (day < 10 ? '0' : '') + day + '/' +
        (month < 10 ? '0' : '') + month + '/' +
        d.getFullYear();
    $('#hndyesterday').val(output);

    //tomorrow

    var d = new Date();

    var month = d.getMonth() + 1;
    var day = d.getDate() + 1;

    var output = (day < 10 ? '0' : '') + day + '/' +
        (month < 10 ? '0' : '') + month + '/' +
        d.getFullYear();
    $('#hndtomorrow').val(output);
}


function Lableftarrow() {
    if ($('#app_date_current').html() == 'Today') {
        var d = new Date();

        var month = d.getMonth() + 1;
        var day = d.getDate();

        var output = (day < 10 ? '0' : '') + day + '/' +
            (month < 10 ? '0' : '') + month + '/' +
            d.getFullYear();
        $('#app_date_current').html(output);
    }
    else if ($('#app_date_current').html() == 'Yesterday') {
        var d = new Date();

        var month = d.getMonth() + 1;
        var day = d.getDate() - 1;

        var output = (day < 10 ? '0' : '') + day + '/' +
            (month < 10 ? '0' : '') + month + '/' +
            d.getFullYear();
        $('#app_date_current').html(output);
    }
    else if ($('#app_date_current').html() == 'Tomorrow') {
        var d = new Date();

        var month = d.getMonth() + 1;
        var day = d.getDate() + 1;

        var output = (day < 10 ? '0' : '') + day + '/' +
            (month < 10 ? '0' : '') + month + '/' +
            d.getFullYear();
        $('#app_date_current').html(output);
    }


    var displaydate = $('#app_date_current').html();
    var date = '';
    var month = '';
    var displaydates = displaydate.split("/");
    displaydate = displaydates[1];
    if (displaydate == '01' || displaydate == '03' || displaydate == '05' || displaydate == '07' || displaydate == '08' || displaydate == '10' || displaydate == '12') {
        if (displaydates[0] > 1) {
            date = displaydates[0] - 1;
            if (date < 10) {
                date = '0' + date;
            }
            date = date + '/' + displaydates[1] + '/' + displaydates[2];
            $('#app_date_current').html(date);
        }
        else {
            if (displaydate == '12') {
                date = parseInt(displaydates[1]) + parseInt(1);
                date = '30' + '/' + '11' + '/' + displaydates[2];
                $('#app_date_current').html(date);
            }
            else if (displaydate == '01') {
                date = parseInt(displaydates[1]) + parseInt(1);
                var year = (displaydates[2]) - (1);
                date = '31' + '/' + '12' + '/' + year;
                $('#app_date_current').html(date);
            }
            else if (displaydate == '03') {
                date = parseInt(displaydates[1]) + parseInt(1);
                date = '28' + '/' + '02' + '/' + displaydates[2];
                $('#app_date_current').html(date);
            }
            else {
                date = displaydates[1] - 1;
                if (date < 10) {
                    date = '0' + date;
                }
                date = '30' + '/' + date + '/' + displaydates[2];
                $('#app_date_current').html(date);
            }
        }

    }
    else if (displaydate == '04' || displaydate == '06' || displaydate == '09' || displaydate == '11') {
        if (displaydates[0] > 1) {
            date = displaydates[0] - 1;
            if (date < 10) {
                date = '0' + date;
            }
            date = date + '/' + displaydates[1] + '/' + displaydates[2];
            $('#app_date_current').html(date);
        }
        else {
            date = displaydates[1] - 1;
            if (date < 10) {
                date = '0' + date;
            }
            date = '31' + '/' + date + '/' + displaydates[2];
            $('#app_date_current').html(date);
        }
    }
    else {
        if (displaydates[0] > 1) {
            date = displaydates[0] - 1;
            if (date < 10) {
                date = '0' + date;
            }
            date = date + '/' + displaydates[1] + '/' + displaydates[2];
            $('#app_date_current').html(date);
        }
        else {
            date = displaydates[1] - 1;
            if (date < 10) {
                date = '0' + date;
            }
            date = '31' + '/' + '01' + '/' + displaydates[2];
            $('#app_date_current').html(date);
        }
    }
    if (date == $('#hndtoday').val()) {
        $('#app_date_current').html('Today');
    }
    if (date == $('#hndyesterday').val()) {
        $('#app_date_current').html('Yesterday');
    }
    if (date == $('#hndtomorrow').val()) {
        $('#app_date_current').html('Tomorrow');
    }
    date_order_list();
}


function Labrightarrow() {
    if ($('#app_date_current').html() == 'Today') {

        var d = new Date();

        var month = d.getMonth() + 1;
        var day = d.getDate();

        var output = (day < 10 ? '0' : '') + day + '/' +
            (month < 10 ? '0' : '') + month + '/' +
            d.getFullYear();
        $('#app_date_current').html(output);
        $('#app_date_current1').html(output);
        $('#app_date_current2').html(output);
        $('#app_date_current3').html(output);
    }


    else if ($('#app_date_current').html() == 'Yesterday') {
        var d = new Date();

        var month = d.getMonth() + 1;
        var day = d.getDate() - 1;

        var output = (day < 10 ? '0' : '') + day + '/' +
            (month < 10 ? '0' : '') + month + '/' +
            d.getFullYear();
        $('#app_date_current').html(output);
    }
    else if ($('#app_date_current').html() == 'Tomorrow') {
        var d = new Date();

        var month = d.getMonth() + 1;
        var day = d.getDate() + 1;

        var output = (day < 10 ? '0' : '') + day + '/' +
            (month < 10 ? '0' : '') + month + '/' +
            d.getFullYear();
        $('#app_date_current').html(output);
    }
    var displaydate = $('#app_date_current').html();
    var date = '';
    var month = '';
    var displaydates = displaydate.split("/");
    displaydate = displaydates[1];
    if (displaydate == '01' || displaydate == '03' || displaydate == '05' || displaydate == '07' || displaydate == '08' || displaydate == '10' || displaydate == '12') {
        if (displaydates[0] < 31) {
            date = parseInt(displaydates[0]) + parseInt(1);
            if (date < 10) {
                date = '0' + date;
            }
            date = date + '/' + displaydates[1] + '/' + displaydates[2];
            $('#app_date_current').html(date);
        }
        else {
            if (displaydate == '12') {
                date = parseInt(displaydates[1]) + parseInt(1);
                year = parseInt(displaydates[2]) + parseInt(1);
                date = '01' + '/' + '01' + '/' + year;
                $('#app_date_current').html(date);
            }
            else {
                date = parseInt(displaydates[1]) + parseInt(1);
                if (date < 10) {
                    date = '0' + date;
                }
                date = '01' + '/' + date + '/' + displaydates[2];
                $('#app_date_current').html(date);
            }
        }
    }
    else if (displaydate == '04' || displaydate == '06' || displaydate == '09' || displaydate == '11') {
        if (displaydates[0] < 30) {
            date = parseInt(displaydates[0]) + parseInt(1);
            if (date < 10) {
                date = '0' + date;
            }
            date = date + '/' + displaydates[1] + '/' + displaydates[2];
            $('#app_date_current').html(date);
        }
        else {
            date = parseInt(displaydates[1]) + parseInt(1);
            if (date < 10) {
                date = '0' + date;
            }
            date = '01' + '/' + date + '/' + displaydates[2];
            $('#app_date_current').html(date);
        }
    }
    else {
        if (displaydates[0] < 28) {
            date = parseInt(displaydates[0]) + parseInt(1);
            if (date < 10) {
                date = '0' + date;
            }
            date = date + '/' + displaydates[1] + '/' + displaydates[2];
            $('#app_date_current').html(date);
        }
        else {
            date = parseInt(displaydates[1]) + parseInt(1);
            if (date < 10) {
                date = '0' + date;
            }
            date = '01' + '/' + date + '/' + displaydates[2];
            $('#app_date_current').html(date);
        }
    }
    if ($('#app_date_current').html() == $('#hndtoday').val()) {
        $('#app_date_current').html('Today');
    }
    if ($('#app_date_current').html() == $('#hndyesterday').val()) {
        $('#app_date_current').html('Yesterday');
    }
    if ($('#app_date_current').html() == $('#hndtomorrow').val()) {
        $('#app_date_current').html('Tomorrow');
    }
    date_order_list();
}

$('#datepicker1').change(function () {
    var date = $('#datepicker1').val();
    $('#app_date_current').html(date);
    date_order_list()
});


$('#Selorder_status').change(function () {
    if($('#Selorder_status').val() == '0')
    {
        patient_lab_order();
    }
    else if ($('#Selorder_status').val() == '1') {
        select_option_filter('AOL');
    }
    else if ($('#Selorder_status').val() == '2') {
        select_option_filter('COL');
    }
    else if ($('#Selorder_status').val() == '3') {
        select_option_filter('CCOL');
    }
    else if ($('#Selorder_status').val() == 4) {
        $('#datefilter').show();
        $('#patientName_filter').hide();
        $('#btnsubmit_order').show();
        return false;
    }
    else if ($('#Selorder_status').val() == 5) {
        $('#datefilter').hide();
        $('#patientName_filter').show();
        $('#btnsubmit_order').show();
        return false;
    }
    else {
        $('#datefilter').hide();
        $('#patientName_filter').hide();
        $('#btnsubmit_order').hide();
    }
});


$('#btncloseX').click(function () {
    clear();
});

$('#btnclose').click(function () {
    clear();
});


function patient_lab_order()
{
    var date;
    if ($('#app_date_current').html() == 'Today') {
        var d = new Date();

        var month = d.getMonth() + 1;
        var day = d.getDate();

        var output = (day < 10 ? '0' : '') + day + '/' +
            (month < 10 ? '0' : '') + month + '/' +
            d.getFullYear();
        date = output;
    }
    else if ($('#app_date_current').html() == 'Yesterday') {
        date = $('#hndyesterday').val();
    }
    else if ($('#app_date_current').html() == 'Tomorrow') {
        date = $('#hndtomorrow').val();
    }
    else {
        date = $('#app_date_current').html();

    } 
    var dates = date.split('/');
    date = dates[2] + '-' + dates[1] + '-' + dates[0];
    var Template = {
        date: date,
        doctor_id: $('#HiddenDoctorID').val(),
        Dml_Indicator: "OL"
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Template/lab_home_colection',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(Template),
        success: function (data) {
            $('#loaderimg').hide();
            $('#Jobdetails').empty();
            var data2 = JSON.parse(data);
            if (jQuery.isEmptyObject((data2.data))) {
                $('#Jobdetails').html(Norecord);
            }
            else
            {

                if (data2.msg == "Success") {
                    var data1 = data2.data;

                    var invoiceAmt = '', invoicedue = '', j, order_status = '', pickup_by, test_type, phone;
                    if (data.length > 4 && data != null) {
                        var b = data1.Table;
                        var c = data1.Table1;
                        $('#AdviceCount').html(b[0].total_order);
                        $('#pendingorder').html(b[0].self_picup);
                        $('#pendingjob').html(b[0].i2h_pickup);
                        tr = $('<table class="table table-bordered table-striped dataTable mt20" id="labJoblist" />');
                        tr.append('<thead><tr><th>&nbsp;</th><th>Patient Details</th><th>Payment Status</th><th>Invoice Amount(RS)</th><th>Booked Date</th><th>Pickup Date</th><th>Pickup Time</th><th>Pickup By</th><th>Order Status</th><th>Action</th><th>Files</th></tr></thead>');
                        j = 0;
                        if (c.length > 0) {
                            var img = '<i class="fa fa-check" aria-hidden="true"></i> Paid';
                            $.each(c, function (i, emp) {
                                debugger;
                                if (emp.payment_status == null || emp.payment_status == '') order_status = '-';
                                else order_status = '<span class="btn btn-submit btn-xs"><a id="btnLabPayment" class="color-white">' + img + '</a></span>';;
                                if (emp.phone_number_1 == null || emp.phone_number_1 == "") phone = "-";
                                else phone = emp.phone_number_1;
                                if (emp.pickup_by == '1') {
                                    pickup_by = 'Self';
                                    row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                                }
                                else if (emp.pickup_by == '2') {
                                    pickup_by = 'I2H';
                                    row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td><button class="blue" data-toggle="popover" data-target="#pattrackdetails" onclick=i2h_order_track("' + emp.I2H_order_id + '")>Order Track</button></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                                }
                                else if (emp.pickup_by == '3') {
                                    pickup_by = 'Cancelled By Doctor';
                                    row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                                }
                                else if (emp.pickup_by == '4') {
                                    pickup_by = 'Cancelled By I2H';
                                    row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                                }
                                else if (emp.pincode_status == '2') {
                                    pickup_by = '-';
                                    row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td><button class="delete btn btn-default  btn-sm btn-add UM_77" onclick=i2h_pickup("' + emp.I2H_order_id + '");>I2H Pickup</button> <button class="delete btn btn-default  btn-sm btn-add UM_78" onclick=i2h_cancel_order("' + emp.I2H_order_id + '");>Cancel Order</button></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                                }
                                else {
                                    pickup_by = '-';
                                    row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td><button class="edit btn btn-default  btn-sm btn-add UM_76" onclick=self_pickup("' + emp.I2H_order_id + '")>self Pickup</button><button class="delete btn btn-default  btn-sm btn-add UM_77" onclick=i2h_pickup("' + emp.I2H_order_id + '");>I2H Pickup</button> <button class="delete btn btn-default  btn-sm btn-add UM_78" onclick=i2h_cancel_order("' + emp.I2H_order_id + '");>Cancel Order</button></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                                }
                                j = j + 1;
                                tr.append(row_data);
                            });
                            $('#Jobdetails').html(tr);
                            check_priviliges();
                        }
                        else {
                            $('#Jobdetails').html(Norecord);
                        }
                    }
                    else {
                        $('#Jobdetails').html(Norecord);
                    }
                }
                else {
                    console.log(data);
                }
            }         
        }
    });
}

function order_table(data)
{
    $('#Jobdetails').empty();
    var data1 = JSON.parse(data);
    var b = data1.Table;
    var c = data1.Table1;
    $('#AdviceCount').html(b[0].total_order);
    $('#pendingorder').html(b[0].self_picup);
    $('#pendingjob').html(b[0].i2h_pickup);
    tr = $('<table class="table table-bordered table-striped dataTable" id="labJoblist" />');
    tr.append('<thead><tr><th>&nbsp;</th><th>Patient Details</th><th>Payment Status</th><th>Invoice Amount(RS)</th><th>Booked Date</th><th>Pickup Date</th><th>Pickup Time</th><th>Pickup By</th><th>Order Status</th><th>Action</th><th>Files</th></tr></thead>');
    var j = 0, order_status, phone;
    if (c.length > 0) {
        var img = '<i class="fa fa-check" aria-hidden="true"></i> Paid';
        $.each(c, function (i, emp) {
            if (emp.payment_status == null || emp.payment_status == '') order_status = '-';
            else order_status = '<span class="btn btn-submit btn-xs"><a id="btnLabPayment" class="color-white">' + img + '</a></span>';;
            if (emp.phone_number_1 == null || emp.phone_number_1 == "") phone = "-";
            else phone = emp.phone_number_1;
            if (emp.pickup_by == '1') {
                pickup_by = 'Self';
                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
            }
            else if (emp.pickup_by == '2') {
                pickup_by = 'I2H';
                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td><button class="blue" data-toggle="popover" data-target="#pattrackdetails" onclick=i2h_order_track("' + emp.I2H_order_id + '")>Order Track</button></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
            }
            else if (emp.pickup_by == '3') {
                pickup_by = 'Cancelled By Doctor';
                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
            }
            else if (emp.pickup_by == '4') {
                pickup_by = 'Cancelled By I2H';
                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
            }
            else if (emp.pincode_status == '2') {
                pickup_by = '-';
                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td><button class="delete btn btn-default  btn-sm btn-add UM_77" onclick=i2h_pickup("' + emp.I2H_order_id + '");>I2H Pickup</button> <button class="delete btn btn-default  btn-sm btn-add UM_78" onclick=i2h_cancel_order("' + emp.I2H_order_id + '");>Cancel Order</button></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
            }
            else {
                pickup_by = '-';
                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td><button class="edit btn btn-default  btn-sm btn-add UM_76" onclick=self_pickup("' + emp.I2H_order_id + '")>self Pickup</button><button class="delete btn btn-default  btn-sm btn-add UM_77" onclick=i2h_pickup("' + emp.I2H_order_id + '");>I2H Pickup</button> <button class="delete btn btn-default  btn-sm btn-add UM_78" onclick=i2h_cancel_order("' + emp.I2H_order_id + '");>Cancel Order</button></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
            }
            j = j + 1;
            tr.append(row_data);
        });
        $('#Jobdetails').html(tr);
    }
    else
    {
        $('#Jobdetails').html(Norecord);
    }
}

function orderdetails(val, val2) {
    var htmlid = val;
    var orderid = val2;
    var Template = {
        doctor_id: $('#HiddenDoctorID').val(),
        Dml_Indicator: 'TD',
        order_id: orderid
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Template/lab_home_colection',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(Template),
        success: function (data) {
            var data2 = JSON.parse(data);
            if (jQuery.isEmptyObject((data2.data))) {
            }
            else {

                if (data2.msg == "Success") {
                    var data1 = data2.data;

                    var test_type;
                    var tr = '', Action = '';
                    var b = data1.Table;
                    var add_val = "Pickup Address : " + data1.Table1[0].first_name + "," + data1.Table1[0].phone_number + "," + data1.Table1[0].patient_address + "," + data1.Table1[0].town_village + "," + data1.Table1[0].city + "," + data1.Table1[0].state + "-" + data1.Table1[0].pincode;
                    var trhead = '<td colspan="12"><div class="table-tab-title">Order Details</div><div><table class="table table-bordered table-striped dataTable"><thead><tr><th>Test ID</th><th>Type</th><th>Test Name</th><th>Amount</th><th>Date</th></tr></thead><tbody>';
                    $.each(b, function (i, emp) {
                        if (emp.test_type == "1") test_type = "Panel";
                        else test_type = "test";
                        tr = tr + '<tr><td>' + emp.test_id + '</td><td>' + test_type + '</td><td>' + emp.test_name + '</td><td>' + emp.test_price + '</td><td>' + emp.created_on + '</td></tr>'
                    });
                    var trend = '</tbody></table></div><p class="pickupaddress"> ' + add_val + '</span> </p></td>';
                    $('#' + htmlid).html(trhead + tr + trend);
                }
                else {
                    console.log(data);
                }
            }
        }
    });

}

function self_pickup(val)
{
    $('#loaderimg').show();
    var date;
    if ($('#app_date_current').html() == 'Today') {
        var d = new Date();

        var month = d.getMonth() + 1;
        var day = d.getDate();

        var output = (day < 10 ? '0' : '') + day + '/' +
            (month < 10 ? '0' : '') + month + '/' +
            d.getFullYear();
        date = output;
    }
    else
    {
        date = $('#app_date_current').html();
    }
    var dates = date.split('/');
    date = dates[2] + '-' + dates[1] + '-' + dates[0];
    var Template = {
        doctor_id: $('#HiddenDoctorID').val(),
        Dml_Indicator: 'SP',
        order_id: val,
        date: date,
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Template/lab_home_colection',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(Template),
        success: function (data) {
            var data2 = JSON.parse(data);
            var data = data2.data;
            $('#loaderimg').hide();
            order_table(data);
        }
    });
}


function i2h_pickup(val) {
    $('#loaderimg').show();
    var date;
    var date;
    if ($('#app_date_current').html() == 'Today') {
        var d = new Date();

        var month = d.getMonth() + 1;
        var day = d.getDate();

        var output = (day < 10 ? '0' : '') + day + '/' +
            (month < 10 ? '0' : '') + month + '/' +
            d.getFullYear();
        date = output;
    }
    else {
        date = $('#app_date_current').html();
    }
    var dates = date.split('/');
    date = dates[2] + '-' + dates[1] + '-' + dates[0];
    var Template = {
        doctor_id: $('#HiddenDoctorID').val(),
        Dml_Indicator: 'I2HP',
        order_id: val,
        date: date,
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Template/i2h_pickup',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(Template),
        success: function (data) {
            var data2 = JSON.parse(data);
            if (jQuery.isEmptyObject((data2.data))) {
                toastr.warning("Something went wrong, Please try again after some time");
                $('#loaderimg').hide();
            }
            else
            {
                if (data2.msg == "Success") {
                    var data1 = data2.data;

                    if (data.length > 5) {
                        var i2h_id, order_status, order_id = val;
                        if (data1.status == "200") {
                            var i2h_data = data1.data;
                            i2h_id = i2h_data.i2h_order_id;
                            order_status = i2h_data.order_status;
                            order_id = i2h_data.vendor_order_id;
                        }
                        var Template = {
                            doctor_id: $('#HiddenDoctorID').val(),
                            Dml_Indicator: 'I2HPRD',
                            message: data1.message,
                            system_time: data1.system_time,
                            i2h_id: i2h_id,
                            is_order_accepted: data1.is_order_accepted,
                            i2h_order_status: order_status,
                            status: data1.status,
                            order_id: order_id
                        }
                        $.ajax({
                            async: true,
                            type: 'POST',
                            url: '/Template/lab_home_colection',
                            contentType: 'application/json; charset=UTF-8',
                            data: JSON.stringify(Template),
                            success: function (data) {
                                $('#loaderimg').hide();
                                if (data1.is_order_accepted == true) {
                                    toastr.success("Third Party Pickup Successfully Created");
                                }
                                else {
                                    alert(data1.message);
                                }
                                location.reload();
                            }
                        });
                    }
                    else {
                        toastr.warning("Something went wrong, Please try again after some time");
                        $('#loaderimg').hide();
                    }
                }
                else {
                    console.log(data);
                }     
            }
        }
    });
}


function date_order_list() {
    $('#loaderimg').show();
    var date = $('#app_date_current').html();
    var dates = date.split('/');
    date = dates[2] + '-' + dates[1] + '-' + dates[0];
    var Template = {
        doctor_id: $('#HiddenDoctorID').val(),
        Dml_Indicator: 'DOL',
        date: date,
    }    
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Template/lab_home_colection',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(Template),
        success: function (data) {

            var data2 = JSON.parse(data);
            var data = data2.data;
            $('#loaderimg').hide();
            order_table(data);
        }
    });
}


function i2h_cancel_order(id)
{
    $('#loaderimg').show();
    var date;
    if ($('#app_date_current').html() == 'Today') {
        var d = new Date();

        var month = d.getMonth() + 1;
        var day = d.getDate();

        var output = (day < 10 ? '0' : '') + day + '/' +
            (month < 10 ? '0' : '') + month + '/' +
            d.getFullYear();
        date = output;
    }
    else {
        date = $('#app_date_current').html();
    }
    var dates = date.split('/');
    date = dates[2] + '-' + dates[1] + '-' + dates[0];
    var Template = {
        doctor_id: $('#HiddenDoctorID').val(),
        Dml_Indicator: 'CO',
        order_id: id,
        date: date,
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Template/lab_home_colection',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(Template),
        success: function (data) {
            var data2 = JSON.parse(data);
            var data = data2.data;
            $('#loaderimg').hide();
            order_table(data);
        }
    });
}

function select_option_filter(val)
{
    $('#loaderimg').show();
    var date;
    if ($('#app_date_current').html() == 'Today') {
        var d = new Date();

        var month = d.getMonth() + 1;
        var day = d.getDate();

        var output = (day < 10 ? '0' : '') + day + '/' +
            (month < 10 ? '0' : '') + month + '/' +
            d.getFullYear();
        date = output;
    }

    else if ($('#app_date_current').html() == 'Yesterday') {
        date = $('#hndyesterday').val();
    }
    else if ($('#app_date_current').html() == 'Tomorrow') {
        date = $('#hndtomorrow').val();
    }
    else {
        date = $('#app_date_current').html();

    }

    var dates = date.split('/');
    date = dates[2] + '-' + dates[1] + '-' + dates[0];
    var Template = {
        doctor_id: $('#HiddenDoctorID').val(),
        Dml_Indicator: val,
        date: date,
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Template/lab_home_colection',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(Template),
        success: function (data) {
            $('#loaderimg').hide();
            $('#Jobdetails').empty();
            var data2 = JSON.parse(data);
            var data = data2.data;
            if (jQuery.isEmptyObject((data2.data))) {
                $('#Jobdetails').html(Norecord);
            }
            else {

                if (data2.msg == "Success") {
                    var data1 = data2.data;

                    var invoiceAmt = '', invoicedue = '', j, order_status = '', phone, pickup_by;
                    var img = '<i class="fa fa-check" aria-hidden="true"></i> Paid';
                    if (data.length > 4 && data != null) {
                        var b = data1.Table;
                        tr = $('<table class="table table-bordered table-striped dataTable" id="labJoblist" />');
                        tr.append('<thead><tr><th>&nbsp;</th><th>Patient Details</th><th>Payment Status</th><th>Invoice Amount</th><th>Booked Date</th><th>Pickup Date</th><th>Pickup Time</th><th>Pickup By</th><th>Order Status</th><th>Action</th><th>Files</th></tr></thead>');
                        j = 0;
                        $.each(b, function (i, emp) {
                            if (emp.payment_status == null || emp.payment_status == '') order_status = '-';
                            else order_status = '<span class="btn btn-submit btn-xs"><a id="btnLabPayment" class="color-white">' + img + '</a></span>';;
                            if (emp.phone_number_1 == null || emp.phone_number_1 == "") phone = "-";
                            else phone = emp.phone_number_1;
                            if (emp.pickup_by == '1') {
                                pickup_by = 'Self';
                                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                            }
                            else if (emp.pickup_by == '2') {
                                pickup_by = 'I2H';
                                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                            }
                            else if (emp.pickup_by == '3') {
                                pickup_by = 'Cancelled By Doctor';
                                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                            }
                            else if (emp.pickup_by == '4') {
                                pickup_by = 'Cancelled By I2H';
                                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                            }
                            else if (emp.pincode_status == '2') {
                                pickup_by = '-';
                                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td><button class="delete btn btn-default  btn-sm btn-add UM_77" onclick=i2h_pickup("' + emp.I2H_order_id + '");>I2H Pickup</button> <button class="delete btn btn-default  btn-sm btn-add UM_78" onclick=i2h_cancel_order("' + emp.I2H_order_id + '");>Cancel Order</button></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                            }
                            else {
                                pickup_by = '-';
                                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td><button class="edit btn btn-default  btn-sm btn-add UM_76" onclick=self_pickup("' + emp.I2H_order_id + '")>self Pickup</button><button class="delete btn btn-default  btn-sm btn-add UM_77" onclick=i2h_pickup("' + emp.I2H_order_id + '");>I2H Pickup</button> <button class="delete btn btn-default  btn-sm btn-add UM_78" onclick=i2h_cancel_order("' + emp.I2H_order_id + '");>Cancel Order</button></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                            }
                            j = j + 1;
                            tr.append(row_data);
                        });
                        $('#Jobdetails').html(tr);
                        check_priviliges();
                    }
                    else {
                        $('#Jobdetails').html(Norecord);
                    }

                }
                else {
                    console.log(data);
                }
            }
        }
    });
}

$('#btnsubmit_order').click(function () {
    if ($('#Selorder_status').val() == '4')
    {
        date_filter();
    }
    else if ($('#Selorder_status').val() == '5') {
        name_filter();
    }
    else
    {
    }
});


function date_filter()
{
    if ($.trim($('#FDate').val()).length == "") {
        $('#PFDate').show();
        $('#PFDate').fadeOut(8000);
        $('#PFDate').html('Enter From Date');
        $('#FDate').focus();
        $('#FDate').val('');
        return false;
    }
    if ($.trim($('#EDate').val()).length == "") {
        $('#PEDate').show();
        $('#PEDate').fadeOut(8000);
        $('#PEDate').html('Enter To Date');
        $('#EDate').focus();
        $('#EDate').val('');
        return false;
    }
    if ($.trim($('#EDate,#FDate').val()).length > 0) {
        $('#loaderimg').show();
        var from_Date, to_date, condition;
        from_Date = $('#FDate').val();
        to_date = $('#EDate').val();
        var from_Dates = from_Date.split('/');
        from_Date = from_Dates[2] + '-' + from_Dates[1] + '-' + from_Dates[0];
        var to_dates = to_date.split('/');
        to_date = to_dates[2] + '-' + to_dates[1] + '-' + to_dates[0];
        var Template = {
            doctor_id: $('#HiddenDoctorID').val(),
            Dml_Indicator: 'DF',
            FDate: from_Date,
            EDate: to_date
        }
        $.ajax({
            async: true,
            type: 'POST',
            url: '/Template/lab_home_colection',
            contentType: 'application/json; charset=UTF-8',
            data: JSON.stringify(Template),
            success: function (data) {
                $('#EDate').val('');
                $('#FDate').val('');
                $('#loaderimg').hide();
                $('#Jobdetails').empty();
                var data2 = JSON.parse(data);
                var data = data2.data;
                if (jQuery.isEmptyObject((data2.data))) {
                    $('#Jobdetails').html(Norecord);
                }
                else {

                    if (data2.msg == "Success") {
                        var data1 = data2.data;

                        var invoiceAmt = '', invoicedue = '', j, order_status = '', phone, pickup_by;
                        var img = '<i class="fa fa-check" aria-hidden="true"></i> Paid';
                        if (data.length > 4 && data != null) {
                            var b = data1.Table;
                            tr = $('<table class="table table-bordered table-striped dataTable" id="labJoblist" />');
                            tr.append('<thead><tr><th>&nbsp;</th><th>Patient Details</th><th>Payment Status</th><th>Invoice Amount</th><th>Booked Date</th><th>Pickup Date</th><th>Pickup Time</th><th>Pickup By</th><th>Order Status</th><th>Action</th><th>Files</th></tr></thead>');
                            j = 0;
                            $.each(b, function (i, emp) {
                                if (emp.payment_status == null || emp.payment_status == '') order_status = '-';
                                else order_status = '<span class="btn btn-submit btn-xs"><a id="btnLabPayment" class="color-white">' + img + '</a></span>';;
                                if (emp.phone_number_1 == null || emp.phone_number_1 == "") phone = "-";
                                else phone = emp.phone_number_1;
                                if (emp.pickup_by == '1') {
                                    pickup_by = 'Self';
                                    row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                                }
                                else if (emp.pickup_by == '2') {
                                    pickup_by = 'I2H';
                                    row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td><button class="blue" data-toggle="popover" data-target="#pattrackdetails" onclick=i2h_order_track("' + emp.I2H_order_id + '")>Order Track</button></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                                }
                                else if (emp.pickup_by == '3') {
                                    pickup_by = 'Cancelled By Doctor';
                                    row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                                }
                                else if (emp.pickup_by == '4') {
                                    pickup_by = 'Cancelled By I2H';
                                    row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                                }
                                else if (emp.pincode_status == '2') {
                                    pickup_by = '-';
                                    row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td><button class="delete btn btn-default  btn-sm btn-add UM_77" onclick=i2h_pickup("' + emp.I2H_order_id + '");>I2H Pickup</button> <button class="delete btn btn-default  btn-sm btn-add UM_78" onclick=i2h_cancel_order("' + emp.I2H_order_id + '");>Cancel Order</button></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                                }
                                else {
                                    pickup_by = '-';
                                    row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td><button class="edit btn btn-default  btn-sm btn-add UM_76" onclick=self_pickup("' + emp.I2H_order_id + '")>self Pickup</button><button class="delete btn btn-default  btn-sm btn-add UM_77" onclick=i2h_pickup("' + emp.I2H_order_id + '");>I2H Pickup</button> <button class="delete btn btn-default  btn-sm btn-add UM_78" onclick=i2h_cancel_order("' + emp.I2H_order_id + '");>Cancel Order</button></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                                }
                                j = j + 1;
                                tr.append(row_data);
                            });
                            $('#Jobdetails').html(tr);
                            check_priviliges();
                        }
                        else {
                            $('#Jobdetails').html(Norecord);
                        }
                    }
                    else {
                        console.log(data);
                    }
                }
            }
        });
    }
    else {
    }
}
function files_lab(order_id) {
    var data = {
        order_id: order_id,
        Dml_Indicator: "FL"
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Template/lab_home_colection',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(data),
        success: function (data) {
            var data2 = JSON.parse(data);
            var data = data2.data;
            console.log(data);
            if (data.Table[0].health_concern != '' && data.Table[0].health_concern != null) {
                $('#health_concern').html(data.Table[0].health_concern);
            }
            else {
                $('#health_concern').html("    -");
            }
            $('#tblAppointmentFiles_body').empty();
            if (data.Table[0].lab_files != '' && data.Table[0].lab_files != null) {

                var files = data.Table[0].lab_files.split("&&");

                var file_tr = '', k = 1;
                for (var i = 0; i < files.length; i++) {
                    var d, n, drloimage;
                    d = new Date();
                    n = d.getTime();
                    var file = $('#hdnHomeCareFilesView').val() + "HomeCareFiles/ParvathyFiles/" + files[i] + "?" + n;
                    file_tr = file_tr + '<tr><td>' + k + '</td><td><a href = ' + file + ' target=_blank> File </a></td></tr>';

                    k = k + 1;
                }
                $('#tblAppointmentFiles_body').html(file_tr);

            }
        }
    });
}

function name_filter()
{
    if ($.trim($('#PName').val()).length == "") {
        $('#PPName').show();
        $('#PPName').fadeOut(8000);
        $('#PPName').html('Enter Name or Phone Number or Patient Id');
        $('#PName').focus();
        $('#PName').val('');
        return false;
    }
    if ($.trim($('#PName').val()).length > 0) {
        $('#loaderimg').show();
        debugger;
        var Template = {
            doctor_id: $('#HiddenDoctorID').val(),
            Dml_Indicator: 'POL',
            FDate: $('#PName').val().split('/')[2],
        }
        $.ajax({
            async: true,
            type: 'POST',
            url: '/Template/lab_home_colection',
            contentType: 'application/json; charset=UTF-8',
            data: JSON.stringify(Template),
            success: function (data) {
                $('#PName').val('');
                $('#loaderimg').hide();
                $('#Jobdetails').empty();
                var data2 = JSON.parse(data);
                var data = data2.data;
                if (jQuery.isEmptyObject((data2.data))) {
                    $('#Jobdetails').html(Norecord);
                }
                else {


                    if (data2.msg == "Success") {
                        var data1 = data2.data;

                        var invoiceAmt = '', invoicedue = '', j, order_status = '', phone, pickup_by;
                        var img = '<i class="fa fa-check" aria-hidden="true"></i> Paid';
                        if (data.length > 4 && data != null) {
                            var b = data1.Table;
                            tr = $('<table class="table table-bordered table-striped dataTable" id="labJoblist" />');
                            tr.append('<thead><tr><th>&nbsp;</th><th>Patient Details</th><th>Payment Status</th><th>Invoice Amount</th><th>Booked Date</th><th>Pickup Date</th><th>Pickup Time</th><th>Pickup By</th><th>Order Status</th><th>Action</th><th>Files</th></tr></thead>');
                            j = 0;
                            $.each(b, function (i, emp) {
                                if (emp.payment_status == null || emp.payment_status == '') order_status = '-';
                                else order_status = '<span class="btn btn-submit btn-xs"><a id="btnLabPayment" class="color-white">' + img + '</a></span>';
                                if (emp.phone_number_1 == null || emp.phone_number_1 == "") phone = "-";
                                else phone = emp.phone_number_1;
                                if (emp.pickup_by == '1') {
                                    pickup_by = 'Self';
                                    row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                                }
                                else if (emp.pickup_by == '2') {
                                    pickup_by = 'I2H';
                                    row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td><button class="blue" data-toggle="popover" data-target="#pattrackdetails" onclick=i2h_order_track("' + emp.I2H_order_id + '")>Order Track</button></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                                }
                                else if (emp.pickup_by == '3') {
                                    pickup_by = 'Cancelled By Doctor';
                                    row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                                }
                                else if (emp.pickup_by == '4') {
                                    pickup_by = 'Cancelled By I2H';
                                    row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                                }
                                else if (emp.pincode_status == '2') {
                                    pickup_by = '-';
                                    row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td><button class="delete btn btn-default  btn-sm btn-add UM_77" onclick=i2h_pickup("' + emp.I2H_order_id + '");>I2H Pickup</button> <button class="delete btn btn-default  btn-sm btn-add UM_78" onclick=i2h_cancel_order("' + emp.I2H_order_id + '");>Cancel Order</button></td><td><button onclick=files_lab("' + emp.I2H_order_id + '") title="Appointment Files " data-toggle="modal" data-target="#appointment_files">View Files</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                                }
                                else {
                                    pickup_by = '-';
                                    row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td class="align-middle">' + emp.first_name + "</span></a><br /><span class='mys-ph'>ph : " + phone + '</span>&nbsp;/&nbsp<span class="mys-id">' + emp.I2H_order_id + '</span></td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td>' + emp.order_status + '</td><td><button class="edit btn btn-default  btn-sm btn-add UM_76" onclick=self_pickup("' + emp.I2H_order_id + '")>self Pickup</button><button class="delete btn btn-default  btn-sm btn-add UM_77" onclick=i2h_pickup("' + emp.I2H_order_id + '");>I2H Pickup</button> <button class="delete btn btn-default  btn-sm btn-add UM_78" onclick=i2h_cancel_order("' + emp.I2H_order_id + '");>Cancel Order</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
                                }
                                j = j + 1;
                                tr.append(row_data);
                            });
                            $('#Jobdetails').html(tr);
                            check_priviliges();
                        }
                        else {
                            $('#Jobdetails').html(Norecord);
                        }
                    }
                    else {
                        console.log(data);
                    }

                   

                }
            }
        });
    }
    else {
    }
}


$('#PName').on('input', function () {
    $('#PName').autocomplete({
        source: function (request, response) {
            $.ajax({
                async: true,
                url: "/Template/AutoComplete_PatName?rep_list=" + $('#PName').val(),
                type: "POST",
                dataType: "json",
                data: { Prefix: request.term },
                success: function (data) {
                    response($.map(data, function (item) {
                        return { label: item.patient_name, value: item.patient_name };
                    }));

                }
            });
        }
    });
});


function i2h_order_track(id)
{
    var Template = {
        doctor_id: $('#HiddenDoctorID').val(),
        Dml_Indicator: 'I2HORP',
        order_id: id,
    }
    $.ajax({
        async: true,
        type: 'POST',
        url: '/Template/lab_home_colection',
        contentType: 'application/json; charset=UTF-8',
        data: JSON.stringify(Template),
        success: function (data) {
            var data2 = JSON.parse(data);
            if (jQuery.isEmptyObject((data2.data))) {
                $('#Jobdetails').html(Norecord);
            }
            else
            {

                if (data2.msg == "Success") {
                    var data1 = data2.data;

                    $("#trackStausChange").animate({ height: '1px' });
                    $('#pattrackdetails').modal('toggle');
                    if (data1.Table.length > 0) {
                        $('#patid_1').html(data1.Table[0].patient_id);
                        $('#patname_1').html(data1.Table[0].first_name);
                        $('#patnumber').html(data1.Table[0].phone_number);
                        $('#paage').html("Age: " + data1.Table[0].age);
                        $('#patimgphoto').html('<img class="img-responsive text-center imgphoto" src="" alt="Patient Image" width="40" onerror="changedefault(this)"/>')
                        $('#pataddres').html(data1.Table[0].patient_address + ", " + data1.Table[0].town_village + ", " + data1.Table[0].city + ", " + data1.Table[0].state + ", " + data1.Table[0].pincode);
                    }
                    if (data1.Table1.length > 0) {
                        $('#phelbo_1').html("Name : " + data1.Table1[0].agent_assigned_person_name);
                        $('#phelbo_phone').html(data1.Table1[0].agent_assigned_mobile_number);

                        $.each(data1.Table1, function (i, emp) {
                            if (emp.order_status_code == "1") {
                                $('.lh-order-details-tracking ul li:nth-child(1)').hasClass('active');
                                $('#1_time').html(emp.status_date);
                            }
                            if (emp.order_status_code == "2") {
                                $('.lh-order-details-tracking ul li:nth-child(2)').hasClass('active');
                                $("#trackStausChange").animate({ height: '47px' });
                                $('#2_time').html(emp.status_date);
                            }
                            if (emp.order_status_code == "3") {
                                $('.lh-order-details-tracking ul li:nth-child(3)').hasClass('active');
                                $("#trackStausChange").animate({ height: '87px' });
                                $('#3_time').html(emp.status_date);
                            }
                            if (emp.order_status_code == "4") {
                                $('.lh-order-details-tracking ul li:nth-child(4)').hasClass('active');
                                $("#trackStausChange").animate({ height: '127px' });
                                $('#4_time').html(emp.status_date);
                            }
                            if (emp.order_status_code == "5") {
                                $('.lh-order-details-tracking ul li:nth-child(5)').hasClass('active');
                                $("#trackStausChange").animate({ height: '167px' });
                                $('#5_time').html(emp.status_date);
                            }
                            if (emp.order_status_code == "6") {
                                $('.lh-order-details-tracking ul li:nth-child(6)').hasClass('active');
                                $("#trackStausChange").animate({ height: '207px' });
                                $('#6_time').html(emp.status_date);
                            }
                        });

                    }
                }
                else {
                    console.log(data);
                }
            }            
        }
    });
}

$('#btnProCls').click(function () {
    $('#patid_1,#patname_1,#patnumber,#paage,#phelbo_1,#phelbo_phone').html(" ");
    $("#trackStausChange").animate({ height: '1px' });
});

function changedefault(e) {
    var photoSrc = "/Content/img/profile_icon.png";
    console.log("Image Error")
    $(e).attr("src", photoSrc)
}





////MMM code started


//var Norecord = '<div class="img-center"><img src="/Content/img/no_record.png" class="img-resposive no_record_img" style="height:65px; width:72px; border-radius:0px;"><br><div class="no_data_content">No data found.</div></div>';

//$(document).ready(function () {

//    patient_lab_order();
//    //loadlab_id();


//    //$("#tbl").find("input,button,textarea,select").attr("disabled", "disabled");


//    //$("#viewTab>li").click(function () {
//    //    var hrefActive = $(this).find('a').attr("href");
//    //    ('#viewTab a[href="' + hrefActive + '"]').tab('show');
//    //});

//});

//function datefun() {
//    var d = new Date();

//    var month = d.getMonth() + 1;
//    var day = d.getDate();

//    var output = (day < 10 ? '0' : '') + day + '/' +
//        (month < 10 ? '0' : '') + month + '/' +
//        d.getFullYear();
//    $('#hndtoday').val(output);

//    //yesterday
//    var d = new Date();

//    var month = d.getMonth() + 1;
//    var day = d.getDate() - 1;

//    var output = (day < 10 ? '0' : '') + day + '/' +
//        (month < 10 ? '0' : '') + month + '/' +
//        d.getFullYear();
//    $('#hndyesterday').val(output);

//    //tomorrow

//    var d = new Date();

//    var month = d.getMonth() + 1;
//    var day = d.getDate() + 1;

//    var output = (day < 10 ? '0' : '') + day + '/' +
//        (month < 10 ? '0' : '') + month + '/' +
//        d.getFullYear();
//    $('#hndtomorrow').val(output);
//}


//function Lableftarrow() {
//    if ($('#app_date_current').html() == 'Today') {
//        var d = new Date();

//        var month = d.getMonth() + 1;
//        var day = d.getDate();

//        var output = (day < 10 ? '0' : '') + day + '/' +
//            (month < 10 ? '0' : '') + month + '/' +
//            d.getFullYear();
//        $('#app_date_current').html(output);
//    }
//    else if ($('#app_date_current').html() == 'Yesterday') {
//        var d = new Date();

//        var month = d.getMonth() + 1;
//        var day = d.getDate() - 1;

//        var output = (day < 10 ? '0' : '') + day + '/' +
//            (month < 10 ? '0' : '') + month + '/' +
//            d.getFullYear();
//        $('#app_date_current').html(output);
//    }
//    else if ($('#app_date_current').html() == 'Tomorrow') {
//        var d = new Date();

//        var month = d.getMonth() + 1;
//        var day = d.getDate() + 1;

//        var output = (day < 10 ? '0' : '') + day + '/' +
//            (month < 10 ? '0' : '') + month + '/' +
//            d.getFullYear();
//        $('#app_date_current').html(output);
//    }


//    var displaydate = $('#app_date_current').html();
//    var date = '';
//    var month = '';
//    var displaydates = displaydate.split("/");
//    displaydate = displaydates[1];
//    if (displaydate == '01' || displaydate == '03' || displaydate == '05' || displaydate == '07' || displaydate == '08' || displaydate == '10' || displaydate == '12') {
//        if (displaydates[0] > 1) {
//            date = displaydates[0] - 1;
//            if (date < 10) {
//                date = '0' + date;
//            }
//            date = date + '/' + displaydates[1] + '/' + displaydates[2];
//            $('#app_date_current').html(date);
//        }
//        else {
//            if (displaydate == '12') {
//                date = parseInt(displaydates[1]) + parseInt(1);
//                date = '30' + '/' + '11' + '/' + displaydates[2];
//                $('#app_date_current').html(date);
//            }
//            else if (displaydate == '01') {
//                date = parseInt(displaydates[1]) + parseInt(1);
//                var year = (displaydates[2]) - (1);
//                date = '31' + '/' + '12' + '/' + year;
//                $('#app_date_current').html(date);
//            }
//            else if (displaydate == '03') {
//                date = parseInt(displaydates[1]) + parseInt(1);
//                date = '28' + '/' + '02' + '/' + displaydates[2];
//                $('#app_date_current').html(date);
//            }
//            else {
//                date = displaydates[1] - 1;
//                if (date < 10) {
//                    date = '0' + date;
//                }
//                date = '30' + '/' + date + '/' + displaydates[2];
//                $('#app_date_current').html(date);
//            }
//        }

//    }
//    else if (displaydate == '04' || displaydate == '06' || displaydate == '09' || displaydate == '11') {
//        if (displaydates[0] > 1) {
//            date = displaydates[0] - 1;
//            if (date < 10) {
//                date = '0' + date;
//            }
//            date = date + '/' + displaydates[1] + '/' + displaydates[2];
//            $('#app_date_current').html(date);
//        }
//        else {
//            date = displaydates[1] - 1;
//            if (date < 10) {
//                date = '0' + date;
//            }
//            date = '31' + '/' + date + '/' + displaydates[2];
//            $('#app_date_current').html(date);
//        }
//    }
//    else {
//        if (displaydates[0] > 1) {
//            date = displaydates[0] - 1;
//            if (date < 10) {
//                date = '0' + date;
//            }
//            date = date + '/' + displaydates[1] + '/' + displaydates[2];
//            $('#app_date_current').html(date);
//        }
//        else {
//            date = displaydates[1] - 1;
//            if (date < 10) {
//                date = '0' + date;
//            }
//            date = '31' + '/' + '01' + '/' + displaydates[2];
//            $('#app_date_current').html(date);
//        }
//    }
//    if (date == $('#hndtoday').val()) {
//        $('#app_date_current').html('Today');
//    }
//    if (date == $('#hndyesterday').val()) {
//        $('#app_date_current').html('Yesterday');
//    }
//    if (date == $('#hndtomorrow').val()) {
//        $('#app_date_current').html('Tomorrow');
//    }
//    date_order_list();
//}


//function Labrightarrow() {
//    if ($('#app_date_current').html() == 'Today') {

//        var d = new Date();

//        var month = d.getMonth() + 1;
//        var day = d.getDate();

//        var output = (day < 10 ? '0' : '') + day + '/' +
//            (month < 10 ? '0' : '') + month + '/' +
//            d.getFullYear();
//        $('#app_date_current').html(output);
//        $('#app_date_current1').html(output);
//        $('#app_date_current2').html(output);
//        $('#app_date_current3').html(output);
//    }


//    else if ($('#app_date_current').html() == 'Yesterday') {
//        var d = new Date();

//        var month = d.getMonth() + 1;
//        var day = d.getDate() - 1;

//        var output = (day < 10 ? '0' : '') + day + '/' +
//            (month < 10 ? '0' : '') + month + '/' +
//            d.getFullYear();
//        $('#app_date_current').html(output);
//    }
//    else if ($('#app_date_current').html() == 'Tomorrow') {
//        var d = new Date();

//        var month = d.getMonth() + 1;
//        var day = d.getDate() + 1;

//        var output = (day < 10 ? '0' : '') + day + '/' +
//            (month < 10 ? '0' : '') + month + '/' +
//            d.getFullYear();
//        $('#app_date_current').html(output);
//    }
//    var displaydate = $('#app_date_current').html();
//    var date = '';
//    var month = '';
//    var displaydates = displaydate.split("/");
//    displaydate = displaydates[1];
//    if (displaydate == '01' || displaydate == '03' || displaydate == '05' || displaydate == '07' || displaydate == '08' || displaydate == '10' || displaydate == '12') {
//        if (displaydates[0] < 31) {
//            date = parseInt(displaydates[0]) + parseInt(1);
//            if (date < 10) {
//                date = '0' + date;
//            }
//            date = date + '/' + displaydates[1] + '/' + displaydates[2];
//            $('#app_date_current').html(date);
//        }
//        else {
//            if (displaydate == '12') {
//                date = parseInt(displaydates[1]) + parseInt(1);
//                year = parseInt(displaydates[2]) + parseInt(1);
//                date = '01' + '/' + '01' + '/' + year;
//                $('#app_date_current').html(date);
//            }
//            else {
//                date = parseInt(displaydates[1]) + parseInt(1);
//                if (date < 10) {
//                    date = '0' + date;
//                }
//                date = '01' + '/' + date + '/' + displaydates[2];
//                $('#app_date_current').html(date);
//            }
//        }
//    }
//    else if (displaydate == '04' || displaydate == '06' || displaydate == '09' || displaydate == '11') {
//        if (displaydates[0] < 30) {
//            date = parseInt(displaydates[0]) + parseInt(1);
//            if (date < 10) {
//                date = '0' + date;
//            }
//            date = date + '/' + displaydates[1] + '/' + displaydates[2];
//            $('#app_date_current').html(date);
//        }
//        else {
//            date = parseInt(displaydates[1]) + parseInt(1);
//            if (date < 10) {
//                date = '0' + date;
//            }
//            date = '01' + '/' + date + '/' + displaydates[2];
//            $('#app_date_current').html(date);
//        }
//    }
//    else {
//        if (displaydates[0] < 28) {
//            date = parseInt(displaydates[0]) + parseInt(1);
//            if (date < 10) {
//                date = '0' + date;
//            }
//            date = date + '/' + displaydates[1] + '/' + displaydates[2];
//            $('#app_date_current').html(date);
//        }
//        else {
//            date = parseInt(displaydates[1]) + parseInt(1);
//            if (date < 10) {
//                date = '0' + date;
//            }
//            date = '01' + '/' + date + '/' + displaydates[2];
//            $('#app_date_current').html(date);
//        }
//    }
//    if ($('#app_date_current').html() == $('#hndtoday').val()) {
//        $('#app_date_current').html('Today');
//    }
//    if ($('#app_date_current').html() == $('#hndyesterday').val()) {
//        $('#app_date_current').html('Yesterday');
//    }
//    if ($('#app_date_current').html() == $('#hndtomorrow').val()) {
//        $('#app_date_current').html('Tomorrow');
//    }
//    date_order_list();
//}

//$('#datepicker1').change(function () {
//    var date = $('#datepicker1').val();
//    $('#app_date_current').html(date);
//    date_order_list()
//});


//$('#Selorder_status').change(function () {
//    if ($('#Selorder_status').val() == '0') {
//        patient_lab_order();
//    }
//    else if ($('#Selorder_status').val() == '1') {
//        select_option_filter('AOL');
//    }
//    else if ($('#Selorder_status').val() == '2') {
//        select_option_filter('COL');
//    }
//    else if ($('#Selorder_status').val() == '3') {
//        select_option_filter('CCOL');
//    }
//    else if ($('#Selorder_status').val() == 4) {
//        $('#datefilter').show();
//        $('#patientName_filter').hide();
//        $('#btnsubmit_order').show();
//        return false;
//    }
//    else if ($('#Selorder_status').val() == 5) {
//        $('#datefilter').hide();
//        $('#patientName_filter').show();
//        $('#btnsubmit_order').show();
//        return false;
//    }
//    else {
//        $('#datefilter').hide();
//        $('#patientName_filter').hide();
//        $('#btnsubmit_order').hide();
//    }
//});


//$('#btncloseX').click(function () {
//    clear();
//});

//$('#btnclose').click(function () {
//    clear();
//});


//function patient_lab_order() {
//    var date;
//    if ($('#app_date_current').html() == 'Today') {
//        var d = new Date();

//        var month = d.getMonth() + 1;
//        var day = d.getDate();

//        var output = (day < 10 ? '0' : '') + day + '/' +
//            (month < 10 ? '0' : '') + month + '/' +
//            d.getFullYear();
//        date = output;
//    }

//    else if ($('#app_date_current').html() == 'Yesterday') {
//        date = $('#hndyesterday').val();
//    }
//    else if ($('#app_date_current').html() == 'Tomorrow') {
//        date = $('#hndtomorrow').val();
//    }
//    else {
//        date = $('#app_date_current').html();

//    }

//    var dates = date.split('/');
//    date = dates[2] + '-' + dates[1] + '-' + dates[0];
//    var Template = {
//        date: date,
//        doctor_id: $('#HiddenDoctorID').val(),
//        Dml_Indicator: "OL"
//    }
//    $.ajax({
//        async: true,
//        type: 'POST',
//        url: '/Template/lab_home_colection',
//        contentType: 'application/json; charset=UTF-8',
//        data: JSON.stringify(Template),
//        success: function (data) {
//            $('.testcount').hide();
//            $('#Jobdetails').empty();
//            if (jQuery.isEmptyObject((data))) {
//                $('#Jobdetails').html(Norecord);
//            }
//            else {
//                var invoiceAmt = '', invoicedue = '', j, order_status = '', pickup_by, test_type, phone;
//                var data1 = JSON.parse(data);
//                if (data.length > 4 && data != null) {
//                    var b = data1.Table;
//                    var c = data1.Table1;
//                    $('#AdviceCount').html(b[0].total_order);
//                    $('#pendingorder').html(b[0].self_picup);
//                    $('#pendingjob').html(b[0].i2h_pickup);
//                    tr = $('<table class="table-responsive table table-condensed body-borderless table_borderless" id="labJoblist" />');
//                    tr.append('<thead><tr><th>&nbsp;</th><th>Order No</th><th>Name</th><th>Mobile No</th><th>Invoice Amount</th><th>Status</th><th>Booked Date</th><th>Pickup Date/Time</th><th>Pickup By</th><th>Order Status</th><th>Action</th></tr></thead>');
//                    j = 0;
//                    var phlebo_status;
//                    if (c.length > 0) {
//                        $.each(c, function (i, emp) {
//                            if (emp.payment_status == null || emp.payment_status == '') order_status = '-';
//                            else order_status = emp.payment_status;
//                            if (emp.phone_number_1 == null || emp.phone_number_1 == "") phone = "-";
//                            else phone = emp.phone_number_1;
//                            if (emp.order_status == '1') phlebo_status = 'To Assign';
//                            else if (emp.order_status == '2') phlebo_status = "Assigned";
//                            else if (emp.order_status == '3') phlebo_status = "Accepted";
//                            else if (emp.order_status == '4') phlebo_status = "Phlebo Navigating to Customer’s place";
//                            else if (emp.order_status == '5') phlebo_status = "Phlebo Reached Customer’s Place";
//                            else if (emp.order_status == '6') phlebo_status = "Phlebo Collected the Samples";
//                            else if (emp.order_status == '7') phlebo_status = "Phlebo has taken signature of the customer";
//                            else if (emp.order_status == '8') phlebo_status = "Phlebo Departed to hand-off the samples at Laboratory";
//                            else if (emp.order_status == '10') phlebo_status = "Order Rejected By Phlebo";
//                            else phlebo_status = "-";

//                            if (emp.pickup_by == '1') {
//                                pickup_by = 'Self';
//                                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + emp.total_cost + '</td><td>' + order_status + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + ' ' + emp.slot_time + ' </td><td>' + pickup_by + '</td><td>' + phlebo_status + '</td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//                            }
//                            else if (emp.pickup_by == '2') {
//                                pickup_by = 'I2H';
//                                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//                            }
//                            else {
//                                pickup_by = '-';
//                                //row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td><button class="edit btn btn-default  btn-sm btn-add" onclick=self_pickup("' + emp.I2H_order_id + '")>self Pickup</button><button class="delete btn btn-default  btn-sm btn-add" onclick=i2h_pickup("' + emp.I2H_order_id + '");>Third Party Pickup</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//                                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + emp.total_cost + '</td><td>' + order_status + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + ' ' + emp.slot_time + ' </td><td>' + pickup_by + '</td><td>' + phlebo_status + '</td><td><button class="edit btn btn-default  btn-sm btn-add" onclick=self_pickup("' + emp.I2H_order_id + '")>self Pickup</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//                            }
//                            j = j + 1;
//                            tr.append(row_data);
//                        });
//                        $('#Jobdetails').html(tr);
//                    }
//                    else {
//                        $('#Jobdetails').html(Norecord);
//                    }
//                }
//                else {
//                    $('#Jobdetails').html(Norecord);
//                }

//            }
//        }
//    });
//}

//function order_table(data) {
//    $('#Jobdetails').empty();
//    var data1 = JSON.parse(data);
//    var b = data1.Table;
//    var c = data1.Table1;
//    $('#AdviceCount').html(b[0].total_order);
//    $('#pendingorder').html(b[0].self_picup);
//    $('#pendingjob').html(b[0].i2h_pickup);
//    tr = $('<table class="table-responsive table table-condensed body-borderless table_borderless" id="labJoblist" />');
//    tr.append('<thead><tr><th>&nbsp;</th><th>Order No</th><th>Name</th><th>Mobile No</th><th>Invoice Amount</th><th>Status</th><th>Booked Date</th><th>Pickup Date/Time</th><th>Pickup By</th><th>Order Status</th><th>Action</th></tr></thead>');
//    var j = 0, order_status, phone, phlebo_status;;
//    if (c.length > 0) {
//        $.each(c, function (i, emp) {
//            if (emp.payment_status == null || emp.payment_status == '') order_status = '-';
//            else order_status = emp.payment_status;
//            if (emp.phone_number_1 == null || emp.phone_number_1 == "") phone = "-";
//            else phone = emp.phone_number_1;
//            if (emp.order_status == '1') phlebo_status = 'To Assign';
//            else if (emp.order_status == '2') phlebo_status = "Assigned";
//            else if (emp.order_status == '3') phlebo_status = "Accepted";
//            else if (emp.order_status == '4') phlebo_status = "Phlebo Navigating to Customer’s place ";
//            else if (emp.order_status == '5') phlebo_status = "Phlebo Reached Customer’s Place";
//            else if (emp.order_status == '6') phlebo_status = "Phlebo Collected the Samples";
//            else if (emp.order_status == '7') phlebo_status = "Phlebo has taken signature of the customer";
//            else if (emp.order_status == '8') phlebo_status = "Phlebo Departed to hand-off the samples at Laboratory";
//            else if (emp.order_status == '10') phlebo_status = "Order Rejected By Phlebo";
//            else phlebo_status = "-";
//            if (emp.pickup_by == '1') {
//                pickup_by = 'Self';
//                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + emp.total_cost + '</td><td>' + order_status + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + ' ' + emp.slot_time + ' </td><td>' + pickup_by + '</td><td>' + phlebo_status + '</td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//            }
//            else if (emp.pickup_by == '2') {
//                pickup_by = 'I2H';
//                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//            }
//            else {
//                pickup_by = '-';
//                //row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td><button class="edit btn btn-default  btn-sm btn-add" onclick=self_pickup("' + emp.I2H_order_id + '")>self Pickup</button><button class="delete btn btn-default  btn-sm btn-add" onclick=i2h_pickup("' + emp.I2H_order_id + '");>Third Party Pickup</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + emp.total_cost + '</td><td>' + order_status + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + ' ' + emp.slot_time + ' </td><td>' + pickup_by + '</td><td>' + phlebo_status + '</td><td><button class="edit btn btn-default  btn-sm btn-add" onclick=self_pickup("' + emp.I2H_order_id + '")>self Pickup</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//            }
//            j = j + 1;
//            tr.append(row_data);
//        });
//        $('#Jobdetails').html(tr);
//    }
//    else {
//        $('#Jobdetails').html(Norecord);
//    }
//}

//function orderdetails(val, val2) {
//    var htmlid = val;
//    var orderid = val2;
//    var Template = {
//        doctor_id: $('#HiddenDoctorID').val(),
//        Dml_Indicator: 'TD',
//        order_id: orderid
//    }
//    $.ajax({
//        async: true,
//        type: 'POST',
//        url: '/Template/lab_home_colection',
//        contentType: 'application/json; charset=UTF-8',
//        data: JSON.stringify(Template),
//        success: function (data) {
//            if (jQuery.isEmptyObject((data))) {

//            }
//            else {
//                var test_type;
//                var data1 = JSON.parse(data);
//                var trhead = '<td colspan="12"><div><table class="table table-condensed body-borderless table_borderless"><thead><tr><th>Test ID</th><th>Type</th><th>Test Name</th><th>Amount</th><th>Date</th></tr></thead><tbody>';
//                var tr = '', Action = '';
//                var b = data1.Table;
//                $.each(b, function (i, emp) {
//                    if (emp.test_type == "1") test_type = "Panel";
//                    else test_type = "test";
//                    tr = tr + '<tr><td>' + emp.test_id + '</td><td>' + test_type + '</td><td>' + emp.test_name + '</td><td>' + emp.test_price + '</td><td>' + emp.created_on + '</td></tr>'
//                });
//                var trend = '</tbody></table></div></td>';
//                $('#' + htmlid).html(trhead + tr + trend);
//            }
//        }
//    });

//}


//function self_pickup(val)
//{
//    $('#tblPatientAppiontment').empty();
//    $('#laborderid').val(val);
//    var Template = {
//        doctor_id: $('#HiddenDoctorID').val(),
//        Dml_Indicator: 'PHEU'
//    }
//    $.ajax({
//        async: true,
//        type: 'POST',
//        url: '/Template/lab_home_colection',
//        contentType: 'application/json; charset=UTF-8',
//        data: JSON.stringify(Template),
//        success: function (data) {
//            if (jQuery.isEmptyObject((data))) {
//                alert("No phlebo for your lab please create phlebo users");
//            }
//            else {
//                debugger;
//                var data1, b, SelRole, default_opt;
//                data1 = JSON.parse(data);
//                b = data1.Table;
//                if (b.length > 0)
//                {
//                    $('#Selphleboname').empty();
//                    SelRole = "";
//                    default_opt = '<option value="0">--Select--</option>';
//                    $.each(b, function (i, emp) {
//                        SelRole = SelRole + '<option value="' + emp.phlebo_id + '">' + emp.phlebo_name + '</option>';
//                    });
//                    $('#Selphleboname').append(default_opt + SelRole);
//                    $('#assignphelbo').modal('toggle');
//                }
//                else
//                {
//                    alert("No phlebo for your lab please create phlebo users");
//                }
//            }
//        }
//    });
//}


//$('#PHDate').change(function () {
//    if ($('#Selphleboname').val() == "0" || $('#Selphleboname').val() == "") {
//        $('#PSelphleboname').show();
//        $('#PSelphleboname').fadeOut(8000);
//        $('#PSelphleboname').html('Select Phlebo');
//        $('#Selphleboname').focus();
//        return false;
//    }
//    if ($('#PHDate').val() == "0" || $('#PHDate').val() == "") {
//        $('#PPHDate').show();
//        $('#PPHDate').fadeOut(8000);
//        $('#PPHDate').html('Select Date');
//        $('#PHDate').focus();
//        return false;
//    }      
//    else {
//        var date = $('#PHDate').val();
//        date = date.split('/');
//        date = date[2] + '-' + date[1] + '-' + date[0];
//        var Template = {
//            doctor_id: $('#HiddenDoctorID').val(),
//            Dml_Indicator: 'PHLESLO',
//            phlebo_id: $('#Selphleboname').val(),
//            ph_date: date,
//        }
//        $.ajax({
//            async: true,
//            type: 'POST',
//            url: '/Template/lab_home_colection',
//            contentType: 'application/json; charset=UTF-8',
//            data: JSON.stringify(Template),
//            success: function (data) {
//                $('#tblPatientAppiontment').empty();
//                if (jQuery.isEmptyObject((data))) {
//                    var values = '<div class="NA" style="text-align:center;"><h1 style="text-align:center;">No Slot Avaliable</h1><br/></div>';
//                    $('#tblPatientAppiontment').append(values);
//                }
//                else {
//                    var data1, b, SelRole, default_opt, PhlebotAppiontment = '';
//                    data1 = JSON.parse(data);
//                    if (data.length > 4)
//                    {
//                        b = data1.Table;
//                        if (b.length > 0) {
//                            $('#tblPatientAppiontment').empty();
//                            $.each(b, function (i, emp) {
//                                PhlebotAppiontment = PhlebotAppiontment + '<div class="col-xs-6 col-sm-4 col-md-2"><button type="button" class="btn btn-primary btn-xs" id=' + emp.slot_id + ' onclick="insert_phlebo_order(' + emp.slot_id + ')"><i class="fa fa-clock-o" aria-hidden="true"> ' + emp.slot_time + '</i></button></div>';
//                            });
//                            $('#tblPatientAppiontment').append(PhlebotAppiontment);
//                        }
//                        else {
//                            var values = '<div class="NA" style="text-align:center;"><h1 style="text-align:center;">No Slot Avaliable</h1><br/></div>';
//                            $('#tblPatientAppiontment').append(values);
//                        }
//                    }
//                    else {
//                        var values = '<div class="NA" style="text-align:center;"><h1 style="text-align:center;">No Slot Avaliable</h1><br/></div>';
//                        $('#tblPatientAppiontment').append(values);
//                    }
//                }
//            }
//        });
//    }
//});

//function insert_phlebo_order(id)
//{
//    var date = $('#PHDate').val();
//    date = date.split('/');
//    date = date[2] + '-' + date[1] + '-' + date[0];
//    var Template = {
//        doctor_id: $('#HiddenDoctorID').val(),
//        Dml_Indicator: 'SPPHEL',
//        phlebo_id: $('#Selphleboname').val(),
//        ph_date: date,
//        slot_id: id,
//        order_id: $('#laborderid').val()
//    }
//    $.ajax({
//        async: true,
//        type: 'POST',
//        url: '/Template/lab_home_colection',
//        contentType: 'application/json; charset=UTF-8',
//        data: JSON.stringify(Template),
//        success: function (data) {
//            location.reload();
//        }
//    });
//}

//function self_pickup_after_assign_phlebo(val) {
//    $('.testcount').show();
//    var date;
//    if ($('#app_date_current').html() == 'Today') {
//        var d = new Date();

//        var month = d.getMonth() + 1;
//        var day = d.getDate();

//        var output = (day < 10 ? '0' : '') + day + '/' +
//            (month < 10 ? '0' : '') + month + '/' +
//            d.getFullYear();
//        date = output;
//    }
//    else {
//        date = $('#app_date_current').html();
//    }
//    var dates = date.split('/');
//    date = dates[2] + '-' + dates[1] + '-' + dates[0];
//    var Template = {
//        doctor_id: $('#HiddenDoctorID').val(),
//        Dml_Indicator: 'SP',
//        order_id: val,
//        date: date,
//    }
//    $.ajax({
//        async: true,
//        type: 'POST',
//        url: '/Template/lab_home_colection',
//        contentType: 'application/json; charset=UTF-8',
//        data: JSON.stringify(Template),
//        success: function (data) {
//            $('.testcount').hide();
//            order_table(data);
//        }
//    });
//}


//function i2h_pickup(val) {
//    $('.testcount').show();
//    var date;
//    var date;
//    if ($('#app_date_current').html() == 'Today') {
//        var d = new Date();

//        var month = d.getMonth() + 1;
//        var day = d.getDate();

//        var output = (day < 10 ? '0' : '') + day + '/' +
//            (month < 10 ? '0' : '') + month + '/' +
//            d.getFullYear();
//        date = output;
//    }
//    else {
//        date = $('#app_date_current').html();
//    }
//    var dates = date.split('/');
//    date = dates[2] + '-' + dates[1] + '-' + dates[0];
//    var Template = {
//        doctor_id: $('#HiddenDoctorID').val(),
//        Dml_Indicator: 'I2HP',
//        order_id: val,
//        date: date,
//    }
//    $.ajax({
//        async: true,
//        type: 'POST',
//        url: '/Template/lab_home_colection',
//        contentType: 'application/json; charset=UTF-8',
//        data: JSON.stringify(Template),
//        success: function (data) {
//            $('.testcount').hide();
//            order_table(data);
//        }
//    });
//}


//function date_order_list() {
//    $('.testcount').show();
//    var date = $('#app_date_current').html();
//    var dates = date.split('/');
//    date = dates[2] + '-' + dates[1] + '-' + dates[0];
//    var Template = {
//        doctor_id: $('#HiddenDoctorID').val(),
//        Dml_Indicator: 'DOL',
//        date: date,
//    }
//    $.ajax({
//        async: true,
//        type: 'POST',
//        url: '/Template/lab_home_colection',
//        contentType: 'application/json; charset=UTF-8',
//        data: JSON.stringify(Template),
//        success: function (data) {
//            $('.testcount').hide();
//            $('#Jobdetails').empty();
//            if (jQuery.isEmptyObject((data))) {
//                $('#Jobdetails').html(Norecord);
//            }
//            else {
//                debugger;
//                var invoiceAmt = '', invoicedue = '', j, order_status = '', pickup_by, phone;
//                var data1 = JSON.parse(data);
//                if (data.length > 4 && data != null) {
//                    var b = data1.Table;
//                    tr = $('<table class="table-responsive table table-condensed body-borderless table_borderless" id="labJoblist" />');
//                    tr.append('<thead><tr><th>&nbsp;</th><th>Order No</th><th>Name</th><th>Mobile No</th><th>Status</th><th>Invoice Amount</th><th>Booked Date</th><th>Pickup Date</th><th>Pickup Time</th><th>Pickup By</th><th>Action</th></tr></thead>');
//                    j = 0;
//                    $.each(b, function (i, emp) {
//                        if (emp.payment_status == null || emp.payment_status == '') order_status = '-';
//                        else order_status = emp.payment_status;
//                        if (emp.phone_number_1 == null || emp.phone_number_1 == "") phone = "-";
//                        else phone = emp.phone_number_1;
//                        if (emp.pickup_by == '1') {
//                            pickup_by = 'Self';
//                            row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//                        }
//                        else if (emp.pickup_by == '2') {
//                            pickup_by = 'I2H';
//                            row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//                        }
//                        else {
//                            pickup_by = '-';
//                            //row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td><button class="edit btn btn-default  btn-sm btn-add" onclick=self_pickup("' + emp.I2H_order_id + '")>self Pickup</button><button class="delete btn btn-default  btn-sm btn-add" onclick=i2h_pickup("' + emp.I2H_order_id + '");>Third Party Pickup</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//                            row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td><button class="edit btn btn-default  btn-sm btn-add" onclick=self_pickup("' + emp.I2H_order_id + '")>self Pickup</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//                        }
//                        j = j + 1;
//                        tr.append(row_data);
//                    });
//                    $('#Jobdetails').html(tr);
//                }
//                else {
//                    $('#Jobdetails').html(Norecord);
//                }

//            }
//        }
//    });
//}

//function select_option_filter(val) {
//    $('.testcount').show();
//    var date;
//    if ($('#app_date_current').html() == 'Today') {
//        var d = new Date();

//        var month = d.getMonth() + 1;
//        var day = d.getDate();

//        var output = (day < 10 ? '0' : '') + day + '/' +
//            (month < 10 ? '0' : '') + month + '/' +
//            d.getFullYear();
//        date = output;
//    }

//    else if ($('#app_date_current').html() == 'Yesterday') {
//        date = $('#hndyesterday').val();
//    }
//    else if ($('#app_date_current').html() == 'Tomorrow') {
//        date = $('#hndtomorrow').val();
//    }
//    else {
//        date = $('#app_date_current').html();

//    }

//    var dates = date.split('/');
//    date = dates[2] + '-' + dates[1] + '-' + dates[0];
//    var Template = {
//        doctor_id: $('#HiddenDoctorID').val(),
//        Dml_Indicator: val,
//        date: date,
//    }
//    $.ajax({
//        async: true,
//        type: 'POST',
//        url: '/Template/lab_home_colection',
//        contentType: 'application/json; charset=UTF-8',
//        data: JSON.stringify(Template),
//        success: function (data) {
//            $('.testcount').hide();
//            $('#Jobdetails').empty();
//            if (jQuery.isEmptyObject((data))) {
//                $('#Jobdetails').html(Norecord);
//            }
//            else {
//                var invoiceAmt = '', invoicedue = '', j, order_status = '', phone, pickup_by;
//                var data1 = JSON.parse(data);
//                if (data.length > 4 && data != null) {
//                    var b = data1.Table;
//                    tr = $('<table class="table-responsive table table-condensed body-borderless table_borderless" id="labJoblist" />');
//                    tr.append('<thead><tr><th>&nbsp;</th><th>Order No</th><th>Name</th><th>Mobile No</th><th>Invoice Amount</th><th>Status</th><th>Booked Date</th><th>Pickup Date/Time</th><th>Pickup By</th><th>Order Status</th><th>Action</th></tr></thead>');
//                    j = 0;
//                    var phlebo_status;
//                    $.each(b, function (i, emp) {
//                        if (emp.payment_status == null || emp.payment_status == '') order_status = '-';
//                        else order_status = emp.payment_status;
//                        if (emp.phone_number_1 == null || emp.phone_number_1 == "") phone = "-";
//                        else phone = emp.phone_number_1;
//                        if (emp.order_status == '1') phlebo_status = 'To Assign';
//                        else if (emp.order_status == '2') phlebo_status = "Assigned";
//                        else if (emp.order_status == '3') phlebo_status = "Accepted";
//                        else if (emp.order_status == '4') phlebo_status = "Phlebo Navigating to Customer’s place";
//                        else if (emp.order_status == '5') phlebo_status = "Phlebo Reached Customer’s Place";
//                        else if (emp.order_status == '6') phlebo_status = "Phlebo Collected the Samples";
//                        else if (emp.order_status == '7') phlebo_status = "Phlebo has taken signature of the customer";
//                        else if (emp.order_status == '8') phlebo_status = "Phlebo Departed to hand-off the samples at Laboratory";
//                        else if (emp.order_status == '10') phlebo_status = "Order Rejected By Phlebo";
//                        else phlebo_status = "-";
//                        if (emp.pickup_by == '1') {
//                            pickup_by = 'Self';
//                            row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + emp.total_cost + '</td><td>' + order_status + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + ' ' + emp.slot_time + ' </td><td>' + pickup_by + '</td><td>' + phlebo_status + '</td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//                        }
//                        else if (emp.pickup_by == '2') {
//                            pickup_by = 'I2H';
//                            row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//                        }
//                        else {
//                            pickup_by = '-';
//                            //row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td><button class="edit btn btn-default  btn-sm btn-add" onclick=self_pickup("' + emp.I2H_order_id + '")>self Pickup</button><button class="delete btn btn-default  btn-sm btn-add" onclick=i2h_pickup("' + emp.I2H_order_id + '");>Third Party Pickup</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//                            row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + emp.total_cost + '</td><td>' + order_status + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + ' ' + emp.slot_time + ' </td><td>' + pickup_by + '</td><td>' + phlebo_status + '</td><td><button class="edit btn btn-default  btn-sm btn-add" onclick=self_pickup("' + emp.I2H_order_id + '")>self Pickup</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//                        }
//                        j = j + 1;
//                        tr.append(row_data);
//                    });
//                    $('#Jobdetails').html(tr);
//                }
//                else {
//                    $('#Jobdetails').html(Norecord);
//                }
//            }
//        }
//    });
//}

//$('#btnsubmit_order').click(function () {
//    if ($('#Selorder_status').val() == '4') {
//        date_filter();
//    }
//    else if ($('#Selorder_status').val() == '5') {
//        name_filter();
//    }
//    else {
//    }
//});


//function date_filter() {
//    if ($.trim($('#FDate').val()).length == "") {
//        $('#PFDate').show();
//        $('#PFDate').fadeOut(8000);
//        $('#PFDate').html('Enter From Date');
//        $('#FDate').focus();
//        $('#FDate').val('');
//        return false;
//    }
//    if ($.trim($('#EDate').val()).length == "") {
//        $('#PEDate').show();
//        $('#PEDate').fadeOut(8000);
//        $('#PEDate').html('Enter To Date');
//        $('#EDate').focus();
//        $('#EDate').val('');
//        return false;
//    }
//    if ($.trim($('#EDate,#FDate').val()).length > 0) {
//        $('.testcount').show();
//        var from_Date, to_date, condition;
//        from_Date = $('#FDate').val();
//        to_date = $('#EDate').val();
//        var from_Dates = from_Date.split('/');
//        from_Date = from_Dates[2] + '-' + from_Dates[1] + '-' + from_Dates[0];
//        var to_dates = to_date.split('/');
//        to_date = to_dates[2] + '-' + to_dates[1] + '-' + to_dates[0];
//        var Template = {
//            doctor_id: $('#HiddenDoctorID').val(),
//            Dml_Indicator: 'DF',
//            FDate: from_Date,
//            EDate: to_date
//        }
//        $.ajax({
//            async: true,
//            type: 'POST',
//            url: '/Template/lab_home_colection',
//            contentType: 'application/json; charset=UTF-8',
//            data: JSON.stringify(Template),
//            success: function (data) {
//                $('#EDate').val('');
//                $('#FDate').val('');
//                $('.testcount').hide();
//                $('#Jobdetails').empty();
//                if (jQuery.isEmptyObject((data))) {
//                    $('#Jobdetails').html(Norecord);
//                }
//                else {
//                    debugger;
//                    var invoiceAmt = '', invoicedue = '', j, order_status = '', phone, pickup_by;
//                    var data1 = JSON.parse(data);
//                    if (data.length > 4 && data != null) {
//                        var b = data1.Table;
//                        tr = $('<table class="table-responsive table table-condensed body-borderless table_borderless" id="labJoblist" />');
//                        tr.append('<thead><tr><th>&nbsp;</th><th>Order No</th><th>Name</th><th>Mobile No</th><th>Status</th><th>Invoice Amount</th><th>Booked Date</th><th>Pickup Date</th><th>Pickup Time</th><th>Pickup By</th><th>Action</th></tr></thead>');
//                        j = 0;
//                        $.each(b, function (i, emp) {
//                            if (emp.payment_status == null || emp.payment_status == '') order_status = '-';
//                            else order_status = emp.payment_status;
//                            if (emp.phone_number_1 == null || emp.phone_number_1 == "") phone = "-";
//                            else phone = emp.phone_number_1;
//                            if (emp.pickup_by == '1') {
//                                pickup_by = 'Self';
//                                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//                            }
//                            else if (emp.pickup_by == '2') {
//                                pickup_by = 'I2H';
//                                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//                            }
//                            else {
//                                pickup_by = '-';
//                                //row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td><button class="edit btn btn-default  btn-sm btn-add" onclick=self_pickup("' + emp.I2H_order_id + '")>self Pickup</button><button class="delete btn btn-default  btn-sm btn-add" onclick=i2h_pickup("' + emp.I2H_order_id + '");>Third Party Pickup</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//                                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td><button class="edit btn btn-default  btn-sm btn-add" onclick=self_pickup("' + emp.I2H_order_id + '")>self Pickup</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//                            }
//                            j = j + 1;
//                            tr.append(row_data);
//                        });
//                        $('#Jobdetails').html(tr);
//                    }
//                    else {
//                        $('#Jobdetails').html(Norecord);
//                    }

//                }
//            }
//        });
//    }
//    else {
//    }
//}

//function name_filter() {
//    if ($.trim($('#PName').val()).length == "") {
//        $('#PPName').show();
//        $('#PPName').fadeOut(8000);
//        $('#PPName').html('Enter Name or Phone Number or Patient Id');
//        $('#PName').focus();
//        $('#PName').val('');
//        return false;
//    }
//    if ($.trim($('#PName').val()).length > 0) {
//        $('.testcount').show();
//        debugger;
//        var Template = {
//            doctor_id: $('#HiddenDoctorID').val(),
//            Dml_Indicator: 'POL',
//            FDate: $('#PName').val().split('/')[2],
//        }
//        $.ajax({
//            async: true,
//            type: 'POST',
//            url: '/Template/lab_home_colection',
//            contentType: 'application/json; charset=UTF-8',
//            data: JSON.stringify(Template),
//            success: function (data) {
//                $('#PName').val('');
//                $('.testcount').hide();
//                $('#Jobdetails').empty();
//                if (jQuery.isEmptyObject((data))) {
//                    $('#Jobdetails').html(Norecord);
//                }
//                else {
//                    debugger;
//                    var invoiceAmt = '', invoicedue = '', j, order_status = '', phone, pickup_by;
//                    var data1 = JSON.parse(data);
//                    if (data.length > 4 && data != null) {
//                        var b = data1.Table;
//                        tr = $('<table class="table-responsive table table-condensed body-borderless table_borderless" id="labJoblist" />');
//                        tr.append('<thead><tr><th>&nbsp;</th><th>Order No</th><th>Name</th><th>Mobile No</th><th>Status</th><th>Invoice Amount</th><th>Booked Date</th><th>Pickup Date</th><th>Pickup Time</th><th>Pickup By</th><th>Action</th></tr></thead>');
//                        j = 0;
//                        $.each(b, function (i, emp) {
//                            if (emp.payment_status == null || emp.payment_status == '') order_status = '-';
//                            else order_status = emp.payment_status;
//                            if (emp.phone_number_1 == null || emp.phone_number_1 == "") phone = "-";
//                            else phone = emp.phone_number_1;
//                            if (emp.pickup_by == '1') {
//                                pickup_by = 'Self';
//                                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//                            }
//                            else if (emp.pickup_by == '2') {
//                                pickup_by = 'I2H';
//                                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//                            }
//                            else {
//                                pickup_by = '-';
//                                //row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td><button class="edit btn btn-default  btn-sm btn-add" onclick=self_pickup("' + emp.I2H_order_id + '")>self Pickup</button><button class="delete btn btn-default  btn-sm btn-add" onclick=i2h_pickup("' + emp.I2H_order_id + '");>Third Party Pickup</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//                                row_data = '<tr data-toggle="collapse" data-target="#demo_' + j + '" class="accordion-toggle"><td><button onclick=orderdetails("demo_' + j + '","' + emp.I2H_order_id + '") class="part-payment btn btn-primary  btn-xs mr-20"><span class="glyphicon glyphicon-eye-open"></span></button></td><td>' + emp.I2H_order_id + '</td><td>' + emp.first_name + '<span style="color: #999; font-size: 11px;">(' + emp.patient_id + ')</td><td>' + phone + '</td><td>' + order_status + '</td><td>' + emp.total_cost + '</td><td>' + emp.created_on + '</td><td>' + emp.pickupdate + '</td><td>' + emp.slot_time + '</td><td>' + pickup_by + '</td><td><button class="edit btn btn-default  btn-sm btn-add" onclick=self_pickup("' + emp.I2H_order_id + '")>self Pickup</button></td></tr><tr class="hiddenRow accordian-body collapse" id="demo_' + j + '"></tr>';
//                            }
//                            j = j + 1;
//                            tr.append(row_data);
//                        });
//                        $('#Jobdetails').html(tr);
//                    }
//                    else {
//                        $('#Jobdetails').html(Norecord);
//                    }

//                }
//            }
//        });
//    }
//    else {
//    }
//}


//$('#PName').on('input', function () {
//    $('#PName').autocomplete({
//        source: function (request, response) {
//            $.ajax({
//                async: true,
//                url: "/Template/AutoComplete_PatName?rep_list=" + $('#PName').val(),
//                type: "POST",
//                dataType: "json",
//                data: { Prefix: request.term },
//                success: function (data) {
//                    response($.map(data, function (item) {
//                        return { label: item.patient_name, value: item.patient_name };
//                    }));

//                }
//            });
//        }
//    });
//});


//MMM code ended