<?php session_start();
include('accesscheck2.php');
require_once('Connections/courier.php'); 
require_once('functions/functions.php'); 

$action=$_POST["act"];
$id = $_POST['id'];

$supplier = $_POST['supplier'];
$supplier_address = $_POST['supplier_address'];
$memo = $_POST['memo'];
$delivery_location = $_POST['delivery_location'];
$delivery_address = $_POST['delivery_address'];
$expected_date = $_POST['expected_date'];
$user_id = $_SESSION['myMM_Userid'];
$user_name = $_SESSION['myMM_Fullname'];

if ($action == 'update_items_details_procurement') {
    $idd = $_POST['id'];
    list($id, $job_nos, $job_int) = explode("_",$_POST['id']);
    $job_number = $job_nos.'/'.$job_int;

    $provider_id = $_POST['provider_id'];
    $ins_company = $_POST['ins_company'];
    $comment = $_POST['comment_' . $idd];
    $total = $_POST['total'];
    $current_time = gmdate('Y-m-d h:i:s');
    $audit_status = $_POST['audit_status_' . $idd];
    $audit_status_other = $_POST['audit_status_other_' . $idd];
    $branch_id = $_POST['branch_id_' . $idd];

//    $check = mysql_num_rows(mysql_query("SELECT id FROM job_activities_status WHERE process_claim_no='$id' AND job_number='$job_number' AND job_status='$audit_status' AND arrival='$branch_id' LIMIT 1"));
//    if ((($audit_status == 'Job Received' || $audit_status == 'Job In-Progress') && $check > 0)) {
//    } else {
        $update = "update job_numbers set front_desk_date=now(), audit_status = '$audit_status', audit_status_other='$audit_status_other', status_location_id='$branch_id' where process_claim_no='$id' AND job_number='$job_number';";
        $update = $update . "update claims_details set audit_status = '$audit_status' where process_claim_no='$id' and provider_id='$provider_id';";

        $departure_info = mysql_fetch_assoc(mysql_query("SELECT * FROM job_activities_status WHERE process_claim_no='$id' AND job_number='$job_number' ORDER BY id DESC LIMIT 1"));
        if ($departure_info['job_status'] == 'Job In-Transit' && ($audit_status == 'Job Received' || $audit_status == 'Job In-Progress')) {
            mysql_query("UPDATE job_activities_status SET arrival_time=now() WHERE id='" . $departure_info['id'] . "'");
        }

        if ($audit_status == 'Job In-Transit') {
            mysql_query("INSERT INTO job_activities_status (branch_id,process_claim_no,job_number,departure,arrival,departure_time,job_status,job_status_other,user_id,previous_id) VALUES('".$_SESSION['branch_id_user'] . "','$id','$job_number','" . $_SESSION['branch_id_user'] . "','$branch_id',now(),'$audit_status','$audit_status_other','" . $user_id . "','" . $departure_info['id'] . "')");
            mysql_query("UPDATE job_activities_status SET status='closed' WHERE id='".$departure_info['id']."'");
        } else {
            mysql_query("INSERT INTO job_activities_status (branch_id,process_claim_no,job_number,departure,arrival,arrival_time,job_status,user_id,previous_id) VALUES('".$_SESSION['branch_id_user'] . "','$id','$job_number','" . $departure_info['departure'] . "','$branch_id',now(),'$audit_status','" . $user_id . "','" . $departure_info['id'] . "')");
            mysql_query("UPDATE job_activities_status SET status='closed' WHERE id='".$departure_info['id']."'");
        }
//    }

    for ($x = 1; $x <= $total; $x++) {
        $itemid22 = $_POST['chkquery_' . $id . '_' . $x];
        $itemdecisionstatus[$x] = $_POST["itemdecisionstatus_" . $id . "_" . $x];
        $itemreason[$x] = $_POST["decision_reason_" . $id . "_" . $x];
        $update = $update . 'update claims_details set decision_status="' . $itemdecisionstatus[$x] . '", decision_reason="' . $itemreason[$x] . '" where id="' . $itemid22 . '";';
    }

    if ($comment) {
        $update = $update . "INSERT INTO `claims_details_comments` (`id`, `provider_id`, `claimno`, `job_number` `comment`, `date_updated`, `user_id`) VALUES (NULL, '$provider_id', '$id','$job_number', '$comment', '$current_time', '" . $_SESSION['myMM_Userid'] . "');";
    }
    require('Connections/couriermysqli_local.php');
    $query_rsodest = $update;
    $rsodest = mysqli_multi_query($couriermysqli_local, $query_rsodest);
    mysqli_close($couriermysqli_local);
}

