<?php include('accesscheck2.php'); 
require_once('Connections/courier.php');
require_once('functions/functions.php');
mysql_select_db($database_courier, $courier);

$id = $_POST['id'];
$rsodest_patient = mysql_query("SELECT * FROM process_claim_no WHERE patient_no = '$id' ORDER BY date_added, process_claim_no");
$total_count = mysql_num_rows($rsodest_patient);

?>


<ul class="nav nav-tabs">
    <li class="active">
        <a href="#tab_1_1" data-toggle="tab" aria-expanded="true"> CLIENT ACCOUNT STATEMENT </a>
    </li>
    <!-- <li class="">
        <a href="#tab_1_2" data-toggle="tab" aria-expanded="false">  CLIENT REFUNDS </a>
    </li> -->
    <!-- <li class="">
        <a href="#tab_1_3" data-toggle="tab" aria-expanded="false"> ITEM CANCELLATIONS </a>
    </li> -->
</ul>
<div class="tab-content">
    <div class="tab-pane active" id="tab_1_1">
        <div class="portlet light bordered">
            <div class="portlet-title">
                <div class="caption caption-md">
                    <i class="icon-globe theme-font hide"></i>
                   <!--  <span class="caption-subject font-blue-madison bold uppercase"><strong style="color: #9f181c;">BALANCE : GHS <?php if (empty($balance)) {
                        echo '0.00';
                    } else {
                        echo number_format($balance, 2);
                    } ?></strong></span> -->
                </div>
            </div>
            <div class="portlet-body form">
                <div class="form-body">
                    <span style="float: right; padding-right: 20px">
                                <label onclick="printReport2('administrative/print_patient_account_statement.php','<?php echo $row['process_claim_no'] ?>','<?php echo $id ?>','all_transaction');return false;" id="hide_discount_btn" class="btn red btn-outline btn-circle btn-sm active">
                                    Print Statement <i class="fa fa-print"></i>
                                </label>
                            </span>
                    <div class="row">
                        <div class="col-lg-12 col-xs-12 col-md-12">
                            
                            <br>

                            <table class="table table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th></th>
                                        <th style="text-align: center;">SN</th>
                                        <th>Date Time</th>
                                        <th>Visit No</th>
                                        <th>Service Type</th>
                                        <th>Branch</th>
                                        <th style="text-align: center;">Action</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                    $i = 1;
                                    while ($row = mysql_fetch_assoc($rsodest_patient)) {
                                        ?>
                                        <tr style="cursor: pointer;" onclick="$('.claims_<?php echo $row['id']; ?>').slideToggle(); $('#icon_<?php echo $row['id']; ?>').toggleClass('fa fa-plus fa fa-minus');">
                                            <td height="23" valign="top" class="count"><i id="icon_<?php echo $row['id']; ?>" class="fa fa-plus"></i></td>
                                            <td style="text-align: center;"><?php echo $i; ?></td>
                                            <td><?php echo date('jS F, Y g:i a', strtotime($row['date_added'])); ?></td>
                                            <td style="text-align: center;"><?php echo $row['process_claim_no'] ?></td>
                                            <td style="text-align: center;"><?php echo $row['service_category'] ?></td>
                                            <td style="text-align: center;"><?php echo branchName($row['branch_id'], $courier) ?></td>
                                            
                                            <td style="text-align: center;"> 
                                                <label onclick="printReport2('administrative/print_patient_account_statement.php','<?php echo $row['process_claim_no'] ?>','<?php echo $id ?>','single_transaction');return false;" id="hide_discount_btn" class="btn red btn-outline btn-circle btn-sm active">
                                                    Print <i class="fa fa-print"></i>
                                                </label>
                                            </td>
                                        </tr> <tr class="claims_<?php echo $row['id']; ?>" id="claims_<?php echo $row['id']; ?>" style="display: none;">
                                            <td colspan="20">
                                                <form name="form_<?php echo $row['id']; ?>" id="form_<?php echo $row['id']; ?>" method="post" action="">
                                                    <div style="display: none;" class="claims_<?php echo $row['id']; ?>">
                                                        <table class="table table-striped table-bordered">
                                                            <thead>
                                                                <tr>
                                                                    <th></th>                                                              
                                                                    <th>Item Name</th>
                                                                    <th style="text-align: right;">Qty</th>
                                                                    <th style="text-align: right;">Unit Price</th>
                                                                    <th style="text-align: right">Total</th>
                                                                    <th>VAT Excl</th>
                                                                    <th>VAT/NHIL</th>
                                                                    <th>Discount</th>

                                                                    <th>Payment Mode</th>
                                                                    <th>Payment Status</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                                <?php
                                                                $ii = 1;
                                                                $items_credit_sales = mysql_query("SELECT * FROM claims_details WHERE process_claim_no='" . $row['process_claim_no'] . "'");
                                                                while ($row1 = mysql_fetch_assoc($items_credit_sales)) {
                                                                    ?>
                                                                    <tr>
                                                                        <td><?php echo $ii; ?></td>

                                                                        <td><?php echo strtoupper($row1['item']); ?></td>
                                                                        <td style="text-align: right;"><?php echo $row1['qty']; ?></td>
                                                                        <td style="text-align: right;"><?php echo 'GHS ' . $row1['unit_price']; ?></td>

                                                                        <td style="text-align: right;"><?php echo 'GHS ' . number_format($row1['qty'] * $row1['unit_price'], 2, '.', ','); ?></td>

                                                                        <td class="amount"> <?php $vatnhil = 0.03*($row1['qty']*$row1['unit_price']); $vatexl = ($row1['qty']*$row1['unit_price'])-$vatnhil;  echo number_format($vatexl,2) ; $vatexcl_total = $vatexcl_total+$vatexl;?></td>

                                                                        <td class="amount"> <?php echo number_format($vatnhil,2) ; $vatnhil_total = $vatnhil_total+$vatnhil;  ?> </td>

                                                                        <td class="amount"> <?php echo
                                                                        $discount_info = getDiscountAllowed($row1['process_claim_no'], $row1['discount_id']);echo $discount_info; $discount_total=$discount_total+$discount_info;?></td>


                                                                        <td><?php echo strtoupper($row1['mode_of_payment']); ?></td>
                                                                        <td><?php echo $row1['payment_status']; ?></td>
                                                                    </tr>
                                                                    <?php $ii++;
                                                                } ?>
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                </form>
                                            </td>
                                        </tr>
                                        <?php $i++;
                                    } ?>
                                </tbody>
                            </table>

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

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

    <div class="tab-pane" id="tab_1_2">
        <div class="portlet light bordered">
            <div class="portlet-title">
                <div class="caption caption-md">
                    <i class="icon-globe theme-font hide"></i>
                    <span class="caption-subject font-blue-madison bold uppercase"><strong style="color: #9f181c;">BALANCE : GHS <?php if (empty($balance)) {
                        echo '0.00';
                    } else {
                        echo number_format($balance, 2);
                    } ?></strong></span>
                </div>
                <div class="actions">
                    <a href="#cash_refund" class="btn btn-circle red btn-outline btn-sm active" data-toggle="modal">
                        <i class="fa fa-plus"></i> Create Refund </a>
                    </div>
                </div>
                <div class="portlet-body form">
                    <div class="form-body">
                        <div class="row">
                            <div class="col-lg-12 col-xs-12 col-md-12">
                                <table class="table table-striped table-bordered">
                                    <thead>
                                        <tr>
                                            <th></th>
                                            <th style="text-align: center;">SN</th>
                                            <th>Date Time</th>
                                            <th>Visit No</th>
                                            <th>Payment Mode</th>
                                            <th style="text-align: right;">Total Refunds</th>
                                            <th style="text-align: right;">Total Amount</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $i = 1;
                                        while ($row = mysql_fetch_assoc($query_rsodest)) {
                                            ?>
                                            <tr style="cursor: pointer;" onclick="$('.claims_<?php echo $row['process_claim_no']; ?>').slideToggle(); $('#icon_<?php echo $row['process_claim_no']; ?>').toggleClass('fa fa-plus fa fa-minus');">
                                                <td height="23" valign="top" class="count"><i id="icon_<?php echo $row['id']; ?>" class="fa fa-plus"></i></td>
                                                <td style="text-align: center;"><?php echo $i; ?></td>
                                                <td><?php echo date('jS F, Y g:i a', strtotime($row['date_added'])); ?></td>
                                                <td><?php echo $row['process_claim_no']; ?></td>
                                                <td><?php echo $row['mode_of_payment']; ?></td>
                                                <td style="text-align: right;"><?php echo $row['total_refunds']; ?></td>
                                                <td style="text-align: right;"><?php echo number_format($row['total_amount'], 2); ?></td>
                                            </tr> 
                                            <tr class="claims_<?php echo $row['process_claim_no']; ?>" id="claims_<?php echo $row['process_claim_no']; ?>" style="display: none;">
                                               <td colspan="12">
                                                   <form name="form_<?php echo $row['process_claim_no']; ?>" id="form_<?php echo $row['process_claim_no']; ?>" method="post" action="">
                                                       <div style="display: none;" class="claims_<?php echo $row['process_claim_no']; ?>">
                                                           <table class="table table-striped table-bordered">
                                                               <thead>
                                                                   <tr>
                                                                       <th></th>
                                                                       <th>Date Time</th>
                                                                       <th>Item Name</th>
                                                                       <th style="text-align: right;">Qty</th>
                                                                       <th style="text-align: right;">Price</th>
                                                                       <th style="text-align: right;">Amount</th>
                                                                       <th>Reason</th>
                                                                       <th>Initiated By</th>
                                                                       <th>Approved By</th>
                                                                       <th>Status</th>
                                                                   </tr>
                                                               </thead>
                                                               <tbody>
                                                                   <?php
                                                                   $i=1;
                                                                   $items_gratis = mysql_query("SELECT * FROM refund_payments WHERE process_claim_no='".$row['process_claim_no']."'");
                                                                   while($row2 = mysql_fetch_assoc($items_gratis)){ ?>
                                                                       <tr id="status_tr_<?php echo $row2['id'] ?>">
                                                                           <td><?php echo $i; ?></td>
                                                                           <td><?php echo date('jS F, Y g:i a',  strtotime($row2['date_time'])); ?></td>
                                                                           <td><?php echo strtoupper($row['item']); ?></td>
                                                                           <td style="text-align: right;"><?php echo $row2['qty']; ?></td>
                                                                           <td style="text-align: right;"><?php echo $row2['unit_price']; ?></td>
                                                                           <td style="text-align: right;"><?php echo 'GHS '. number_format($row2['qty']*$row2['unit_price'],2,'.',','); ?></td>
                                                                           <td><?php echo $row2['reason']; ?></td>
                                                                           <td><?php echo strtoupper($row2['initiated_by']); ?></td>
                                                                           <td><?php echo strtoupper($row2['approved_by']); ?></td>
                                                                           <td id="gratis">
                                                                               <b id="status_approve_<?php echo $row2['id']; ?>" style="color:<?php if($row2['status']=='Approved'){echo 'green';}else{echo 'red';} ?>;"><?php echo $row2['status']; ?></b>
                                                                           </td>
                                                                       </tr>
                                                                       <?php $i++; } ?>
                                                                   </tbody>
                                                               </table>
                                                           </div>
                                                       </form>
                                                   </td>
                                               </tr>
                                               <?php $i++;
                                           } ?>
                                       </tbody>
                                   </table>

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

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

           <div class="tab-pane" id="tab_1_3">
            <div class="portlet light bordered">
                <div class="portlet-title">
                    <div class="caption caption-md">
                        <i class="icon-globe theme-font hide"></i>
                        <span class="caption-subject font-blue-madison bold uppercase"><strong style="color: #9f181c;">BALANCE : GHS <?php if (empty($balance)) {
                            echo '0.00';
                        } else {
                            echo number_format($balance, 2);
                        } ?></strong></span>
                    </div>
                </div>
                <div class="portlet-body form">
                    <div class="form-body">
                        <div class="row">
                            <div class="col-lg-12 col-xs-12 col-md-12">
                                <table class="table table-striped table-bordered">
                                    <thead>
                                        <tr>
                                            <th></th>
                                            <th style="text-align: center;">SN</th>
                                            <th>Date Time</th>
                                            <th>Visit No</th>
                                            <th>Payment Mode</th>
                                            <th style="text-align: right;">Total Cancellations</th>
                                            <th style="text-align: right;">Total Amount</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $i = 1;
                                        while ($row = mysql_fetch_assoc($query_rsodest_cancelled)) {
                                            ?>
                                            <tr style="cursor: pointer;" onclick="$('.claims_<?php echo $row['process_claim_no']; ?>').slideToggle(); $('#icon_<?php echo $row['process_claim_no']; ?>').toggleClass('fa fa-plus fa fa-minus');">
                                                <td height="23" valign="top" class="count"><i id="icon_<?php echo $row['id']; ?>" class="fa fa-plus"></i></td>
                                                <td style="text-align: center;"><?php echo $i; ?></td>
                                                <td><?php echo date('jS F, Y g:i a', strtotime($row['date_added'])); ?></td>
                                                <td><?php echo $row['process_claim_no']; ?></td>
                                                <td><?php echo $row['mode_of_payment']; ?></td>
                                                <td style="text-align: right;"><?php echo $row['total_refunds']; ?></td>
                                                <td style="text-align: right;"><?php echo number_format($row['total_amount'], 2); ?></td>
                                            </tr> 
                                            <tr class="claims_<?php echo $row['process_claim_no']; ?>" id="claims_<?php echo $row['process_claim_no']; ?>" style="display: none;">
                                               <td colspan="12">
                                                   <form name="form_<?php echo $row['process_claim_no']; ?>" id="form_<?php echo $row['process_claim_no']; ?>" method="post" action="">
                                                       <div style="display: none;" class="claims_<?php echo $row['process_claim_no']; ?>">
                                                          <table class="table table-striped table-bordered">
                                                           <thead>
                                                               <tr>
                                                                   <th></th>
                                                                   <th>Date Time</th>
                                                                   <th>Item Name</th>
                                                                   <th style="text-align: right;">Qty</th>
                                                                   <th style="text-align: right;">Price</th>
                                                                   <th style="text-align: right;">Amount</th>
                                                                   <th style="text-align: right;">Reason</th>
                                                                   <th>Initiated By</th>
                                                                   <th>Approved By</th>
                                                                   <th>Status</th>
                                                               </tr>
                                                           </thead>
                                                           <tbody>
                                                               <?php
                                                               $i=1;
                                                               $items_gratis = mysql_query("SELECT * FROM items_cancel_swap WHERE process_claim_no='".$row['process_claim_no']."'");
                                                               while($row = mysql_fetch_assoc($items_gratis)){ ?>
                                                                   <tr id="status_tr_<?php echo $row['id'] ?>">
                                                                       <td><?php echo $i; ?></td>
                                                                       <td><?php echo date('jS F, Y g:i a',  strtotime($row['date_time'])); ?></td>
                                                                       <td><?php echo strtoupper($row['item']); ?></td>
                                                                       <td style="text-align: right;"><?php echo $row['qty']; ?></td>
                                                                       <td style="text-align: right;"><?php echo $row['unit_price']; ?></td>
                                                                       <td style="text-align: right;"><?php echo 'GHS '. number_format($row['qty']*$row['unit_price'],2,'.',','); ?></td>
                                                                       <td><?php echo $row['reason']; ?></td>
                                                                       <td><?php echo strtoupper($row['initiated_by']); ?></td>
                                                                       <td><?php echo strtoupper($row['approved_by']); ?></td>
                                                                       <td id="gratis">
                                                                           <b id="status_approve_<?php echo $row['id']; ?>" style="color:green;"><?php echo $row['status']; ?></b>
                                                                       </td>
                                                                   </tr>
                                                                   <?php $i++; } ?>
                                                               </tbody>
                                                           </table>
                                                       </div>
                                                   </form>
                                               </td>
                                           </tr>
                                           <?php $i++;
                                       } ?>
                                   </tbody>
                               </table>

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

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




