<?php
$query_rsodest_claim_no = "select * from process_claim_no where process_claim_no='$process_claim_no'";
$rsodest_claim_no = mysql_query($query_rsodest_claim_no, $courier) or die(mysql_error());
$row_rsodest_claim_no = mysql_fetch_assoc($rsodest_claim_no);
$totalRows_rsodest_claim_no = mysql_num_rows($rsodest_claim_no);

$rsclaim=mysql_query("select * from claims_details where process_claim_no='$process_claim_no' AND mode_of_payment='$claim_area' order by id desc;", $courier) or die(mysql_error());
$row_rsclaim = mysql_fetch_assoc($rsclaim);
$totalRows_rsclaim = mysql_num_rows($rsclaim);

$rsclaim_total=mysql_query("select sum(qty*unit_price) as totalprice from claims_details where process_claim_no='$process_claim_no' and mode_of_payment='cash'", $courier) or die(mysql_error());
$row_rsclaim_total = mysql_fetch_assoc($rsclaim_total);
$total_cash=$row_rsclaim_total['totalprice'];

$rsclaim_total=mysql_query("select sum(qty*unit_price) as totalprice from claims_details where process_claim_no='$process_claim_no' and mode_of_payment='gratis'", $courier) or die(mysql_error());
$row_rsclaim_total = mysql_fetch_assoc($rsclaim_total);
$total_gratis=$row_rsclaim_total['totalprice'];

$rsclaim_total=mysql_query("select sum(qty*unit_price) as totalprice,mode_of_payment from claims_details where process_claim_no='$process_claim_no' and (mode_of_payment<>'cash' AND mode_of_payment<>'gratis')", $courier) or die(mysql_error());
$row_rsclaim_total = mysql_fetch_assoc($rsclaim_total);
$total_other=$row_rsclaim_total['totalprice'];
$payment_mode_other=$row_rsclaim_total['mode_of_payment'];
$currency = '';

$discount_amount_info = mysql_fetch_assoc(mysql_query("SELECT sum(discount_amount) AS total_discount FROM patient_visit_discounts WHERE process_claim_no = '$process_claim_no' AND discount_status='Approved'"));
$discount_amount = $discount_amount_info['total_discount'];

?>    

     
     <table class="table" style="background-color: #EEEEEE">
         <tbody>
             <tr>
             <?php if($claim_area != 'insurance' && $claim_area != 'company'){ ?>
                 <td> <div style="padding: 2px;"> <b> TOTAL </b> : <?php echo $currency." ".number_format(($total_cash+$total_other+$total_gratis),2); ?> </div> </td>
                 <td> <div style="padding: 2px;"> <b> <?php echo strtoupper($payment_mode_other);?> </b> : <?php echo $currency." ".number_format($total_other,2); ?> </div> </td>
                 <td> <div style="padding: 2px;"> <b> GRATIS </b> : <?php echo $currency." ".number_format($total_gratis,2); ?> </div> </td>
                 <td> <div style="padding: 2px;"> <b> CASH </b> : <?php echo $currency." ".number_format($total_cash,2); ?> </div> </td>
                 <td> <div style="padding: 2px;"> <b> DISCOUNT </b> : <?php echo $currency." ".number_format($discount_amount,2); ?> </div> </td>
                <?php } else{ ?>
                 <td> <div style="padding: 2px;"> <b> TOTAL AMOUNT </b> : <?php echo $currency." ".number_format($total_other,2); ?> </div> </td>
               <?php  } ?>
             </tr>
         </tbody>
     </table>
                                     </div>
                        <div class="portlet-body">
                            
                            <div id="claimsno_diagnostic" class="slimScrollDiv">
                                <div id="claim_response">
                                     <table class="table table-bordered">
                                         <thead>
                                             <tr>
                                                 <th style="">Item</th>
                                                 <th style="text-align:right">Qty</th>
                                                 <th style="text-align:right">Price</th>
                                                 <th style="text-align:right">Total</th>
                                                 <th style="text-align:center;">Mode</th>
                                                 <th style="text-align:center">Status</th>
                                             </tr>
                                         </thead>
                                                <tbody>
                                                <?php if ($totalRows_rsclaim> 0) { 
                                                    do {$i = $i + 1; ?>
                                                        <tr>
                                                          <td><?php echo strtoupper($row_rsclaim['item']); ?></td>
                                                        <td style="text-align:right">
                                                              <?php if($row_rsclaim['payment_status'] == 'Owing'&&$row_rsclaim['mode_of_payment'] == 'cash'&&$row_rsclaim['discount_applied']=='not applied'){ ?>
                                                              <input type="hidden" type="hidden" multiple="" name="item_trans_id[]" value="<?php echo $row_rsclaim['id'];?>">
                                                              <input type="hidden" type="hidden" multiple="" name="item_trans_amount[]" value="<?php echo ($row_rsclaim['qty']*$row_rsclaim['unit_price']);?>">
                                                            <?php } ?>
                                                            <?php echo $row_rsclaim['qty'];?>
                                                        </td>
                                                        <td style="text-align:right"> <?php echo number_format($row_rsclaim['unit_price'],2); ?></td>
                                                        <td style="text-align:right"><?php echo number_format($row_rsclaim['qty']*$row_rsclaim['unit_price'],2);?></td>
                                                        <td style="text-align:center;"><?php echo strtoupper($row_rsclaim['mode_of_payment']); ?></td>
                                                        <td style="text-align:center;"><?php if($row_rsclaim['payment_status']=='Owing' || $row_rsclaim['payment_status']=='Unapproved'){ 
														  echo "<span style='color:red;'>".$row_rsclaim['payment_status']."</span>";
														 }else{
														  echo "<span style='color:#090;'>".$row_rsclaim['payment_status']."</span>";
														 }?>
                                                        </td>
                                                        
                    </tr>
                  <?php }  while ($row_rsclaim = mysql_fetch_assoc($rsclaim)); ?>
                  <?php }  else{ echo '<tr><td colspan="9"><div class="none">No Billed Items Found. Search Items to Add to Bill.</div></td></tr>'; } ?>
                                                </tbody>
                </table> 
                <div class="pull-right" style="padding:10px;">
                    <?php $patient_signature = mysql_fetch_assoc(mysql_query("SELECT * FROM patient_signature_files WHERE process_claim_no = '$process_claim_no' LIMIT 1", $courier)); ?>
                     CLIENT SIGNATURE : 
                     <?php if(file_exists("administrative/".$patient_signature['signature_path'])) { ?>
                     <img style="height:50px" class="img-responsive" src="administrative/<?php echo $row['signature_path']; ?>">
                                                        <?php } else {
                                                                    echo 'NO SIGNATRE FOUND';
                                                        } ?>
                </div>

                                </div>  
                            </div>
                        </div>