if ($action == 'update_items_details_administrative') {
    $provider_id = $_POST['provider_id'];
    $ins_company = $_POST['ins_company'];
    $comment = $_POST['comment_' . $id];
    $total = $_POST['total'];
    $current_time = gmdate('Y-m-d h:i:s');
    $audit_status = $_POST['audit_status_' . $id];
    $branch_id = $_POST['branch_id_' . $id];

    $update = "update process_claim_no set audit_status = '$audit_status', audit_status_location='$branch_id' where process_claim_no='$id' and provider_id='$provider_id';";
    require('Connections/couriermysqli_local.php');
    $query_rsodest = $update;
    $rsodest = mysqli_multi_query($couriermysqli_local, $query_rsodest);
    mysqli_close($couriermysqli_local);
}

if ($action == 'save_new_supplier') {
    $supplier_name = $_POST['supplier_name'];
    $supplier_address = $_POST['address'];
    $query_insert = "INSERT INTO suppliers(supplier,supplier_address) VALUES('$supplier_name','$supplier_address')";
    $rsinsert = mysql_query($query_insert, $courier) or die(mysql_error());

    if ($rsinsert == TRUE) {
        echo 'Success! New Supplier Saved Successfully.@@@success@@@';
    } else {
        echo 'Oops! Failed to Save New Supplier.@@@error@@@';
    }
    include('list_of_suppliers.php');
}

if($action == 'edit_supplier_details'){ 
    $row = mysql_fetch_assoc(mysql_query("SELECT * FROM suppliers WHERE id = '$id'")); ?>
    <div class="row">
        <div class="col-lg-12 col-md-12 col-xs-12 col-sm-12">
            <div class="portlet light ">
                <div class="portlet-title">
                    <div class="caption">
                        <span class="caption-subject bold uppercase font-dark">SUPPLIERS DETAILS</span>
                    </div>
                </div>
                <div class="portlet-body form">
                    <form role="form" action="#" id="edit_supplier_details_form" class="form-horizontal">
                        <div class="form-body">
                            <div class="row" id="investment_plan_wrapper">    
                                <div class="col-lg-12 col-xs-12 col-md-12">
                                    <div class="form-group">
                                        <label class="col-md-3 control-label"><span class="pull-left">Supplier's Name</span></label>
                                        <div class="col-md-7">
                                            <input name="supplier_name" id="supplier_name" type="text" class="form-control" value="<?php echo $row['supplier'];?>">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-md-3 control-label"><span class="pull-left">Address/Phone/Email</span></label>
                                        <div class="col-md-7">
                                            <textarea name="address" id="address" rows="3" class="form-control"><?php echo $row['supplier_address']; ?></textarea>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-actions right">
                            <a class="btn default"> <i class="fa fa-refresh"></i> Reset </a>
                            <a class="btn green" onclick="saveInformation2('update_supplier_details','<?php echo $id; ?>','form#edit_supplier_details_form','#currentarea');return false;"> Update Supplier <i class="fa fa-check"></i> </a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
<?php
}

if($action == 'update_supplier_details'){
    $supplier_name = $_POST['supplier_name'];
    $supplier_address = $_POST['address'];
    $rsupdate_records = mysql_query("UPDATE suppliers SET supplier='$supplier_name',supplier_address='$supplier_address' WHERE id = '$id'");
    if ($rsupdate_records == TRUE) {
        echo 'Success! Supplier Details Updated.@@@success@@@';
    } else {
        echo 'Oops! Failed to Update Supplier Details.@@@error@@@';
    }
    include('list_of_suppliers.php');
}

