	<?php 
	error_reporting(0);
	if ($_SERVER['REQUEST_METHOD'] == 'POST') 
		{
		$fdt=$_POST['fromDate'];
		$tdt=$_POST['toDate'];
		$member_user_id=strtoupper($_POST['member_user_id']);
		$member_name=$_POST['member_name'];
		$from_date=date("Y-m-d",strtotime($fdt));
		$to_date=date("Y-m-d",strtotime($tdt));
		 $title=$member_user_id."  ".$member_name. " Business Report From ".date("d-M-Y",strtotime($fdt)). " To ".date("d-M-Y",strtotime($tdt));
		}
		else
		{
 		    $title="Check Business || Admin Panel";
 		}
?>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
	<title><?php echo $title; ?></title>

	<!-- Favicons -->
<link rel="shortcut icon" type="image/x-icon" href="../UserProfile/images/logo/logo.png">

	<!-- Bootstrap CSS -->
	<link rel="stylesheet" href="assets/plugins/bootstrap/css/bootstrap.min.css">

	<!-- Fontawesome CSS -->
	<link rel="stylesheet" href="assets/plugins/fontawesome/css/fontawesome.min.css">
	<link rel="stylesheet" href="assets/plugins/fontawesome/css/all.min.css">
	 
	<!-- Animate CSS -->
	<link rel="stylesheet" href="assets/css/animate.min.css">

	<!-- Main CSS -->
	<link rel="stylesheet" href="assets/css/admin.css">
		<!-- Datatables CSS -->
	<link rel="stylesheet" href="assets/plugins/datatables/datatables.min.css">
 <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css"> 
  <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.5.6/css/buttons.dataTables.min.css">
  <style>
input[type=search]
{
    display: block;
    width: 100%;
    padding: .50rem 1rem;
    font-size: 1rem;
    line-height: 1.25;
    color: #4E5154;
    background-color:#FFF;
    background-clip: padding-box;
    border: 1px solid #BABFC7;
    border-radius: .25rem;
}
input[type=button]
{
 
    background-color:#140dec;

}
</style>

</head>

