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


list($process_claim_no, $job_nos, $job_int)= explode("_",$_POST['id']);
$job_number = $job_nos.'/'.$job_int;
$job_number2 = $job_nos.'_'.$job_int;
$query_claim="select *  from claims_details where process_claim_no='$process_claim_no' AND job_number='$job_number' AND (item_service_type='Optical Frame' OR item_service_type='Optical Lens') order by item_service,id desc";
$rsclaim=mysql_query($query_claim, $courier) or die(mysql_error());
$row_rsclaim = mysql_fetch_assoc($rsclaim);
$totalRows_rsclaim = mysql_num_rows($rsclaim);

$lens_id_info = mysql_fetch_assoc(mysql_query("SELECT lens_id_count FROM claims_details WHERE process_claim_no='$process_claim_no' AND item_service_type='Optical Lens' AND job_number='$job_number'"));
$lens_id_count = $lens_id_info['lens_id_count'];

$query_status = mysql_fetch_assoc(mysql_query("select audit_status,audit_status_other,branch_id,status_location_id from job_numbers where process_claim_no='$process_claim_no' AND job_number='$job_number'"));

$memnoclaim=$row_rsclaim['member_no'];
$meminscompanyclaim=$row_rsclaim['ins_company'];
$query_rsodest_mem = "select * from patient_information where card_number='$memnoclaim' and insurance_company1='$meminscompanyclaim'";
$rsodest_mem = mysql_query($query_rsodest_mem, $courier) or die(mysql_error());
$row_rsodest_mem = mysql_fetch_assoc($rsodest_mem);	
$totalRows_rsodest_mem = mysql_num_rows($rsodest_mem);

$query_claim_comment="select *, DATE_FORMAT(date_updated, '%e %b %Y %r') as datenew from claims_details_comments where claimno='$process_claim_no' AND job_number='$job_number' order by id desc;";
$rsclaim_comment=mysql_query($query_claim_comment, $courier) or die(mysql_error());
$row_rsclaim_comment = mysql_fetch_assoc($rsclaim_comment);
$totalRows_rsclaim_comment= mysql_num_rows($rsclaim_comment);

$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='$lens_id_count'"));
$optical_info = mysql_fetch_assoc(mysql_query("SELECT * FROM optical_examination WHERE process_claim_no ='$process_claim_no' AND lens_id_count='$lens_id_count'", $courier));

$branch_id = $query_status['branch_id'];
$branch_info = mysql_query("SELECT * FROM branches");
$audit_status = mysql_query("SELECT * FROM audit_status where type='main'");
$audit_status_2 = mysql_query("SELECT * FROM audit_status where type='other'");
$typeofvisit = 'OUT-PATIENT';
$departure_info = mysql_fetch_assoc(mysql_query("SELECT * FROM job_activities_status WHERE process_claim_no='$process_claim_no' AND job_number='$job_number' ORDER BY id DESC LIMIT 1"));
?>                                              