if ($action == 'update_tems_details') {
    $item = $_POST['item'];
    $price = $_POST['price'];
    $price_insurance = $_POST['insurance_price'];
    $price_company = $_POST['company_price'];
    $price_staff = $_POST['staff_price'];
    $total_selected = $_POST['total_selected'];
    $category_name = $_POST['category'];
    $quantity_available=$_POST['quantity_available'];
    $min_re_order_qty =$_POST['min_re_order_qty'];
    $re_order_qty =$_POST['re_order_qty'];

    if($_SESSION['change_price'] == 'yes') { 
    $query_rsodest = "update service_items set service='$category_name', price='$price',price_company='$price_company',price_insurance='$price_insurance',price_staff='$price_staff',quantity_available='$quantity_available',min_re_order_qty='$min_re_order_qty',re_order_qty='$re_order_qty' where id='$id';";
    }else{
    $query_rsodest = "update service_items set quantity_available='$quantity_available',min_re_order_qty='$min_re_order_qty',re_order_qty='$re_order_qty' where id='$id';";
    }
    $rsupdate_records = mysql_query($query_rsodest, $courier) or die(mysql_error());

    if($_SESSION['change_price'] == 'yes') { 
    if ($total_selected > 0) {
        for ($i = 1; $i <= $total_selected; $i++) {
            $company_code = $_POST['company_code_' . $i];
            $company_pricing = $_POST['company_pricing_' . $i];
            $exclusive = $_POST['exclusive_' . $i];
            $delete = $_POST['delete_' . $i];
            
            ($exclusive != 'yes') ? $exclusive = 'no' : $exclusive;
            if (!empty($company_code) && !empty($company_pricing)) {
                if ($delete == 'yes') {
                    mysql_query("DELETE FROM service_items_price WHERE ins_company ='$company_code' AND provider_item_id = '$id'");
                }
                $check = mysql_query("SELECT * FROM service_items_price WHERE ins_company='$company_code' AND provider_item_id='$id'", $courier);
                if (mysql_num_rows($check) < 1) {
                    mysql_query("INSERT INTO service_items_price(ins_company,provider_item_id,price,exclusion,selling_qty) VALUES('$company_code','$id','$company_pricing','$exclusive','1')");
                } else if (mysql_num_rows($check) > 0) {
                    mysql_query("UPDATE service_items_price SET price='$company_pricing', exclusion='$exclusive',selling_qty='1' WHERE ins_company ='$company_code' AND provider_item_id = '$id'");
                }
            }
        }
    }
    }
    
     if ($rsupdate_records == TRUE) {
        echo 'Success! Item Details Updated Successfully.@@@success@@@';
    } else {
        echo 'Oops! Failed to Update Item Details.@@@error@@@';
    }
    include 'list_of_all_items.php';
}

