<?php 

include "../db.php";
session_start();
if (isset($_POST['r_ref'])) 
{ 

    $total_amount_send = 0;
 	$total_amount_received = 0;
    $output = "";
    $sql ="SELECT * FROM ref_payment WHERE rp_holder_ref = '$_POST[r_ref]' ORDER BY rp_id DESC";
    $res = mysqli_query($con,$sql);
    if (mysqli_num_rows($res)>0) {
        while ($row=mysqli_fetch_assoc($res)) {
            
            $rp_amount_send = $row['rp_amount_receive'];
            $rp_amount_received = $row['rp_amount_send'];
            $rp_paymethod = $row['rp_paymethod'];
            $rp_date=$row['rp_date'];
            $total_amount_send +=  $rp_amount_send ;
            $total_amount_received +=  $rp_amount_received ;
            if ($rp_amount_send == 0) {
                $output .= "<div class='row'>
                     <div class='col-xs-4'>Received </div>
                     <div class='col-xs-4'><i class='fa fa-inr'></i> $rp_amount_received</div>
                     <div class='col-xs-4'>$rp_date</div>
                 </div>";
            }elseif($rp_amount_received ==0){
                $output .= "<div class='row'>
                     <div class='col-xs-4'>Send </div>
                     <div class='col-xs-4'><i class='fa fa-inr'></i> $rp_amount_send</div>
                     <div class='col-xs-4'>$rp_date</div>
                 </div>";
            }
            
        }
        $output .= "<hr>
                <div class='row'>
                     <div class='col-xs-7'>Total Send Amount</div>
                     <div class='col-xs-5 text-right'><i class='fa fa-inr'></i> $total_amount_send </div>
                     <div class='col-xs-7'>Total Received Amount</div>
                     <div class='col-xs-5 text-right'><i class='fa fa-inr'></i> $total_amount_received </div>
                 </div>";

 	}
    echo $output;

}

if (isset($_POST['r_ref_list'])) 
{ 

    $ap_total= 0;
    $not_ap_total= 0;
    $output = "";
    $sql ="SELECT * FROM registration WHERE r_upload_ref = '$_POST[r_ref_list]' ORDER BY r_id DESC";
    $res = mysqli_query($con,$sql);
    if (mysqli_num_rows($res)>0) {
        while ($row=mysqli_fetch_assoc($res)) {
            
            $r_name = $row['r_name'];
            
            if ($row['r_approved'] == 1) {
                $flag = "Approved";
                $ap_total += 1;
            }elseif($row['r_approved'] ==0){
                $flag = "Pending";
                $not_ap_total += 1;
            }
            $output .= "
                 <div class='row'>
                     <div class='col-xs-8'> <i class='fa fa-user'></i> $r_name </div>
                     <div class='col-xs-4'>$flag</div>
                 </div>";
            
        }
        $output .= "<hr>
                <div class='row'>
                     <div class='col-xs-6'><i class='fa fa-user-o'></i> $ap_total Approved</div>
                     <div class='col-xs-6 text-right'><i class='fa fa-user-o'></i> $not_ap_total Pending</div>
                 </div>";

    }
    echo $output;

}

 ?>