<div style="width:100%">
<table width="100%" border="0" cellpadding="1" cellspacing="1" class="sectionText1" id="membershipinfo">
    <tbody>
      <tr>
        <td height="25" valign="middle" style="color: #000; background-color: #FFFFFF;cursor: pointer;" class="baseborder">
       <?php if(($query_status['status_location_id']==$_SESSION['branch_id_user']&&$query_status['audit_status']!='Job In-Transit') || ($query_status['audit_status']=='Job In-Transit'&&($departure_info['departure']==$_SESSION['branch_id_user']||$departure_info['arrival']==$_SESSION['branch_id_user']))){ ?>
            <span style="float:left;"> 
                <span id="approvestatus_<?php echo $process_claim_no; ?>_<?php echo $job_number2;?>">
                    <div class="row"> 
                        <div class="col-md-12">
                            <div class="col-md-3">
                                <input type="hidden" name="provider_id" id="provider_id" value="<?php echo $row_rsclaim['provider_id']; ?>">
                                <select name="audit_status_<?php echo $process_claim_no; ?>_<?php echo $job_number2;?>" id="audit_status_<?php echo $process_claim_no; ?>_<?php echo $job_number2;?>" class="form-control" onchange="if(this.value=='Job In-Transit'){$('#other_job_status_<?php echo $process_claim_no; ?>_<?php echo $job_number2;?>').show();}else{$('#other_job_status_<?php echo $process_claim_no; ?>_<?php echo $job_number2;?>').hide()}">
                                    <option value=""> --Select Option-- </option>
                                    <?php while ($audit_status_row = mysql_fetch_assoc($audit_status)) { ?>
                                        <option <?php if ($query_status['audit_status'] == $audit_status_row['audit_status']) {
                                        echo 'selected=""';
                                    } ?> value="<?php echo $audit_status_row['audit_status']; ?>"><?php echo $audit_status_row['audit_status']; ?></option>
<?php } ?>
                                </select>
                            </div>
                            <div class="col-md-3" id="other_job_status_<?php echo $process_claim_no; ?>_<?php echo $job_number2;?>" style="display: <?php if($query_status['audit_status']=='Job In-Transit'){echo 'block';}else{echo 'none';} ?>">
                                <select name="audit_status_other_<?php echo $process_claim_no; ?>_<?php echo $job_number2;?>" id="audit_status_other_<?php echo $process_claim_no; ?>_<?php echo $job_number2;?>" class="form-control">
                                    <option value=""> --Select Option-- </option>
                                    <?php while ($audit_status_row = mysql_fetch_assoc($audit_status_2)) { ?>
                                        <option <?php if ($query_status['audit_status_other'] == $audit_status_row['audit_status']) {
                                        echo 'selected=""';
                                    } ?> value="<?php echo $audit_status_row['audit_status']; ?>"><?php echo $audit_status_row['audit_status']; ?></option>
<?php } ?>
                                </select>
                            </div>
                            <div class="col-md-3" id="audit_status_location_<?php echo $process_claim_no; ?>_<?php echo $job_number2;?>">
                                <input type="hidden" name="provider_id" id="provider_id" value="<?php echo $row_rsclaim['provider_id']; ?>">
                                <select name="branch_id_<?php echo $process_claim_no; ?>_<?php echo $job_number2;?>" id="branch_id_<?php echo $process_claim_no; ?>_<?php echo $job_number2;?>" class="form-control">
                                    <option value=""> --Select Option-- </option>  
                                    <?php while ($branch_row = mysql_fetch_assoc($branch_info)) { ?>
                                        <option <?php if ($branch_row['id'] == $_SESSION['branch_id_user']) {
                                        echo 'selected=""';
                                    } ?> value="<?php echo $branch_row['id']; ?>"><?php echo $branch_row['branch_name']; ?></option>
<?php } ?>
                                </select>
                            </div>
                            <div class="col-md-3">
                                <a href="#" onClick="getapprovequery('update_items_details_procurement','approvestatus_<?php echo $row_rsclaim['process_claim_no']; ?>_<?php echo $job_number2;?>','<?php echo $row_rsclaim['process_claim_no'];?>_<?php echo $job_number2;?>', '<?php echo $totalRows_rsclaim; ?>', '<?php echo $row_rsclaim['provider_id']; ?>', '<?php echo $row_rsclaim['ins_company']; ?>');" class="btn green">
                                    <span style="color:white; font-weight:bold; font-size:12px;">Save Information <i class="fa fa-check"></i></span>
                                </a>
                            </div>
                        </div>
                    </div>
                    </div>
                    </div>
                </span>
            </span>
            <?php }else{ ?>
                <div class="row"> 
                         <div class="col-md-12">
                             <b> LOCATION : <b style="color:green;"><?php echo strtoupper($query_status['audit_status']); ?></b> - <b style="color:red;">[ <?php echo branchName($query_status['status_location_id'], $courier);?> ]</b></b>
                         </div>
                     </div>
           <?php } ?>
       
            <span style="float:right; color:#000; font-size:13px;font-weight: bold;">
                    <label style="color:#FFF; font-size:13px;" onclick="getreceiptpayment('<?php echo $row_rsclaim['process_claim_no']; ?>','<?php echo $typeofvisit;?>');" class="btn red btn-outline btn-circle btn-sm active"> View Payment Made <i class="fa fa-print"></i></label>
            </span>
        
        </td>
      </tr>
      <tr>
        <td height="25" valign="middle" style="color: #000; background-color:#FFFFFF ;cursor: pointer;" class="baseborder"><div style="font-weight:bold; color:#000; font-size:13px;">
            <?php if($row_rsclaim['diagnosis']){?>Diagnosis: <?php echo strtoupper($row_rsclaim['diagnosis']); ?><?php }?> 
        </div>
        
        <div><br>
        <span style="float:right; font-weight:bold; color:#000; font-size:13px;"><?php echo strtoupper($row_rsclaim['type_of_visit']); ?>
        <?php if($row_rsclaim['attending_officer']){?> &nbsp;|&nbsp; ATTENDING OFFICER : <?php echo strtoupper($row_rsclaim['attending_officer']); ?><?php }?></span>
        </div>
        </td>
      </tr>
    </tbody>
  </table>              
                      
               <div style="background:#FFF;">    
                      <table class="table table-bordered">
                          <thead>
                              <tr>
                                  <th style="font-size: 12px;"><strong>Item</strong></th>
                                  <th style="font-size: 12px; background-color:#FFE8E8;text-align: right;"><strong>Qty</strong></th>
                                  <th style="font-size: 12px; text-align:right; background-color:#FFE8E8;text-align: right;"><strong>Price</strong></th>
                                  <th style="font-size: 12px; background-color:#FFE8E8;text-align: right;"><strong>Total</strong></th>
                                  <td style="font-size: 12px;background-color:#FFE8E8;"><strong>Decision</strong></td>
                                  <td style="font-size: 12px;background-color:#FFE8E8;"><strong>Reason</strong></td>
                              </tr>
                          </thead>
                                                <tbody>
                                              
                                                
                                                <?php if ($totalRows_rsclaim> 0) { ?>   
                                                    <?php
                                                    do {
                                                        $i = $i + 1;
                                                        ?>
                                                        <tr<?php
                                                        if (fmod($i, 2) > 0) {
                                                            echo 'class="odd"';
                                                        } else {
                                                            echo 'style="background: #FFE8E8"';
                                                        }
                                                        ?>>
                                                          <td><input type="hidden" name="chkquery_<?php echo $row_rsclaim['process_claim_no']; ?>_<?php echo $job_number2;?>_<?php echo $i;?>" id="chkquery_<?php echo $row_rsclaim['process_claim_no']; ?>_<?php echo $job_number2;?>_<?php echo $i;?>" value="<?php echo $row_rsclaim['id']; ?>"/>
                                                          <?php 
                                                                echo strtoupper($row_rsclaim['item']);
                                                                if($row_rsclaim['rx_prescription_name'] != ''){
                                                                   echo ' - '.$row_rsclaim['rx_prescription_name']; 
                                                                } ?>
                                                          </td>
                    <td style="background-color:#FFE8E8;text-align: right;"> <?php echo $row_rsclaim['qty']; ?></td>
                    <td style="text-align:right; background-color:#FFE8E8;text-align: right;">
                    <?php echo number_format($row_rsclaim['unit_price'],2); ?>
                    &nbsp;&nbsp;&nbsp;
                    </td>
                    <td style="background-color:#FFE8E8;text-align: right;"><?php echo number_format(($row_rsclaim['qty']*$row_rsclaim['unit_price']),2); ?></td>
                    <td style="background-color:#FFE8E8;">
                    <?php if($row_rsclaim['audit_status']!="lab"){?>
                        <select class="form-control" name="itemdecisionstatus_<?php echo $row_rsclaim['process_claim_no']; ?>_<?php echo $job_number2;?>_<?php echo $i;?>" id="itemdecisionstatus_<?php echo $row_rsclaim['process_claim_no']; ?>_<?php echo $job_number2;?>_<?php echo $i;?>" style="width:100px;" onchange="getdecisionshow('<?php echo $row_rsclaim['process_claim_no']; ?>_<?php echo $job_number2;?>', '<?php echo $i;?>');if(this.value=='Reject'){}else{$('#other_reason_<?php echo $row_rsclaim['process_claim_no']; ?>_<?php echo $job_number2;?>_<?php echo $i;?>').hide();}"  <?php if($row_rsclaim['audit_status']=="done"){echo "readonly"; }?>>
                    <option value="" selected>No Decision</option>
                          <?php 
                      $query_claim_dosage_form="select * from query_status order by ranking;";
                      $rsclaim_dosage_form=mysql_query($query_claim_dosage_form, $courier) or die(mysql_error());
                      $row_rsclaim_dosage_form = mysql_fetch_assoc($rsclaim_dosage_form);  
                        do {  ?>
                                                            <option value="<?php echo $row_rsclaim_dosage_form['status'];?>" <?php if($row_rsclaim['decision_status']==$row_rsclaim_dosage_form['status']){echo "selected";}?>><?php echo $row_rsclaim_dosage_form['status'];?></option>
                                                            <?php
} while ($row_rsclaim_dosage_form = mysql_fetch_assoc($rsclaim_dosage_form));
  $rows = mysql_num_rows($rsclaim_dosage_form);
  if($rows > 0) {
      mysql_data_seek($rsclaim_dosage_form, 0);
	  $row_rsclaim_dosage_form = mysql_fetch_assoc($rsclaim_dosage_form);
  }
         ?>
                                                          </select>
                                                           <?php } else{echo $row_rsclaim['decision_status']; }?>   
                    
                    </td>
                    <td style="background-color:#FFE8E8;">  
                        <?php if($row_rsclaim['audit_status']!="lab"){?>
                        <input class="form-control" placeholder="Enter Reason" type="text" name="decision_reason_<?php echo $row_rsclaim['process_claim_no']; ?>_<?php echo $job_number2;?>_<?php echo $i;?>" id="decision_reason_<?php echo $row_rsclaim['process_claim_no']; ?>_<?php echo $job_number2;?>_<?php echo $i;?>" value="<?php echo $row_rsclaim['decision_reason'];?>">
                        <?php }else{
                            echo $row_rsclaim['decision_reason'];
                        }?>
                    </td>
                    </tr>
                  <?php }  while ($row_rsclaim = mysql_fetch_assoc($rsclaim)); ?>
                   
                  <?php }else{echo '<tr><td colspan="9" style="color:red;text-align:center;">No Items Found.</td></tr>';}?>
                  </tbody>
                </table> 
                   
                   <table class="table table-bordered">
                        <thead>
                            <tr>
                                <th style=" background-color:#FFE8E8;">&nbsp;</th>
                                <th style=" background-color:#FFE8E8;"> Sphere </th>
                                <th style=" background-color:#FFE8E8;"> Cylinder </th>
                                <th style=" background-color:#FFE8E8;"> Axis </th>
                                <th style=" background-color:#FFE8E8;"> Add </th>
                                <th style=" background-color:#FFE8E8;"> PD </th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td> <label> OD </label> </td> 
                                <td><?php echo $optical_info['od_sphere']; ?> </td> 
                                <td> <?php echo $optical_info['od_cylinder']; ?> </td> 
                                <td> <?php echo $optical_info['od_axis']; ?> </td> 
                                <td> <?php echo $optical_info['od_add']; ?> </td> 
                                <td> <?php echo $optical_info['od_pd']; ?></td> 
                            </tr>
                            <tr>
                                <td> <label> OS </label> </td> 
                                <td> <?php echo $optical_info['os_sphere']; ?> </td> 
                                <td> <?php echo $optical_info['os_cylinder']; ?> </td> 
                                <td> <?php echo $optical_info['os_axis']; ?> </td> 
                                <td> <?php echo $optical_info['os_add']; ?></td> 
                                <td> <?php echo $optical_info['os_pd']; ?></td> 
                            </tr>
                            <tr>
                                <td colspan="6">
                                    <b>Lens Type : </b>
                                    <span> <?php
                                        $lens_addition = PatientLensAddition($process_claim_no,$lens_id_count);
                                        echo strtoupper($patient_lens_type['lens_type']); echo strtoupper(' '.$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>
                                </td>
                            </tr>
                            <tr>
                                <td style="font-weight:bold;" colspan="6">
                                    <b> Comment : </b>
                                    <div class="col-md-12" id="consultation_drawing_wrapper">
                                        <div class="demo-gallery">
                                            <ul id="lightgallery" class="list-unstyled row">
                                                <?php
                                                $all_drawings = mysql_query("SELECT * FROM consultation_drawings WHERE process_claim_no = '$process_claim_no' AND type='additional_comment' ORDER BY id ASC", $courier);
                                                $i = 1;
                                                while ($row = mysql_fetch_assoc($all_drawings)) {
                                                    ?>
                                                    <li class="col-xs-6 col-sm-4 col-md-3" data-responsive="consultation/<?php echo $row['drawing_name']; ?> 375, consultation/<?php echo $row['drawing_name']; ?> 480, consultation/<?php echo $row['drawing_name']; ?> 800" data-src="consultation/<?php echo $row['drawing_name']; ?>" data-sub-html="<h4>Consultation Note <?php echo $i; ?></h4><p>Attached Consultation Note</p>">
                                                        <a href="">
                                                            <img style="height:120px" class="img-responsive" src="consultation/<?php echo $row['drawing_name']; ?>">
                                                        </a>
                                                    </li>
                                                    <?php
                                                    $i++;
                                                }
                                                ?>
                                            </ul>
                                        </div>
                                        <script type="text/javascript">
     $(document).ready(function(){
         $('#lightgallery').lightGallery({
             cssEasing: 'cubic-bezier(0.680, -0.550, 0.265, 1.550)'
           });
    });
</script>
                                    </div>
                                    
                             <textarea name="comment_<?php echo $process_claim_no;?>_<?php echo $job_number2;?>" id="comment_<?php echo $process_claim_no;?>_<?php echo $job_number2;?>" style="width:100%;font-weight: normal;" class="form-control" placeholder="New Comment"></textarea>

                                </td>
                               
                            </tr>
                            <tr <?php
                                                        if (fmod($i, 2) > 0) {
                                                            echo 'class="odd"';
                                                        } else {
                                                            echo 'style="background: #FFE8E8"';
                                                        }
                                                        ?>>
                                                          <td colspan="14">
                                                          <?php if($totalRows_rsclaim_comment>0){?>
                                                          <strong><u>Previous Comments</u></strong>:<br>
                                                          <br>
                                                          <ul>
                                                          <?php  do {?>
                                                          
                                                              <li><?php echo '<b>By : '.  UserFullName($row_rsclaim_comment['user_id'], $courier).'</b> - '. $row_rsclaim_comment['datenew']." -- ".$row_rsclaim_comment['comment'];?></li>
                                                          
                                                          <?php }  while ($row_rsclaim_comment = mysql_fetch_assoc($rsclaim_comment)); ?>
                                                          </ul>
                                                          <?php }?>
                                                          </td>
                                                  </tr>
                        </tbody>
                    </table>
</div>   
</div>