if ($action == 'update_tems_details_procurement' || $action == 'save_tems_details_procurement') {
    $item = $_POST['item'];
    $price = $_POST['price'];
    $price_insurance = $_POST['insurance_price'];
    $price_company = $_POST['company_price'];
    $price_staff = $_POST['staff_price'];
    $total_selected = $_POST['total_selected'];
    $category_id = $_POST['category'];
    // $quantity_available=$_POST['quantity_available'];
    $min_re_order_qty =$_POST['min_re_order_qty'];
    $re_order_qty =$_POST['re_order_qty'];
    $cost_price =$_POST['cost_price'];
    $category_item_service =$_POST['category_item_service'];
    $change_price = 'yes';
    $item_name = $_POST['item_name'];
    $rxclaim_code = $_POST['rxclaim_code'];
    $item_status = $_POST['item_status'];
    $category_name_info = mysql_fetch_assoc(mysql_query("SELECT * FROM item_categories WHERE id='$category_id'"));
    $category_name = $category_name_info['category_name'];
    // $quantity_available_store = $_POST['quantity_available'];
    $quantity_available_adabraka = $_POST['quantity_available_adabraka'];
    $quantity_available_kumasi = $_POST['quantity_available_kumasi'];
    $quantity_available_tema = $_POST['quantity_available_tema'];
    $quantity_available_adenta = $_POST['quantity_available_adenta'];
    $quantity_available_weija = $_POST['quantity_available_weija'];
    $quantity_available_danquah = $_POST['quantity_available_danquah'];
    $quantity_available=$_POST['quantity_available'];

    if($price != ''){
    if($action == 'update_tems_details_procurement'){
    $query_rsodest = "update stock_items set quantity_available='$quantity_available',status='$item_status',ins_item_code='$rxclaim_code', push_status='update',service_type='$category_name',service='$category_item_service', cost_price='$cost_price', price='$price',price_company='$price_company',price_insurance='$price_insurance',price_staff='$price_staff',min_re_order_qty='$min_re_order_qty',re_order_qty='$re_order_qty',group_id='$category_id' where id='$id';";
    $rsupdate_records = mysql_query($query_rsodest, $courier) or die(mysql_error());
    if($item_status == "Approved"){
            $row = mysql_fetch_assoc(mysql_query("SELECT * FROM stock_items WHERE id='$id'"));
            $item_name = $row['item'];
            $price = $row['price'];
            $price_insurance = $row['price_insurance'];
            $price_company = $row['price_company'];
            $price_staff = $row['price_staff'];
            $service_type = $row['service_type'];
            
            $service_type = $row['service_type'];
            $category_item_service = $row['service'];
            $min_re_order_qty = 1;
            $re_order_qty = 1;
            $change_price = 'yes';
            $rxclaim_code = $row['ins_item_code'];
            $rsupdate_records = mysql_query("INSERT IGNORE INTO service_items SET id='$id',ins_item_code='$rxclaim_code', item='$item_name',rx_prescription_name='$item_name',rx_item_name='$item_name',rx_brand_name='$item_name',service_type='$service_type',service='$category_item_service',push_status='update', price_adabraka='$price',price_weija='$price',price_adenta='$price',price_tema='$price',price_kumasi='$price',price_danquah='$price',price_mobile_unit='$price',price_company='$price_company',price_insurance='$price_insurance',price_staff='$price_staff',quantity_available_adabraka='$quantity_available_adabraka',quantity_available_kumasi='$quantity_available_kumasi',quantity_available_tema='$quantity_available_tema',quantity_available_adenta='$quantity_available_adenta',quantity_available_weija='$quantity_available_weija',quantity_available_danquah='$quantity_available_danquah',min_re_order_qty='0',re_order_qty='0', branch_id='1'", $courier);
            $rsupdate_records = mysql_query("UPDATE service_items SET ins_item_code='$rxclaim_code', item='$item_name',rx_prescription_name='$item_name',rx_item_name='$item_name',rx_brand_name='$item_name',service_type='$service_type',service='$category_item_service',push_status='update', price_adabraka='$price',price_weija='$price',price_adenta='$price',price_tema='$price',price_kumasi='$price',price_danquah='$price',price_mobile_unit='$price',price_company='$price_company',price_insurance='$price_insurance',price_staff='$price_staff',quantity_available_adabraka='$quantity_available_adabraka',quantity_available_kumasi='$quantity_available_kumasi',quantity_available_tema='$quantity_available_tema',quantity_available_adenta='$quantity_available_adenta',quantity_available_weija='$quantity_available_weija',quantity_available_danquah='$quantity_available_danquah' WHERE id='$id'", $courier);
        }
    } else if($action == 'save_tems_details_procurement'){
        if($item_name !=''){
            $rsupdate_records = mysql_query("INSERT INTO stock_items SET cost_price='$cost_price', ins_item_code='$rxclaim_code', item='$item_name',rx_item_name='$item_name',rx_brand_name='$item_name',service_type='$category_name',service='$category_item_service',push_status='update', price='$price',price_company='$price_company',price_insurance='$price_insurance',price_staff='$price_staff',quantity_available='$quantity_available',min_re_order_qty='$min_re_order_qty',re_order_qty='$re_order_qty', branch_id='6',group_id='$category_id'", $courier);
            $id = mysql_insert_id();
            mysql_query("UPDATE stock_items SET item_id = '$id' WHERE id='$id'");
    }
    }
}

    // if($change_price == 'yes') { 
    // if ($total_selected > 0) {
    //     for ($i = 1; $i <= $total_selected; $i++) {
    //         $company_code = $_POST['company_code_' . $i];
    //         $company_pricing = $_POST['company_pricing_' . $i];
    //         $exclusive = $_POST['exclusive_' . $i];
    //         $delete = $_POST['delete_' . $i];
            
    //         ($exclusive != 'yes') ? $exclusive = 'no' : $exclusive;
    //         if (!empty($company_code) && !empty($company_pricing)) {
    //             if ($delete == 'yes') {
    //                 mysql_query("DELETE FROM service_items_price WHERE ins_company ='$company_code' AND provider_item_id = '$id'");
    //             }
    //             $check = mysql_query("SELECT * FROM service_items_price WHERE ins_company='$company_code' AND provider_item_id='$id'", $courier);
    //             if (mysql_num_rows($check) < 1) {
    //                 mysql_query("INSERT INTO service_items_price(ins_company,provider_item_id,price,exclusion,selling_qty,push_status) VALUES('$company_code','$id','$company_pricing','$exclusive','1','insert')");
    //             } else if (mysql_num_rows($check) > 0) {
    //                 mysql_query("UPDATE service_items_price SET price='$company_pricing', exclusion='$exclusive',selling_qty='1',push_status='update' WHERE ins_company ='$company_code' AND provider_item_id = '$id'");
    //             }
    //         }
    //     }
    // }
    // }
    
     if ($rsupdate_records == TRUE) {
        echo 'Success! Item Details Updated Successfully.@@@success@@@';
    } else {
        echo 'Oops! Failed to Update Item Details.@@@error@@@';
    }
    $action = "list_of_all_items_procurement";
    include 'list_of_all_items_procurement.php';
}


