<?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 (item_service_type='Optical Frame' OR item_service_type='Optical Lens') AND job_number='$job_number' 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_total="select sum(qty*unit_price) as claim_total from claims_details where process_claim_no='$process_claim_no' and job_number='$job_number' and (item_service_type='Optical Frame')";
$rsclaim_total=mysql_query($query_claim_total, $courier) or die(mysql_error());
$row_rsclaim_total = mysql_fetch_assoc($rsclaim_total);
$totalRows_rsclaim_total = mysql_num_rows($rsclaim_total);

$query_claim_comment="select *, DATE_FORMAT(date_updated, '%e %b %Y %r') as datenew from claims_details_comments where claimno='$process_claim_no' 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'");

$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">
       
       <span style="float:left;"> 
             <span id="approvestatus_<?php echo $process_claim_no;?>_<?php echo $job_number2;?>">
                <?php if($action == 'view_items_details_admin_sent_job'){ ?>
               <?php }  else if(($query_status['status_location_id']==$_SESSION['branch_id']&&$query_status['audit_status']!='Job In-Transit') || ($query_status['audit_status']=='Job In-Transit'&&($departure_info['departure']==$_SESSION['branch_id']||$departure_info['arrival']==$_SESSION['branch_id']))){ ?>
                 <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']) {
                                        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>
                 <?php } else { ?>
                     <div class="row"> 
                         <div class="col-md-12">
                             <b> LOCATION : <b style="color:green;"><?php echo strtoupper($query_status['audit_status_proc']); ?></b> - <b>[ <?php echo strtoupper($query_status['audit_status_location']); ?></b> ]</b>
                         </div>
                     </div>
                     <?php  } ?>  
                 </div>
                 </div>
            </span>
      </span>
             <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>
        <span style="float:right; font-weight:bold; color:#000; font-size:13px;"><?php echo strtoupper($row_rsclaim['type_of_visit']); ?>
        &nbsp;|&nbsp;<?php if($row_rsclaim['attending_officer']){?> 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 - Description</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;"><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); ?></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 echo $row_rsclaim['decision_status']; ?></td>
                    <td style="background-color:#FFE8E8;"><?php echo $row_rsclaim['decision_reason'];?></td>
                    </tr>
                  <?php }  while ($row_rsclaim = mysql_fetch_assoc($rsclaim)); ?>
                   <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>
                  <?php }else{echo '<tr><td colspan="9" style="background: linen"><div class="none">No Claim Items Found. Search Items to Add to Claim.</div></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>
                        </tbody>
                    </table>
</div>  
</div>