<body>
	<div class="main-wrapper">
	
		<!-- Header -->
	<?php include 'include/header.php'; ?>
		<!-- /Header -->
		
		<!-- Sidebar -->
		<?php include 'include/leftmenu.php'; ?>
		<!-- /Sidebar -->
		
		<div class="page-wrapper">
			<div class="content container-fluid">
			
				<!-- Page Header -->
				<div class="page-header">
					<div class="row">
						<div class="col">
							<h5 class="page-title text-white">Date Wise Business</h5>
    					
						</div>
					
					</div>
				</div>
				
					<form action="#" method="post" id="frmreg">
                	<div class="row">
						<div class="col-sm-12">
							<div class="card">
								<div class="card-body">

									<div class="table-responsive">
										<div class="card filter-card">
						<div class="card-body pb-0">
							<div class="row filter-row">
							    <div class="col-sm-6 col-md-6">
									<div class="form-group">
										<label>From Date</label>
										<input type="date" name="fromDate" id="fromDate" value="<?php echo date("Y-m-d"); ?>" class="form-control" required>
										</div>
								</div>
							    <div class="col-sm-6 col-md-6">
									<div class="form-group">
										<label>To Date</label>
										<input type="date" name="toDate" id="toDate" value="<?php echo date("Y-m-d"); ?>" class="form-control" required>
										</div>
								</div>
								
								<div class="col-sm-6 col-md-3">
									<div class="form-group">
										<label>Associate Id</label>
								 <input type="text" class="form-control" id="member_user_id"  maxlength="10" minlength="10" style="text-transform:uppercase;background-color:#FFFFFF" placeholder="" name="member_user_id"  required onBlur="getmember();" onkeyup="getmember();">
									</div>
								</div>
									<div class="col-sm-6 col-md-5">
									<div class="form-group">
										<label>Member Name</label>
									 <input type="text" class="form-control" id="member_name" placeholder="Customer Name" name="member_name" style="background-color:#FFFFFF" readonly="true" required>
									</div>
								</div>
									<div class="col-sm-4 col-md-3">
									<div class="form-group">
										<button class="btn btn-primary btn-rounded" id="btnsubmit" type="submit" style="width:150px;padding-top:10px">Submit</button>
									
									</div>
								
								</div>
							</div>	

						</div>
					</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				    </form>
				    <div class="row">
 						<div class="col-sm-12">
							<div class="card">
					<?php if ($_SERVER['REQUEST_METHOD'] == 'POST') 
					{
					$fdt=$_POST['fromDate'];
					$tdt=$_POST['toDate'];
					$member_user_id=strtoupper($_POST['member_user_id']);
					$member_name=$_POST['member_name'];
					$from_date=date("Y-m-d",strtotime($fdt));
					$to_date=date("Y-m-d",strtotime($tdt));
					$hdr=$member_user_id."  ".$member_name. " Business Report From ".date("d-M-Y",strtotime($fdt)). " To ".date("d-M-Y",strtotime($tdt));
					$resMember=mysqli_query($connection,"Select * from tbl_memberreg where member_user_id='$member_user_id'");
					$rowMember=mysqli_fetch_array($resMember);
					 ?>
					<div class="card-body">
					    
                    <div class="col-sm-12">
                     <h6><?php echo $hdr; ?></h6>
                    </div>
                    <div class="row">
                     <div class="col-sm-3">
                     <h6>Current Left : <?php echo $rowMember['left_business']; ?></h6>
                     </div>
                     <div class="col-sm-3">
                     <h6>Current Right : <?php echo $rowMember['right_business']; ?></h6>
                     </div>
                     <div class="col-sm-3">
                     <h6>Total Business : <?php echo $rowMember['left_business']+$rowMember['right_business']; ?></h6>
                     </div>
                     </div>
                     <div class="row">
                     <div class="col-sm-3">
                     <h6>Previous Left : <?php echo $rowMember['left_business1']; ?></h6></div>
                     <div class="col-sm-3">
                     <h6>Previous Right : <?php echo $rowMember['right_business1']; ?></h6></div>
                     <div class="col-sm-3">
                     <h6>Previous Total : <?php echo $rowMember['left_business1']+$rowMember['right_business1']; ?></h6></div>
                     </div>
                     <div class="row">
                     <div class="col-sm-3">
                     <h6>New Left : <?php echo $rowMember['left_businessN']; ?></h6></div>
                     <div class="col-sm-3">
                     <h6>New Right : <?php echo $rowMember['right_businessN']; ?></h6></div>
                     <div class="col-sm-3">
                     <h6>New Total : <?php echo $rowMember['left_businessN']+$rowMember['right_businessN']; ?></h6></div>
                     </div>
                        <hr>
									<div class="table-responsive">
										<table class="table table-stripped" id="example">
									  <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>EMI Receipt No</th>
                                        <th>Customer Id</th>
                                        <th>Customer Name</th>
                                        <th>Date</th>
                                        <th>Payment Amt</th>
                                        <th>Business Amt(%)</th>
                                    
                                    </tr>
                                </thead>
                                <tbody>
                                   <?php
                                   $cnt=1;$total=0;$totalBusiness=0;
                                   $strI="Select * from tbl_memberreg where promoter_id='$member_user_id' ";
                                   $resI=mysqli_query($connection,$strI) or die(mysqli_error($connection));
                                   while($rowI=mysqli_fetch_array($resI))
                                   {
                                       
                                        $data_array[]=$rowI['member_user_id'];
                                        if($rowI['is_customer']==1)
										{
                                           $customerId=$rowI['member_user_id'];
                                           $customer_name=$rowI['member_name'];
                                           
                                           $resEmi=mysqli_query($connection,"Select * from tbl_plot_emi_payment where member_user_id ='$customerId' and entry_date between '$from_date' and '$to_date' and closingstatus=1");
                                           while($rowEmi=mysqli_fetch_array($resEmi))
                                           {
                                               $total=$total+$rowEmi['payment_amt'];
                                               $totalBusiness=$totalBusiness+$rowEmi['comm_business_amt'];
                                 		 ?>
				                        <tr>
				                
                                        <td><?php echo $cnt++; ?></td>
                                         <td><?php echo $rowEmi['emi_reference_no']; ?></td>
                                        <td><?php echo $customerId; ?></td>
                                        <td><?php echo $customer_name; ?></td>
                                         <td><?php echo date("d-M-Y",strtotime($rowEmi['entry_date'])); ?></td>
                                          <td><?php echo $rowEmi['payment_amt']; ?></td>
                                           <td><?php echo $rowEmi['comm_business_amt']; ?>-<?php echo $rowEmi['businessper']; ?></td>
                                      
                                      
                                    </tr>
                                    <?php } 
                                        } 
                                    } 
                                    ?>
                                   
                                   
                                   <!-- downline List -->
				 						<?php
				 						$list=array();
										while(count($data_array)>0)
										{
										$arrlength = count($data_array);
										for($x = 0; $x < $arrlength; $x++) 
										{
    										$member_user_id1= $data_array[$x];
    										$sql="select * from tbl_memberreg where  promoter_id='$member_user_id1'  order by member_id";
    										$result=mysqli_query($connection,$sql);
    										while($rowI = mysqli_fetch_array($result))
    										{
        										$list[]=$rowI['member_user_id'];
        										if($rowI['is_customer']==1)
        										{
                                                   $customerId=$rowI['member_user_id'];
                                                   $customer_name=$rowI['member_name'];
                                                   
                                                   $resEmi=mysqli_query($connection,"Select * from tbl_plot_emi_payment where member_user_id ='$customerId' and entry_date between '$from_date' and '$to_date'");
                                                   while($rowEmi=mysqli_fetch_array($resEmi))
                                                   {
                                                        $total=$total+$rowEmi['payment_amt'];
                                               $totalBusiness=$totalBusiness+$rowEmi['comm_business_amt'];
                                         		 ?>
        				                        <tr>
        				                
                                                <td><?php echo $cnt++; ?></td>
                                                <td><?php echo $rowEmi['emi_reference_no']; ?></td>
                                                <td><?php echo $customerId; ?></td>
                                                <td><?php echo $customer_name; ?></td>
                                                 <td><?php echo date("d-M-Y",strtotime($rowEmi['entry_date'])); ?></td>
                                                  <td><?php echo $rowEmi['payment_amt']; ?></td>
                                                   <td><?php echo $rowEmi['comm_business_amt']; ?>-<?php echo $rowEmi['businessper']; ?></td>
                                        
                                            </tr>
                                            <?php 
                                                       
                                                   } 
                                                } 
    			 						    }
						                } 
						
        							$cnt++;
        							$data_array=$list;
        							unset($list);
        										}				
        						?>
        						<tr>
        						    <td></td>
        						    <td></td>
        						    <td></td>
        						    <td></td>
        						    <td><b>Total</b></td>
        						    <td><b><?php echo $total;  ?></b></td>
        						    <td><b><?php echo $totalBusiness;  ?></b></td>
        						</tr>
                                </tbody>
										</table>
									</div>
								
								</div>
									<?php }  ?>
							</div>
						</div>
						
					</div>
	</div>
	</div>
	<!-- jQuery -->
	<script src="assets/js/jquery-3.5.0.min.js"></script>

	<!-- Bootstrap Core JS -->
	<script src="assets/js/popper.min.js"></script>
	<script src="assets/plugins/bootstrap/js/bootstrap.min.js"></script>

	<!-- Slimscroll JS -->
	<script src="assets/plugins/slimscroll/jquery.slimscroll.min.js"></script>
		<script src="assets/plugins/datatables/jquery.dataTables.min.js"></script>
	<script src="assets/plugins/datatables/datatables.min.js"></script> 


	<!-- Custom JS -->
	<script src="assets/js/admin.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.js" type="text/javascript"></script>
  <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js" type="text/javascript"></script> 
  <script src="https://cdn.datatables.net/buttons/1.5.6/js/dataTables.buttons.min.js" type="text/javascript"></script>
  <script src="https://cdn.datatables.net/buttons/1.5.6/js/buttons.flash.min.js" type="text/javascript"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js" type="text/javascript"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js" type="text/javascript"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js" type="text/javascript"></script>
  <script src="https://cdn.datatables.net/buttons/1.5.6/js/buttons.html5.min.js" type="text/javascript"></script>
  <script src="https://cdn.datatables.net/buttons/1.5.6/js/buttons.print.min.js" type="text/javascript"></script>
 <script>
$(document).ready(function() {
    $('#example').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print'
        ]
    } );
} );
</script>
<script>
function getmember()
{ 
	 var sponcerid=$.trim($("#member_user_id").val());
	 
	 if(sponcerid.length==10)
	 {
    //alert(sponcerid);
	 var dataString = 'member_user_id='+ sponcerid;
		$.ajax
		({
			type: "POST",
			url: "get_member.php",
			data: dataString,
			cache: false,
			success: function(data)
			{
			    console.log(data);
				$("#member_name").val(data);
			} 
		});
	 }
	 else
	 {
	 $("#member_name").val("");
	 }
}

</script>
</body>

</html>