if ($action == 'fetch_job_activities_status') {
    list($process_claim_no,$job_number) = explode("_",$_POST['id']);
    $all_activiities = mysql_query("SELECT * FROM job_activities_status WHERE process_claim_no = '$process_claim_no' AND job_number='$job_number' ORDER BY id ASC;");
    $current_location_info = mysql_fetch_assoc(mysql_query("SELECT audit_status,status_location_id FROM job_numbers WHERE process_claim_no='$process_claim_no' AND job_number='$job_number'"));
    $count_activities = mysql_num_rows($all_activiities);
    $current_location = $current_location_info['status_location_id'];
    $current_location_status = $current_location_info['audit_status'];
    ?>
        <table class="table table-striped">
        <thead>
            <tr>
                <th></th>
                <th>Departure</th>
                <th>Arrival</th>
                <th>Departure Time</th>
                <th>Arrival Time</th>
                <th>Job Status</th>
                <th>Current Location</th>
                <th>Initiated By</th>
            </tr>
        </thead>
        <tbody>
            <?php
            $i=1;
            while ($row = mysql_fetch_assoc($all_activiities)) { ?>
                <tr>
                    <td><?php echo $i.'.'; ?></td>
                    <td><?php echo branchName($row['departure'], $courier) ?></td>
                    <td><?php echo branchName($row['arrival'], $courier) ?></td>
                    <td><?php if(!empty($row['departure_time'])){echo date('jS F, Y g:i a', strtotime($row['departure_time']));} ?></td>
                    <td><?php if(!empty($row['arrival_time'])){echo date('jS F, Y g:i a', strtotime($row['arrival_time']));} ?></td>
                    <td><?php echo strtoupper($row['job_status']); if($row['job_status']=='Job In-Transit' && !empty($row['job_status_other'])){ echo '-'. $row['job_status_other'];} ?></td>
                    <td><?php if($count_activities==$i){ 
                        if($current_location_status=='Job In-Transit'){
                        if($_SESSION['branch_id_user']==$row['departure'] || $_SESSION['branch_id_user']==$row['arrival']){
                          $current_location = $row['departure'];
                        }else{
                           $current_location = $row['arrival']; 
                        }
                    }
                        echo branchName($current_location, $courier) ;
                    }?></td>
                    <td><?php echo UserFullName($row['user_id'],$courier); ?></td>
                </tr>
            <?php $i++; } ?>
        </tbody>
    </table>
                
                
                <?php
}

if($action == "save_new_item_category"){
    $parent_name = $_POST['parent_name'];
    $category_name = $_POST['category_name'];
    $category_code = $_POST['category_code'];
    $insert = mysql_query("INSERT INTO item_categories(parent_id,category_name,category_code) VALUES('$parent_name','$category_name','$category_code')");
}

