<?php

    session_start();

    include "../db.php";

    date_default_timezone_set('Asia/Kolkata');

    $currentDate = date('M j, Y');

    $currentDate2 = date('Y-m-d');



    if ( !isset($_SESSION['uid']) && !isset($_SESSION['uref']) && !isset($_SESSION['utype']) ) {

        header("Location: logout.php");

        exit();

    }

    if ( $_SESSION['utype'] != 'master_admin' && $_SESSION['uref'] != 'fssdf4543frts' ) {

        header("Location: logout.php");

        exit();

    }

    if (empty($_GET['uref_id'])) {

        header("Location: view-ref-users.php");

    }else{

        $p_sql = "SELECT * FROM users WHERE uref_code = '$_GET[uref_id]'";

        $p_res = mysqli_query($con,$p_sql);

        $p_row = mysqli_fetch_assoc($p_res);

    }



?>

<!DOCTYPE html>

<html lang="en">

<head>

 <?php include "includes/meta.php"; ?>        

    <?php include "includes/css.php"; ?>      

  



</head>

<body id="page-top" class="mt-55">



    <div style="margin-top: 70px;"></div>



      <?php include "includes/header2.php"; ?>



<div cl ass="container-fluid ">       

   <div class="row mx-0 justify-content-center mt-2">

        <div class="col-12 col-sm-8 col-md-8">

            <h1 class="h3 text-gray-800 text-center"><?php echo $p_row['uname']."'s"; ?> Payment  Details</h1>

                    <hr>

        <?php

            $pd_sql = "SELECT * FROM ref_payment WHERE rp_holder_ref = '$_GET[uref_id]' ORDER BY rp_id DESC";

            $pd_res = mysqli_query($con,$pd_sql);

            if (mysqli_num_rows($pd_res)>0) {

               $total_payment = 0;

            ?>



            <div class="mx-0 justify-content-center gx-1 rd" style="padding-top: 10px;padding-bottom: 10px;">

            <?php  while ($pd_rows= mysqli_fetch_assoc($pd_res)) { 

                        $total_payment += $pd_rows['rp_amount_send'];

                ?>

                <div class="row">

                    <div class="col-md-4 col-xs-5 text-center"> <?php echo $pd_rows['rp_date']; ?>    

                    </div>

                    <div class="col-md-4 col-xs-3 text-left"><i class="fa fa-inr" aria-hidden="true"></i> <?php echo $pd_rows['rp_amount_send']; ?>          

                    </div>

                    <div class="col-md-4 col-xs-4 text-left"><?php echo $pd_rows['rp_paymethod']; ?>         

                    </div>

                </div>

            <?php } ?>

            <hr>

            <div class="row">

                <div class="col-md-6 col-xs-6 text-center">Total Payment : </div>

                <div class="col-md-6 col-xs-6 text-center"><i class="fa fa-inr" aria-hidden="true"></i>  <?php echo $total_payment; ?>

                </div>

            </div>

        </div>







            <?php

           

            }     

        ?>



            <!--Payment Insert -->

        <div class="card shadow mt-3">

            <h5 class="card-header text-dark  text-center font-weight-bold"> Payment <span id="showUserNameDetails"></span></h5>

                <div class="card-body">

                    <form method="POST">   

                        <div class="row" id="Show_InsertUserName">

                            <div class="col-md-6 mt-2">

                                <label class="badge badge-warning">Amount</label>

                                <input type="number" class="form-control" name="amount" >

                            </div>

                            <div class="col-md-6 mt-2">

                                <label class="badge badge-warning">Pay Method</label>

                                <select class="form-control" name="method" >

                                    <option disabled selected>Select A Option</option>

                                    <option value="Cash">Cash</option>

                                    <option value="Net Banking">Net Banking</option>

                                    <option value="Google Pay">Google Pay</option>

                                    <option value="PhonePe">PhonePe</option>

                                </select>

                            </div>

                            <div class="col-md-12 mt-2">

                                <label class="badge badge-warning">Transaction ID</label>

                                <input type="text" class="form-control" name="TransactionID" >

                            </div>

                        </div>



                            <div class=" row justify-content-center">

                                <button type="submit" class="btn btn-success text-sm-center mt-4" name="submit_payment">

                                     Submit

                                </button>

                            </div>

                    </form>

                </div>

            </div>







        </div>

     </div>

</div> 



            <?php include "includes/ft.php"; ?>

            <?php include "includes/js.php"; ?>

</body>

</html>





<?php

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



        $amount = mysqli_real_escape_string($con, strip_tags($_POST['amount']));

        $method = mysqli_real_escape_string($con, strip_tags($_POST['method']));

        $TransactionID = mysqli_real_escape_string($con, strip_tags($_POST['TransactionID']));



        $ins_sql = "INSERT INTO ref_payment (rp_holder_ref,rp_amount_send,   rp_paymethod,rp_transaction_id,rp_date,rp_date2) VALUES ('$_GET[uref_id]','$amount','$method','$TransactionID','$currentDate','$currentDate2')";



        if(mysqli_query($con, $ins_sql)){

            ?>

            <script>

                alert('Submit Successful');

                window.location = "add-member-payment.php?uref_id=<?php echo $_GET['uref_id']; ?>";

            </script>

            <?php

        }

        else{

            ?>

            <script>

                alert('OOPS !!!!');

                setTimeout(() => {

                    window.location = "add-member-payment.php?uref_id=<?php echo $_GET['uref_id']; ?>";

                }, 500);

            </script>

            <?php

        }

    }

?>







<?php 







