<?php 

  include "../db.php";

  date_default_timezone_set('Asia/Kolkata');

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

  session_start();

$s_output='';

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

    

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

    $AndWhere ='';



    if ( !empty($_POST['FirstFilterValue']) ) {



        $sf_sql = "SELECT uref_code FROM users WHERE ( utype='Admin'|| utype = 'Member' ) AND uname='$_POST[FirstFilterValue]'";

        $sf_run = mysqli_query($con, $sf_sql);

        $sf_rows = mysqli_fetch_assoc($sf_run);



        $AndWhere .= "AND rp_holder_ref='$sf_rows[uref_code]' ";



    }





   if (!empty($_POST['SecondFilterValue']) && !empty($_POST['ThirdFilterValue']) ) {



        $AndWhere .= "AND rp_date2 BETWEEN '$_POST[SecondFilterValue]' AND '$_POST[ThirdFilterValue]'";

       



    }

    if (!empty($_POST['SecondFilterValue']) && empty($_POST['ThirdFilterValue']) ) {



        $AndWhere .= "AND rp_date2 BETWEEN '$_POST[SecondFilterValue]' AND '$currentDate'";

       



    }

    if (empty($_POST['SecondFilterValue']) && !empty($_POST['ThirdFilterValue']) ) {



        echo "<div style='text-align:center;font-size:20px;color:red;padding:15px;background:#f2f2f2;'>You Have To Enter Starting Date First.</div><br>";

        die();

       



    }



    /*total Payment count*/

    $count_sql = "SELECT * FROM ref_payment WHERE rp_id !='' $AndWhere ORDER BY rp_id DESC";

     $count_res = mysqli_query($con,$count_sql);

    if ($count_total_rows=mysqli_num_rows($count_res)>0) {

        $total_receive = 0;

        $total_send = 0;

        while ($count_rows = mysqli_fetch_assoc($count_res)) {

            

            if ($count_rows['rp_amount_send'] == 0) {

                 $total_receive += $count_rows['rp_amount_receive'];

            }elseif($count_rows['rp_amount_receive'] == 0){

                 $total_send += $count_rows['rp_amount_send'];      

            }

        }

        $amount_output="

        <li class='clearfix' style='float: none;padding:10px;'>

          <div class='row'>

            <div class='col-md-12 text-center'>

                <b><i class='fa fa-check-square' aria-hidden='true' style='color:green;'></i> Receive : $total_receive &nbsp; &nbsp;<i class='fa fa-window-close' aria-hidden='true' style='color:red;'></i> Send : $total_send </b>

            </div>

          </div>

        </li>



                ";

        

    }



    echo $amount_output ;







     $sql = "SELECT * FROM ref_payment WHERE rp_id !='' $AndWhere ORDER BY rp_id DESC LIMIT $start,30";



    $res = mysqli_query($con,$sql);

    if ($total_rows=mysqli_num_rows($res)>0) {

        

          $c = $start+1;

        while ($rows=mysqli_fetch_assoc($res)) {



           

           $reg_sql = "SELECT * FROM users WHERE uref_code = '$rows[rp_holder_ref]'";

            $reg_res = mysqli_query($con,$reg_sql);

            $reg_rows=mysqli_fetch_assoc($reg_res);



            if ($rows['rp_amount_send'] == 0) {

                $amount = "Received Amount : <i class='fa fa-inr'></i> ".$rows['rp_amount_receive'];

            }elseif($rows['rp_amount_receive'] == 0){

                $amount = "Send Amount : <i class='fa fa-inr'></i> ".$rows['rp_amount_send'];      

            }



            $s_output .= 

                "

                <li class='clearfix' style='float: none;'>

                <div class='row'>

                    



                    <div class='col-md-12 col-xs-12 second-item'>

                    

                        <i class='fa fa-user-circle' aria-hidden='true'style='color:orange;font-size:17px;'></i> <b style='color:black;font-size:15px;'>$reg_rows[uname]</b>

                        &nbsp;&nbsp;<i class='fa fa-list-ul'></i> $reg_rows[uqualification]

                        <br>

                        <b> $amount </b>

                         &nbsp; <i class='fa fa-money'></i> $rows[rp_paymethod]

                         &nbsp; <i class='fa fa-pencil-square-o'></i> $rows[rp_transaction_id]

                        <br>

                        <i class='fa fa-clock-o text-primary'></i> $rows[rp_date]

                        

                    </div>



                </div>

                </li>

                ";

               

          $c++;

        }



        mysqli_close($con);



        echo $s_output;

    }



}



/*if (isset($_POST['amount_ajax'])) {

    $AndWhere = '';



    $count_sql = "SELECT * FROM ref_payment WHERE rp_id !='' $AndWhere ORDER BY rp_id DESC";

     $count_res = mysqli_query($con,$count_sql);

    if ($count_total_rows=mysqli_num_rows($count_res)>0) {

        $total_receive = 0;

        $total_send = 0;

        while ($count_rows = mysqli_fetch_assoc($count_res)) {

            

            if ($count_rows['rp_amount_send'] == 0) {

                 $total_receive += $count_rows['rp_amount_receive'];

            }elseif($count_rows['rp_amount_receive'] == 0){

                 $total_send += $count_rows['rp_amount_send'];      

            }

        }

        $amount_output="<div class='col-md-12 text-center'>

                    <b><i class='fa fa-check-square' aria-hidden='true' style='color:green;'></i> Receive : $total_receive &nbsp; &nbsp;<i class='fa fa-window-close' aria-hidden='true' style='color:red;'></i> Send : $total_send </b>

                    <hr>

                </div>

                ";

        

    }



    echo $amount_output ;



}*/

?>



    <script>

        $(document).ready(function(){



            $('.viewDetails').on('click', function () {

                var name = $(this).data('name');

                $('#modalName').text(name);

                $('.modal-css').css({

                    'color' : 'black'

                    

                });

                $('.modal-name').css({

                    'text-align' : 'center',

                    'color' : 'black'

                });

                $('.modal-id').css({

                    'color' : 'red',

                    'font-weight' : 'bold'

                });

                var dist = $(this).data('dist');

                $('#modalDist').text(dist);

                var pin = $(this).data('pin');

                $('#modalPin').text(pin);

                var userid = $(this).data('userid');

                $('#modalId').text(userid);

                var pass = $(this).data('pass');

                $('#modalPass').text(pass);

                var classs = $(this).data('classs');

                $('#modalClass').text(classs);

                var address = $(this).data('address');

                $('#modalAddress').text(address);

                var date = $(this).data('date');

                $('#modalDate').text(date);

                var email = $(this).data('email');

                $('#modalEmail').text(email);

                

            });

        });

    </script>