if($action == "pro_lens_prescription_details"){
    list($process_claim_no, $id) = explode("_",$_POST['id']);
    $patient_lens_type = mysql_fetch_assoc(mysql_query("SELECT lens_type FROM patient_lens_type WHERE process_claim_no='$process_claim_no' AND lens_id_count='$id'"));
    $optical_info = mysql_fetch_assoc(mysql_query("SELECT * FROM optical_examination WHERE process_claim_no ='$process_claim_no' AND lens_id_count='$id'"));
?>

             <div class="modal-body"> 
    <div class="portlet light bordered">
    <?php if(!empty($id)){ ?>
                                        <div class="portlet-title">
                                        <div class="actions">
                                <div class="btn-group btn-group-devided" data-toggle="buttons"> 
                                <?php if($visit_status == 'In Use'){ ?>                            
                                    <label onclick="calculateLensPrice('calculate_lens_price','<?php echo $process_claim_no; ?>', '<?php echo  $id; ?>', '#lens_price_details');" class="btn green btn-outline btn-circle btn-sm active" data-toggle="modal" href="#large">
                                            <input type="radio" name="options" class="toggle" id="option2"> Calculate Price <i class="fa fa-print"></i>
                                        </label>
                                <?php } ?>
                                    <label onclick="getprintPrescription('<?php echo $process_claim_no; ?>', '<?php echo  $id; ?>', '');" class="btn red btn-outline btn-circle btn-sm active" data-toggle="modal" href="#large">
                                            <input type="radio" name="options" class="toggle" id="option2"> Print Prescription <i class="fa fa-print"></i>
                                        </label>
                                </div>
                            </div>
                                        </div>
<?php } ?> 
                            <div class="row">
                                <div class="col-md-12" id="lens_price_details">
                                </div>
                            </div>

                                            <div class="portlet-body form">
                                        <div class="form-body">
                                            <div class="row">
                                                 <div class="col-md-12">
                                                 <table class="table table-bordered">
                        <thead>
                            <tr>
                                <th>&nbsp;</th>
                                <th> Sphere </th>
                                <th> Cylinder </th>
                                <th> Axis </th>
                                <th> VA </th>
                                <th> Add </th>
                                <th> VA </th>
                                <th> PD </th>
                                <th nowrap>  &nbsp;
                                    <label class="mt-checkbox"><input onclick="Apply_od_os();" id="apply_od_os" type="checkbox">
                                                    <span></span>
                                                </label> </th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td> <label> RIGHT </label> </td> 
                                <td> 
                                <input type="hidden" name="od_sphere" id="od_sphere" class="form-control" value="<?php echo $optical_info['od_sphere']; ?>"> <?php echo $optical_info['od_sphere']; ?> </td> 
                                <td> 
                                <input type="hidden" name="od_cylinder" id="od_cylinder" class="form-control" value="<?php echo $optical_info['od_cylinder']; ?>"> <?php echo $optical_info['od_cylinder']; ?></td>
                                <td> <input type="text" name="od_axis" id="od_axis" class="form-control" value="<?php echo $optical_info['od_axis']; ?>"> </td> 
                                <td> <input type="text" name="od_va" id="od_va" class="form-control" value="<?php echo $optical_info['od_va']; ?>"> </td> 
                                <td> <input type="text" name="od_add" id="od_add" class="form-control" value="<?php echo $optical_info['od_add']; ?>"> </td> 
                                <td> <input type="text" name="od_va2" id="od_va2" class="form-control" value="<?php echo $optical_info['od_va2']; ?>"> </td> 
                                <td> <input type="text" name="od_pd" id="od_pd" class="form-control" value="<?php echo $optical_info['od_pd']; ?>"> </td> 
                                <td></td> 
                            </tr>
                            <tr>
                                <td> <label> LEFT </label> </td> 
                                <td> <input type="hidden" name="os_sphere" id="os_sphere" class="form-control" value="<?php echo $optical_info['os_sphere']; ?>"> <?php echo $optical_info['os_sphere']; ?></td> 
                                <td> <input type="hidden" name="os_cylinder" id="os_cylinder" class="form-control" value="<?php echo $optical_info['os_cylinder']; ?>"> <?php echo $optical_info['os_cylinder']; ?></td>
                                <td> <input type="text" name="os_axis" id="os_axis" class="form-control" value="<?php echo $optical_info['os_axis']; ?>"> </td> 
                                <td> <input type="text" name="os_va" id="os_va" class="form-control" value="<?php echo $optical_info['os_va']; ?>"> </td> 
                                <td> <input type="text" name="os_add" id="os_add" class="form-control" value="<?php echo $optical_info['os_add']; ?>"> </td> 
                                <td> <input type="text" name="os_va2" id="os_va2" class="form-control" value="<?php echo $optical_info['os_va2']; ?>"> </td> 
                                <td> <input type="text" name="os_pd" id="os_pd" class="form-control" value="<?php echo $optical_info['os_pd']; ?>"> </td> 
                                <td></td>
                            </tr>
                        </tbody>
                    </table>
                                                </div> 
                                            </div>
                                           <hr>  
                                           
                                           <div class="row">
                                           <div class="col-md-12">
                             <div class="col-md-4">
                                 <div class="row">
                                     <div class="form-group">
                                         <label class="bold">GLASS</label>
                                         <div class="mt-radio-list">
                                             <?php
                                             $patient_lens_type = mysql_fetch_assoc(mysql_query("SELECT lens_type FROM patient_lens_type WHERE process_claim_no='$process_claim_no' AND lens_id_count='$id'"));
                                             $glass_lens = mysql_query("SELECT * FROM lens_types WHERE parent_name='GLASS'");
                                             while ($row = mysql_fetch_assoc($glass_lens)) { ?>
                                                 <label class="mt-radio mt-radio-outline"> <?php echo $row['lens_name']; ?>
                                                     <input <?php if($patient_lens_type['lens_type']== 'Glass - '.$row['lens_name']){ echo 'checked=""'; } ?> onchange="lensPrescriptions(this.value);" type="radio" value="Glass - <?php echo $row['lens_name']; ?>" name="lens_type">
                                                     <span></span>
                                                 </label>
                                                <?php } ?>
                                         </div>
                                     </div>
                                     <div class="form-group">
                                         <label class="bold">PLASTIC</label>
                                         <div class="mt-radio-list">
                                             <?php
                                             $plastic_lens = mysql_query("SELECT * FROM lens_types WHERE parent_name='PLASTIC'");
                                             while ($row = mysql_fetch_assoc($plastic_lens)) {
                                                 ?>
                                                 <label class="mt-radio mt-radio-outline"> <?php echo $row['lens_name']; ?>
                                                     <input <?php if($patient_lens_type['lens_type']=='Plastic - '.$row['lens_name']){ echo 'checked=""'; } ?> onchange="lensPrescriptions(this.value);" type="radio" value="Plastic - <?php echo $row['lens_name']; ?>" name="lens_type">
                                                     <span></span>
                                                 </label>
<?php } ?>
                                         </div>
                                     </div>
                                 </div>
                             </div>
                             <div class="col-md-4">
                                 <div class="row">
                                     <div class="form-group">
                                         <label class="bold">POLYCARBONATE/OTHER</label>
                                         <div class="mt-radio-list">
                                             <?php
                                             $poly_lens = mysql_query("SELECT * FROM lens_types WHERE parent_name='POLYCARBONATE/OTHER'");
                                             while ($row = mysql_fetch_assoc($poly_lens)) {
                                                 ?>
                                                 <label class="mt-radio mt-radio-outline"> <?php echo $row['lens_name']; ?>
                                                     <input <?php if($patient_lens_type['lens_type']=='Polycarbonate - '.$row['lens_name']){ echo 'checked=""'; } ?> onchange="lensPrescriptions(this.value);" type="radio" value="Polycarbonate - <?php echo $row['lens_name']; ?>" name="lens_type">
                                                     <span></span>
                                                 </label>
<?php } ?>
                                         </div>
                                     </div>
                                     <div class="form-group">
                                         <label class="bold">CONTACT LENS</label>
                                         <div class="mt-radio-list">
<?php
$contact_lens = mysql_query("SELECT * FROM lens_types WHERE parent_name='CONTACT LENS'");
while ($row = mysql_fetch_assoc($contact_lens)) {
    ?>
                                                 <label class="mt-radio mt-radio-outline"> <?php echo $row['lens_name']; ?>
                                                     <input <?php if($patient_lens_type['lens_type']=='Contact Lens - '.$row['lens_name']){ echo 'checked=""'; } ?> onchange="lensPrescriptions(this.value);" type="radio" value="Contact Lens - <?php echo $row['lens_name']; ?>" name="lens_type">
                                                     <span></span>
                                                 </label>
<?php } ?>
                                         </div>
                                     </div>
                                 </div>
                             </div>
                             <div class="col-md-4">
                                 <div class="row">
                                     <div class="form-group">
                                         <label class="bold">LENS TYPE/ADDITIONS</label>
                                         <div class="mt-checkbox-list">
<?php
$additons = mysql_query("SELECT * FROM lens_types WHERE parent_name='ADDITIONS'");
$additons_extra = mysql_query("SELECT * FROM lens_types WHERE parent_name='EXTRA ADDITIONS'");
$lens_extra = mysql_query("SELECT * FROM lens_types WHERE parent_name='EXTRA LENS'");?>


<select class="form-control" name="lens_type_main" id="lens_type_main">
    <option value="">Select Lens Type</option>
<?php while ($row = mysql_fetch_assoc($additons)) {  ?> 
    <option <?php if($row['lens_name']==$optical_info['lens_type']){ echo 'selected=""';} ?> value="<?php echo $row['lens_name']; ?>"><?php echo $row['lens_name']; ?></option>
                                                 <!-- <label class="mt-checkbox mt-checkbox-outline"> <?php echo $row['lens_name']; ?> -->
                                                     <!-- <input <?php //checkPatientLensAddition($process_claim_no, $row['lens_name'], $id); ?> class="addition_lens" onchange="displayLensPrescription();" type="checkbox" value="<?php echo $row['lens_name']; ?>" name="lens_addition[]" multiple=""> -->
                                                     <!-- <span></span> -->
                                                 <!-- </label> -->
        
<?php } ?>
</select>
<hr>
    <select class="form-control" name="lens_index" id="lens_index">
        <option value="">Select Option</option>
    <?php while ($row = mysql_fetch_assoc($lens_extra)) { ?>
            <option <?php if($row['lens_name']==$optical_info['lens_index']){ echo 'selected=""';} ?> value="<?php echo $row['lens_name']; ?>"><?php echo $row['lens_name']; ?></option>
    <?php } ?>
    </select>
    <hr>
<?php
while ($row = mysql_fetch_assoc($additons_extra)) { ?>  
                                                 <label class="mt-checkbox mt-checkbox-outline"> <?php echo $row['lens_name']; ?>
                                                     <input <?php checkPatientLensAddition($process_claim_no, $row['lens_name'], $id); ?> class="addition_lens" onchange="displayLensPrescription();" type="checkbox" value="<?php echo $row['lens_name']; ?>" name="lens_addition[]" multiple="">
                                                     <span></span>
                                                 </label>
<?php } ?>
                                         </div>
                                     </div> 
                                 </div> 
                             </div>
                         </div>
                     </div>
                 </div>
                                                
                                                <div class="row">
                                                    <div class="alert bold" id="">
                                                        <span id="lens_description_wrapper"> </span>
                                                        <span> <?php
                                                            $lens_addition = PatientLensAddition($process_claim_no,$id);
                                                            echo $patient_lens_type['lens_type']; echo ' '.$optical_info['lens_type'].' '; if(!empty($optical_info['lens_index'])){ echo '('.$optical_info['lens_index'].')';} if(!empty($lens_addition)){ ?> - Additions (<span id="lens_description_wrapper2"><?php echo $lens_addition; ?></span>) <?php } ?> </span>
                                                    </div>

                                                <div class="col-md-12 ">
        <div class="portlet light bordered">
            <div class="portlet-title">
                <div class="caption">
                    <i class="fa fa-bolt font-blue-hoki"></i>
                    <span class="caption-subject bold font-blue-hoki"> Contact Lens Prescription </span>
                </div>
                <div class="portlet-body">
                  <table class="table table-bordered">
                        <thead>
                            <tr>
                                <th> R </th>
                                <th> L </th>
                                <th> Base Curve </th>
                                <th> Diameter </th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td> <input type="text" name="r_eye" id="r_eye" class="form-control" value="<?php echo $optical_info['r_eye']; ?>"> </td> 
                                <td> <input type="text" name="l_eye" id="l_eye" class="form-control" value="<?php echo $optical_info['l_eye']; ?>"> </td> 
                                <td> <input type="text" name="base_curve" id="base_curve" class="form-control" value="<?php echo $optical_info['base_curve']; ?>"> </td> 
                                <td> <input type="text" name="diameter" id="diameter" class="form-control" value="<?php echo $optical_info['diameter']; ?>"> </td> 
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

                                                <!-- <hr> -->
                                                <button type="button" class="btn red btn-outline active" data-dismiss="modal">Close</button>
                                        <?php if($visit_status == 'In Use'){ ?>     
                                        <button id="save_patient_consultation" onclick="save_consultation('save_patient_prescription','<?php echo $process_claim_no; ?>@@@<?php echo $patient_id; ?>','<?php echo $id;?>','','0');return false;" class="btn btn green pull-right"> Save Prescription <i class="icon-ok"></i></button>
                                        <?php } ?>
                                          </div>
                                            </div>
                                            </div>
                                            </div>

<?php }