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

 $recp_no=$_POST['id'];
$s = "/";
$r= "-";
$receiptno = str_replace($r,$s,$recp_no);										 
$query_rsodest_cashier_payments = "select * from cashier_payments where receiptno='$receiptno' order by id desc";
$rsodest_cashier_payments = mysql_query($query_rsodest_cashier_payments, $courier) or die(mysql_error($courier));
$row_rsodest_cashier_payments = mysql_fetch_assoc($rsodest_cashier_payments);	
$totalRows_cashier_payments = mysql_num_rows($rsodest_cashier_payments);

$transaction_type=$row_rsodest_cashier_payments['transaction_type']; 
$currency = 'GHS';


if($transaction_type=='' || $transaction_type=='payments'){ 
$query_claim="select * from claims_details where receipt_number='$receiptno' order by id desc;";
$rsclaim=mysql_query($query_claim, $courier) or die(mysql_error());
$row_rsclaim = mysql_fetch_assoc($rsclaim);
$totalRows_rsclaim = mysql_num_rows($rsclaim);

$memnoclaim=$row_rsclaim['member_no'];
$meminscompanyclaim=$row_rsclaim['ins_company'];

$query_claim_total="select sum(qty*unit_price) as claim_total from claims_details where receipt_number='$receiptno';";
$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);
}

if($transaction_type=='deposit' || $transaction_type=='refund'){ 

}


function getuser($userid){
$query_rsodest_insurer = "SELECT * FROM users where id='$userid'";
$rsodest_insurer = mysql_query($query_rsodest_insurer) or die(mysql_error());
$row_rsodest_insurer=mysql_fetch_assoc($rsodest_insurer);

$ccode=$row_rsodest_insurer['surname']." ".$row_rsodest_insurer['firstnames'];
return $ccode;
	
}?>                                                                                       

