<?php
error_reporting(0);
$query_claim = "select * from claims_details where receipt_number='$receipt_number' order by id desc;";
$rsclaim = mysql_query($query_claim, $courier) or die(mysql_error($courier));
$row_rsclaim = mysql_fetch_assoc($rsclaim);
$totalRows_rsclaim = mysql_num_rows($rsclaim);
if($totalRows_rsclaim < 1){
    $row_rsclaim = mysql_fetch_assoc(mysql_query("select type_of_visit,process_claim_no from claims_details where process_claim_no='$process_claim_no' order by id desc limit 1;"));
}
$process_claim_no = $row_rsclaim['process_claim_no'];
$type_of_visit = $row_rsclaim['type_of_visit'];
$currency = 'GHS' ;

// $query_claim_total = "select sum(qty*unit_price) as totalprice from claims_details where process_claim_no='$process_claim_no' and receipt_number='$receiptno'";
// $rsclaim_total = mysql_query($query_claim_total, $courier) or die(mysql_error($courier));
// $row_rsclaim_total = mysql_fetch_assoc($rsclaim_total);
// $totalRows_rsclaim_total = mysql_num_rows($rsclaim_total);
// $total_cash = $row_rsclaim_total['totalprice'];

?>

<div class="portlet-title">
    <div class="caption">
        <i class="fa fa-dollar" style="color:#000"></i>
        <span class="caption-subject bold" style="color:#000"> PRINT PAYMENT DETAILS  </span>
    </div>
    <div class="actions">
        <a href="#" onClick="getcashierprint('<?php echo $process_claim_no; ?>', '<?php echo $receipt_number; ?>', '<?php echo $type_of_visit; ?>');" class="btn green"> Print Receipt <i class="fa fa-print"></i></a> 
    </div>
</div>
<div class="portlet-body">
    <table class="table table-bordered" id="">
        <tbody>
            <tr>
                <td style="font-weight:bold;">Visit Number</td>
                <td colspan="3"><?php echo $process_claim_no; ?></td>
            </tr>
            <tr>
                <td style="font-weight:bold;">Receipt No</td>
                <td colspan="3"><?php echo $receipt_number; ?></td>
            </tr>
            <tr>
                <td style="font-weight:bold;">Total Amount</td>
                <td><?php echo $currency . " " . $total_total_amount; ?></td>
                <td style="font-weight:bold;">VAT/NHIL</td>
                <td><?php echo $currency . " " .$total_vatnhil; ?></td>
            </tr>
            <tr>
                <td style="font-weight:bold;">Total Bill</td>
                <td colspan="3"><?php echo $currency . " " .$total_bill; ?></td>
            </tr>
            <tr>
                <td style="font-weight:bold;">Amount Paid</td>
                <td><?php echo $currency . " " . number_format(($amount), 2); ?></td>
                <td style="font-weight:bold;">Paid By</td>
                <td><?php echo strtoupper($pay_by); ?></td>
            </tr>
            <tr>
                <td style="font-weight:bold;">Amount Deducted</td>
                <td><?php echo $currency . " " . number_format(($amount_deducted), 2); ?></td>
                <td style="font-weight:bold;">Current Balance</td>
                <td><?php echo $currency . " " . number_format($new_balance, 2); ?></td>
            </tr>
        </tbody>
    </table>
    
    <hr style="border-style: inset;border-width:2px;">
   
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>Item</th>
                <th style="text-align:right">Price</th>
                <th style="text-align: center">Status</th>
            </tr>
        </thead>
        <tbody>
            <?php if ($totalRows_rsclaim > 0) { ?>   
                <?php do { $i = $i + 1;?>
                    <tr>
                        <td><?php echo strtoupper($row_rsclaim['item']); ?></td>
                        <td style="text-align:right"> <?php echo number_format($row_rsclaim['unit_price'] * $row_rsclaim['qty'], 2); ?></td>
                        <td style="text-align: center;"><?php
                            if ($row_rsclaim['payment_status'] == 'Owing') {
                                echo "<span style='color:red;'>" . $row_rsclaim['payment_status'] . "</span>";
                            } else if ($row_rsclaim['payment_status'] == 'Paid') {
                                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" style="color:red;"><div class="none">No Billed Items Found. Search Items to Add to Bill.</div></td></tr>';
            }?>
        </tbody>
    </table> 
          
</div>