<div style="width:100%">
    <?php if($transaction_type=='' || $transaction_type=='payment'){ ?>
<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;?>">
                     <div class="row"> 
                         <div class="col-md-12">
                             <b> TOTAL AMOUNT : <b style="color:green;"><?php echo $currency.' '. number_format($row_rsclaim_total['claim_total'],2); ?></b>
                         </div>
                     </div>
                 </div>
                 </div>
            </span>
      </span>
       
            <span style="float:right; color:#000; font-size:13px;font-weight: bold;">
                    <label style="color:#FFF; font-size:13px;" onclick="getcashierprint('<?php echo $row_rsclaim['process_claim_no'] ?>','<?php echo $receiptno;?>','<?php echo $row_rsclaim['type_of_visit']; ?>')" class="btn green btn-outline btn-circle btn-sm active"> PRINT <i class="fa fa-print"></i></label>
                    <label style="color:#FFF; font-size:13px;" class="btn green btn-outline btn-circle btn-sm active"> RECEIPT NO: <?php echo $receiptno; ?></label>
            </span>
        
        </td>
      </tr>
      <tr>
        <td height="25" valign="middle" style="color: #000; background-color:#FFFFFF ;cursor: pointer;" class="baseborder">
        <div>
        <span style="float:left; font-weight:bold; color:#000; font-size:13px;display: none;">
        Service Provider:  
                                <?php $claim_for=$row_rsclaim['provider_id_data_for'];
				  if($row_rsclaim['provider_id_data_for']==''){
				  echo getprovider($row_rsclaim['provider_id']);
				  }
				  if($row_rsclaim['provider_id_data_for']!=''){
				  echo getprovider($row_rsclaim['provider_id_data_for']);
				  } ?>
        
        </span><br>
        <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>              
 <table width="100%" border="0" cellspacing="0" cellpadding="2" class="table table-striped table-bordered table-hover">
      <tr>
      <td width="100%" valign="top">                     
               <div style="background:#FFF;">    
                      <table class="table table-bordered">
                                                <thead>
                                                    <tr>
                                                    <th style="font-size: 12px; background-color:#FFE8E8;"><strong>Item</strong></th>
                                                    <th style="font-size: 12px; background-color:#FFE8E8;"><strong>User</strong></th>
                                                    <th style="font-size: 12px; background-color:#FFE8E8;text-align: right"><strong>Quantity</strong></th>
                                                    <th style="font-size: 12px; background-color:#FFE8E8;text-align: right"><strong>Unit Price</strong></th>
                                                    <th style="font-size: 12px; background-color:#FFE8E8;text-align: right"><strong>Total Amount</strong></th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                               
                                                    <?php if ($totalRows_rsclaim> 0) { ?>   
                                                    <?php
                                                    do {$i = $i + 1;?>
                                                        <tr>
                                                        <td><?php echo strtoupper($row_rsclaim['item']); ?></td>
                                                        <td><?php echo getuser($row_rsclaim['user_id']);?></td>
                                                        <td style="text-align: right"><?php echo $row_rsclaim['qty']; ?></td>
                                                        <td style="text-align:right;"><?php echo $row_rsclaim['unit_price']; ?></td>
                                                        <td style="text-align: right"><?php echo number_format($row_rsclaim['qty']*$row_rsclaim['unit_price'],2); ?></td>
                    
                    </tr>
                  <?php }  while ($row_rsclaim = mysql_fetch_assoc($rsclaim)); ?>
                   
                  <?php }else{echo '<tr><td colspan="9" style="color:red;"><div class="none">No Records Found.</div></td></tr>';}?>
                  </tbody>
                </table> 
</div>                
        </td>
                </tr>
                </table> 
    <?php } ?>
    
    <?php if($transaction_type=='deposit' || $transaction_type=='refund'){ ?>
        <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:right; color:#000; font-size:13px;font-weight: bold;">
                    <label style="color:#FFF; font-size:13px;" onclick="getcashierprint('<?php echo $row_rsclaim['process_claim_no'] ?>','<?php echo $receiptno;?>','<?php echo $row_rsclaim['type_of_visit']; ?>')" class="btn green btn-outline btn-circle btn-sm active"> PRINT <i class="fa fa-print"></i></label>
                    <label style="color:#FFF; font-size:13px;" class="btn green btn-outline btn-circle btn-sm active"> RECEIPT NO: <?php echo $receiptno; ?></label>
            </span>
        
        </td>
      </tr>
    </tbody>
  </table><br>
    <table width="100%" border="0" cellspacing="0" cellpadding="2" class="table table-striped table-bordered table-hover">
      <tr>
      <td width="100%" valign="top">                     
               <div style="background:#FFF;">    
                      <table class="table table-bordered">
                                                <thead>
                                                    <tr>
                                                    <th style="font-size: 12px; background-color:#FFE8E8;text-align: right"><strong></strong></th>
                                                    <th style="font-size: 12px; background-color:#FFE8E8;text-align: right"><strong>Balance Before</strong></th>
                                                    <th style="font-size: 12px; background-color:#FFE8E8;"><strong>Pay By</strong></th>
                                                    <th style="font-size: 12px; background-color:#FFE8E8;"><strong>User</strong></th>
                                                    <th style="font-size: 12px; background-color:#FFE8E8;text-align: right"><strong>Deposit Amount</strong></th>
                                                    <th style="font-size: 12px; background-color:#FFE8E8;text-align: right"><strong>Refund Amount</strong></th>
                                                    <th style="font-size: 12px; background-color:#FFE8E8;text-align: right"><strong>Balance After</strong></th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                               
                                                    <?php if ($totalRows_cashier_payments> 0) { ?>   
                                                    <?php
                                                    do {$i = $i + 1;?>
                                                        <tr>
										      <td height="23" valign="top" class="count"><span><?php echo $start_row; ?></span></td>
										      <td valign="top" style="cursor: pointer; text-align:right;" ><?php echo number_format($row_rsodest_cashier_payments['previous_balance'],2); ?></td>
										      <td valign="top"  style="cursor: pointer;"><?php echo strtoupper($row_rsodest_cashier_payments['pay_by']); ?></td>
										      <td valign="top"  style="cursor: pointer;"><?php echo getuser($row_rsodest_cashier_payments['cashier_user']);?></td>
										      <td valign="top"  style="cursor: pointer; text-align:right;"><?php 
										      if($row_rsodest_cashier_payments['transaction_type']=='deposit'){ echo number_format($row_rsodest_cashier_payments['amount'],2); }?></td>
										      <td valign="top"  style="cursor: pointer; text-align:right;"><?php 
											  if($row_rsodest_cashier_payments['transaction_type']=='refund'){
											  echo number_format($row_rsodest_cashier_payments['amount'],2);}?></td>
										      <td valign="top"  style="cursor: pointer; text-align:right;"><?php echo number_format($row_rsodest_cashier_payments['new_balance'],2); ?></td>
									        </tr>
                  <?php }  while ($row_rsodest_cashier_payments = mysql_fetch_assoc($rsodest_cashier_payments)); ?>
                    <input type="hidden" name="querytotal" id="querytotal" value="<?php echo $totalRows_rsclaim; ?>">
                  <?php }else{echo '<tr><td colspan="9" style="color:red;"><div class="none">No Records Found.</div></td></tr>';}?>
                  </tbody>
                </table> 
</div>                
        </td>
                </tr>
                </table> 
        
        <?php } ?>
    
</div>