<?php
session_start();
include "connect.php";
$currentpage=100;
$activepage="HomePage";
if(!isset($_SESSION['admin_login'])){ header("location:index.php");}



?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>:: JOYRAM HELP LINE 80  | Dashboard ::</title>
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <?php include "common/CSS_link.php";?>
  <style>
  .doctor-schedule{max-height:254px}
.doctor-schedule .table-bordered{border:2px solid #e3e3e3;margin-bottom:0;background:#fff}
.table-bordered>tbody>tr>td,.table>thead>tr>th{border:2px solid #ddd;color:#777;font-size:14px;letter-spacing:.2px;font-weight:500;text-align:center;padding:7px}
.table>thead>tr>th{color:#0082c8;font-weight:600;font-family:'Lato',sans-serif;text-transform:uppercase;letter-spacing:2px}
.doctor-schedule h5{margin:0}
  </style>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
  <header class="main-header">
    <?php include "common/header.php";?>
  </header>  
  <aside class="main-sidebar">    
    <section class="sidebar">
      <?php include "common/LEFT_sidebar.php";?>
  </aside>  
  <div class="content-wrapper">    
    <section class="content-header">
      <h1>
        Dashboard
        <small></small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">Dashboard</li>
      </ol>
    </section>
 <section class="content">      
      <div class="row">
	  <?php
				$view_company1 = "SELECT * FROM user_tbl ";  
				$rs_result_company1 = mysqli_query($conn,$view_company1);  
				while($row_company1 = mysqli_fetch_array($rs_result_company1)){
					$q_sql="SELECT * FROM `user_tbl` WHERE id = '".$row_company1['id']."'";
					$q_query=mysqli_query($conn,$q_sql." ORDER BY id DESC");
					$row=mysqli_fetch_array($q_query);
					$id=$row['id'];
					$user_unique_id = $row['user_unique_id'];
					$pay_date = $row['pay_date'];
					$rank = $row['rank'];
					date_default_timezone_set('Asia/Kolkata'); 
					$c_date = date('d-m-Y');
							
							if($rank == 1){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day  = round((strtotime($c_date) - strtotime($row['rank_date']))/(60 * 60 * 24)) + 1;
								if($day > 50){
									$day = 50;
								}
								$amt = $day  * 5;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 2){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$day2  = round((strtotime($c_date) - strtotime($row['rank_date2']))/(60 * 60 * 24)) + 1;
								if($day2 > 50){
									$day2 = 50;
								}
								$amt = $day1  * 5 + $day2  * 10;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 3){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$day3  = round((strtotime($c_date) - strtotime($row['rank_date3']))/(60 * 60 * 24)) + 1;
								if($day3 > 50){
									$day3 = 50;
								}
								$amt = $day1  * 5 + $day2  * 10 + $day3  * 15;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 4){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$day4  = round((strtotime($c_date) - strtotime($row['rank_date4']))/(60 * 60 * 24)) + 1;
								if($day4 > 50){
									$day4 = 50;
								}
								$amt = $day1  * 5 + $day2  * 10 + $day3  * 15 + $day4  * 30;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 5){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$day5  = round((strtotime($c_date) - strtotime($row['rank_date5']))/(60 * 60 * 24)) + 1;
								if($day5 > 50){
									$day5 = 50;
								}
								$amt = $day1  * 5 + $day2  * 10 + $day3  * 15 + $day4  * 30 + $day5  * 60;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 6){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$day5  = round((strtotime($row['rank_date6']) - strtotime($row['rank_date5']))/(60 * 60 * 24));
								if($day5 > 50){
									$day5 = 50;
								}
								$day6  = round((strtotime($c_date) - strtotime($row['rank_date6']))/(60 * 60 * 24)) + 1;
								if($day6 > 75){
									$day6 = 75;
								}
								$amt = $day1  * 5 + $day2  * 10 + $day3  * 15 + $day4  * 30 + $day5  * 60 + $day6  * 100;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 7){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$day5  = round((strtotime($row['rank_date6']) - strtotime($row['rank_date5']))/(60 * 60 * 24));
								if($day5 > 50){
									$day5 = 50;
								}
								$day6  = round((strtotime($row['rank_date7']) - strtotime($row['rank_date6']))/(60 * 60 * 24));
								if($day6 > 75){
									$day6 = 75;
								}
								$day7  = round((strtotime($c_date) - strtotime($row['rank_date7']))/(60 * 60 * 24)) + 1;
								if($day7 > 75){
									$day7 = 75;
								}
								$amt = $day1  * 5 + $day2  * 10 + $day3  * 15 + $day4  * 30 + $day5  * 60 + $day6  * 100 + $day7  * 200;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 8){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$day5  = round((strtotime($row['rank_date6']) - strtotime($row['rank_date5']))/(60 * 60 * 24));
								if($day5 > 50){
									$day5 = 50;
								}
								$day6  = round((strtotime($row['rank_date7']) - strtotime($row['rank_date6']))/(60 * 60 * 24));
								if($day6 > 75){
									$day6 = 75;
								}
								$day7  = round((strtotime($row['rank_date8']) - strtotime($row['rank_date7']))/(60 * 60 * 24));
								if($day7 > 75){
									$day7 = 75;
								}
								$day8  = round((strtotime($c_date) - strtotime($row['rank_date8']))/(60 * 60 * 24)) + 1;
								if($day8 > 75){
									$day8 = 75;
								}
								$amt = $day1  * 5 + $day2  * 10 + $day3  * 15 + $day4  * 30 + $day5  * 60 + $day6  * 100 + $day7  * 200 + $day8  * 300;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 9){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$day5  = round((strtotime($row['rank_date6']) - strtotime($row['rank_date5']))/(60 * 60 * 24));
								if($day5 > 50){
									$day5 = 50;
								}
								$day6  = round((strtotime($row['rank_date7']) - strtotime($row['rank_date6']))/(60 * 60 * 24));
								if($day6 > 75){
									$day6 = 75;
								}
								$day7  = round((strtotime($row['rank_date8']) - strtotime($row['rank_date7']))/(60 * 60 * 24));
								if($day7 > 75){
									$day7 = 75;
								}
								$day8  = round((strtotime($row['rank_date9']) - strtotime($row['rank_date8']))/(60 * 60 * 24));
								if($day8 > 75){
									$day8 = 75;
								}
								$day9  = round((strtotime($c_date) - strtotime($row['rank_date9']))/(60 * 60 * 24)) + 1;
								if($day9 > 100){
									$day9 = 100;
								}
								$amt = $day1  * 5 + $day2  * 10 + $day3  * 15 + $day4  * 30 + $day5  * 60 + $day6  * 100 + $day7  * 200 + $day8  * 300 + $day9  * 500;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 10){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$day5  = round((strtotime($row['rank_date6']) - strtotime($row['rank_date5']))/(60 * 60 * 24));
								if($day5 > 50){
									$day5 = 50;
								}
								$day6  = round((strtotime($row['rank_date7']) - strtotime($row['rank_date6']))/(60 * 60 * 24));
								if($day6 > 75){
									$day6 = 75;
								}
								$day7  = round((strtotime($row['rank_date8']) - strtotime($row['rank_date7']))/(60 * 60 * 24));
								if($day7 > 75){
									$day7 = 75;
								}
								$day8  = round((strtotime($row['rank_date9']) - strtotime($row['rank_date8']))/(60 * 60 * 24));
								if($day8 > 75){
									$day8 = 75;
								}
								$day9  = round((strtotime($row['rank_date10']) - strtotime($row['rank_date9']))/(60 * 60 * 24));
								if($day9 > 100){
									$day9 = 100;
								}
								$day10  = round((strtotime($c_date) - strtotime($row['rank_date10']))/(60 * 60 * 24)) + 1;
								if($day10 > 100){
									$day10 = 100;
								}
								$amt = $day1  * 5 + $day2  * 10 + $day3  *  15 + $day4  * 30 + $day5  * 60 + $day6  * 100 + $day7  * 200 + $day8  * 300 + $day9  * 500 + $day10  * 750;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 11){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$day5  = round((strtotime($row['rank_date6']) - strtotime($row['rank_date5']))/(60 * 60 * 24));
								if($day5 > 50){
									$day5 = 50;
								}
								$day6  = round((strtotime($row['rank_date7']) - strtotime($row['rank_date6']))/(60 * 60 * 24));
								if($day6 > 75){
									$day6 = 75;
								}
								$day7  = round((strtotime($row['rank_date8']) - strtotime($row['rank_date7']))/(60 * 60 * 24));
								if($day7 > 75){
									$day7 = 75;
								}
								$day8  = round((strtotime($row['rank_date9']) - strtotime($row['rank_date8']))/(60 * 60 * 24));
								if($day8 > 75){
									$day8 = 75;
								}
								$day9  = round((strtotime($row['rank_date10']) - strtotime($row['rank_date9']))/(60 * 60 * 24));
								if($day9 > 100){
									$day9 = 100;
								}
								$day10  = round((strtotime($row['rank_date11']) - strtotime($row['rank_date10']))/(60 * 60 * 24));
								if($day10 > 100){
									$day10 = 100;
								}
								$day11  = round((strtotime($c_date) - strtotime($row['rank_date11']))/(60 * 60 * 24)) + 1;
								if($day11 > 100){
									$day11 = 100;
								}
								$amt = $day1  * 5 + $day2  * 10 + $day3  *  15 + $day4  * 30 + $day5  * 60 + $day6  * 100 + $day7  * 200 + $day8  * 300 + $day9  * 500 + $day10  * 750 + $day11  * 1500;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 12){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$day5  = round((strtotime($row['rank_date6']) - strtotime($row['rank_date5']))/(60 * 60 * 24));
								if($day5 > 50){
									$day5 = 50;
								}
								$day6  = round((strtotime($row['rank_date7']) - strtotime($row['rank_date6']))/(60 * 60 * 24));
								if($day6 > 75){
									$day6 = 75;
								}
								$day7  = round((strtotime($row['rank_date8']) - strtotime($row['rank_date7']))/(60 * 60 * 24));
								if($day7 > 75){
									$day7 = 75;
								}
								$day8  = round((strtotime($row['rank_date9']) - strtotime($row['rank_date8']))/(60 * 60 * 24));
								if($day8 > 75){
									$day8 = 75;
								}
								$day9  = round((strtotime($row['rank_date10']) - strtotime($row['rank_date9']))/(60 * 60 * 24));
								if($day9 > 100){
									$day9 = 100;
								}
								$day10  = round((strtotime($row['rank_date11']) - strtotime($row['rank_date10']))/(60 * 60 * 24));
								if($day10 > 100){
									$day10 = 100;
								}
								$day11  = round((strtotime($row['rank_date12']) - strtotime($row['rank_date11']))/(60 * 60 * 24));
								if($day11 > 100){
									$day11 = 100;
								}
								$day12  = round((strtotime($c_date) - strtotime($row['rank_date12']))/(60 * 60 * 24)) + 1;
								if($day12 > 200){
									$day12 = 200;
								}
								$amt = $day1  * 5 + $day2  * 10 + $day3  *  15 + $day4  * 30 + $day5  * 60 + $day6  * 100 + $day7  * 200 + $day8  * 300 + $day9  * 500 + $day10  * 750 + $day11  * 1500 + $day12  * 2000;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 13){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$day5  = round((strtotime($row['rank_date6']) - strtotime($row['rank_date5']))/(60 * 60 * 24));
								if($day5 > 50){
									$day5 = 50;
								}
								$day6  = round((strtotime($row['rank_date7']) - strtotime($row['rank_date6']))/(60 * 60 * 24));
								if($day6 > 75){
									$day6 = 75;
								}
								$day7  = round((strtotime($row['rank_date8']) - strtotime($row['rank_date7']))/(60 * 60 * 24));
								if($day7 > 75){
									$day7 = 75;
								}
								$day8  = round((strtotime($row['rank_date9']) - strtotime($row['rank_date8']))/(60 * 60 * 24));
								if($day8 > 75){
									$day8 = 75;
								}
								$day9  = round((strtotime($row['rank_date10']) - strtotime($row['rank_date9']))/(60 * 60 * 24));
								if($day9 > 100){
									$day9 = 100;
								}
								$day10  = round((strtotime($row['rank_date11']) - strtotime($row['rank_date10']))/(60 * 60 * 24));
								if($day10 > 100){
									$day10 = 100;
								}
								$day11  = round((strtotime($row['rank_date12']) - strtotime($row['rank_date11']))/(60 * 60 * 24));
								if($day11 > 100){
									$day11 = 100;
								}
								$day12  = round((strtotime($row['rank_date13']) - strtotime($row['rank_date12']))/(60 * 60 * 24));
								if($day12 > 200){
									$day12 = 200;
								}
								$day13  = round((strtotime($c_date) - strtotime($row['rank_date13']))/(60 * 60 * 24)) + 1;
								if($day13 > 200){
									$day13 = 200;
								}
								$amt = $day1  * 5 + $day2  * 10 + $day3  *  15 + $day4  * 30 + $day5  * 60 + $day6  * 100 + $day7  * 200 + $day8  * 300 + $day9  * 500 + $day10  * 750 + $day11  * 1500 + $day12  * 2000 + $day13  * 3500;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 14){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$day5  = round((strtotime($row['rank_date6']) - strtotime($row['rank_date5']))/(60 * 60 * 24));
								if($day5 > 50){
									$day5 = 50;
								}
								$day6  = round((strtotime($row['rank_date7']) - strtotime($row['rank_date6']))/(60 * 60 * 24));
								if($day6 > 75){
									$day6 = 75;
								}
								$day7  = round((strtotime($row['rank_date8']) - strtotime($row['rank_date7']))/(60 * 60 * 24));
								if($day7 > 75){
									$day7 = 75;
								}
								$day8  = round((strtotime($row['rank_date9']) - strtotime($row['rank_date8']))/(60 * 60 * 24));
								if($day8 > 75){
									$day8 = 75;
								}
								$day9  = round((strtotime($row['rank_date10']) - strtotime($row['rank_date9']))/(60 * 60 * 24));
								if($day9 > 100){
									$day9 = 100;
								}
								$day10  = round((strtotime($row['rank_date11']) - strtotime($row['rank_date10']))/(60 * 60 * 24));
								if($day10 > 100){
									$day10 = 100;
								}
								$day11  = round((strtotime($row['rank_date12']) - strtotime($row['rank_date11']))/(60 * 60 * 24));
								if($day11 > 100){
									$day11 = 100;
								}
								$day12  = round((strtotime($row['rank_date13']) - strtotime($row['rank_date12']))/(60 * 60 * 24));
								if($day12 > 200){
									$day12 = 200;
								}
								$day13  = round((strtotime($row['rank_date14']) - strtotime($row['rank_date13']))/(60 * 60 * 24));
								if($day13 > 200){
									$day13 = 200;
								}
								$day14  = round((strtotime($c_date) - strtotime($row['rank_date14']))/(60 * 60 * 24)) + 1;
								if($day14 > 400){
									$day14 = 400;
								}
								$amt = $day1  * 5 + $day2  * 10 + $day3  *  15 + $day4  * 30 + $day5  * 60 + $day6  * 100 + $day7  * 200 + $day8  * 300 + $day9  * 500 + $day10  * 750 + $day11  * 1500 + $day12  * 2000 + $day13  * 3500 + $day14  * 5000;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}else if($rank == 15){
								$query_sel1 = "SELECT * FROM `user_wallet` WHERE user_id = '$id'";
								$result_sel1 = mysqli_query($conn,$query_sel1);
								$num = mysqli_num_rows($result_sel1);
								$day1  = round((strtotime($row['rank_date2']) - strtotime($row['rank_date']))/(60 * 60 * 24));
								if($day1 > 50){
									$day1 = 50;
								}
								$day2  = round((strtotime($row['rank_date3']) - strtotime($row['rank_date2']))/(60 * 60 * 24));
								if($day2 > 50){
									$day2 = 50;
								}
								$day3  = round((strtotime($row['rank_date4']) - strtotime($row['rank_date3']))/(60 * 60 * 24));
								if($day3 > 50){
									$day3 = 50;
								}
								$day4  = round((strtotime($row['rank_date5']) - strtotime($row['rank_date4']))/(60 * 60 * 24));
								if($day4 > 50){
									$day4 = 50;
								}
								$day5  = round((strtotime($row['rank_date6']) - strtotime($row['rank_date5']))/(60 * 60 * 24));
								if($day5 > 50){
									$day5 = 50;
								}
								$day6  = round((strtotime($row['rank_date7']) - strtotime($row['rank_date6']))/(60 * 60 * 24));
								if($day6 > 75){
									$day6 = 75;
								}
								$day7  = round((strtotime($row['rank_date8']) - strtotime($row['rank_date7']))/(60 * 60 * 24));
								if($day7 > 75){
									$day7 = 75;
								}
								$day8  = round((strtotime($row['rank_date9']) - strtotime($row['rank_date8']))/(60 * 60 * 24));
								if($day8 > 75){
									$day8 = 75;
								}
								$day9  = round((strtotime($row['rank_date10']) - strtotime($row['rank_date9']))/(60 * 60 * 24));
								if($day9 > 100){
									$day9 = 100;
								}
								$day10  = round((strtotime($row['rank_date11']) - strtotime($row['rank_date10']))/(60 * 60 * 24));
								if($day10 > 100){
									$day10 = 100;
								}
								$day11  = round((strtotime($row['rank_date12']) - strtotime($row['rank_date11']))/(60 * 60 * 24));
								if($day11 > 100){
									$day11 = 100;
								}
								$day12  = round((strtotime($row['rank_date13']) - strtotime($row['rank_date12']))/(60 * 60 * 24));
								if($day12 > 200){
									$day12 = 200;
								}
								$day13  = round((strtotime($row['rank_date14']) - strtotime($row['rank_date13']))/(60 * 60 * 24));
								if($day13 > 200){
									$day13 = 200;
								}
								$day14  = round((strtotime($row['rank_date15']) - strtotime($row['rank_date14']))/(60 * 60 * 24));
								if($day14 > 400){
									$day14 = 400;
								}
								$day15  = round((strtotime($c_date) - strtotime($row['rank_date15']))/(60 * 60 * 24)) + 1;
								if($day15 > 400){
									$day15 = 400;
								}
								$amt = $day1  * 5 + $day2  * 10 + $day3  *  15 + $day4  * 30 + $day5  * 60 + $day6  * 100 + $day7  * 200 + $day8  * 300 + $day9  * 500 + $day10  * 750 + $day11  * 1500 + $day12  * 2000 + $day13  * 3500 + $day14  * 5000 + $day15  * 10000;
									if($num == 0){
								$query_sel2 = "INSERT INTO `user_wallet`(`id`, `user_id`, `amt`) VALUES (NULL,'$id','$amt')";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
								$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}else{
								$query_sel2 = "UPDATE `user_wallet` SET `amt` = $amt WHERE user_id = '$id'";
								$result_sel2 = mysqli_query($conn,$query_sel2);
								
									$query_sel2 = "UPDATE `user_tbl` SET `pay_date` = '$c_date' WHERE id = '$id'";
											$result_sel2 = mysqli_query($conn,$query_sel2);
								}
							}
				}					
		?>
        <div class="col-lg-3 col-xs-6">        
          <div class="small-box bg-primary">
            <div class="inner">
              <h3><?php 
			  
			   
				$view_company = "SELECT * FROM user_tbl WHERE id <> 1";  
				$rs_result_company = mysqli_query($conn,$view_company);  
				$row_company = mysqli_num_rows($rs_result_company);  
	
				
				echo ($row_company * 80);
				
			  ?></h3>

              <p>Company Wallet Balance</p>
            </div>
            <div class="icon">
              <i class="fa fa-inr"></i>
            </div>
             </div>
        </div><div class="col-lg-3 col-xs-6">        
          <div class="small-box bg-aqua">
            <div class="inner">
              <h3><?php 
			  
			  $q_query1 =mysqli_query($conn," SELECT SUM(user_wallet.amt) AS amt FROM `user_wallet` WHERE user_id <> 1 ORDER BY user_wallet.id DESC");
				$row_agent1 = mysqli_fetch_array($q_query1);
				
				$q_query2 =mysqli_query($conn,"SELECT SUM(payment_tbl.pay_amount) AS pay_amount FROM `payment_tbl` WHERE status = 1 ");
				$row_agent2 = mysqli_fetch_array($q_query2);
				$num = mysqli_num_rows($q_query1);
				
				echo $row_agent1['amt'] - $row_agent2['pay_amount'];
				
			  ?></h3>

              <p>Due Wallet Balance</p>
            </div>
            <div class="icon">
              <i class="fa fa-inr"></i>
            </div>
             </div>
        </div>
        <!-- ./col -->
       <div class="col-lg-3 col-xs-6">        
          <div class="small-box bg-red">
            <div class="inner">
			 <?php
				$view_company = "SELECT * FROM user_tbl WHERE id <> 1";  
				$rs_result_company = mysqli_query($conn,$view_company);  
				$row_company = mysqli_num_rows($rs_result_company);  
		?> 
              <h3><?php echo ($row_company);?></h3>

              <p>Total Members</p>
            </div>
            <div class="icon">
              <i class="ion ion-person-add"></i>
            </div>
           </div>
        </div>
		<div class="col-lg-3 col-xs-6">        
          <div class="small-box bg-green">
            <div class="inner">
			<?php
			$amt1 = 0;
			$tax = 0;
				$view_company = "SELECT SUM(taxable_amount) AS tax FROM `payment_tbl` ";  
				$rs_result_company1 = mysqli_query($conn,$view_company);  
				$row_tax= mysqli_fetch_assoc($rs_result_company1);
				$row_company1 = mysqli_num_rows($rs_result_company1);
				/*while($row_company = mysqli_fetch_assoc($rs_result_company)){
					$q_query2 =mysqli_query($conn,"SELECT SUM(payment_tbl.pay_amount) AS pay_amount FROM `payment_tbl` WHERE  payment_tbl.user_id = '".$row_company['user_id']."' AND status = 1 ");
				$row_agent2 = mysqli_fetch_array($q_query2);
					$sql = "SELECT * FROM `kyc_tbl` WHERE user_id = '".$row_company['user_id']."' ORDER BY `id`  DESC";
					$re = mysqli_query($conn,$sql);
					$num1 = mysqli_num_rows($re);
					if($num1 > 0){
						$tax = 6;
					}else{
						$tax = 18;
					}
				$amt1 = $amt1 + round(($row_company['amt'] - $row_agent2['pay_amount']) * $tax /100);
				}	*/				
		?>
              <h3><?php
			  if($row_company1 > 0){
$tax = $row_tax['tax'];
			  }else{
				  $tax = 0;
			  }
			  echo $tax; ?></h3>

              <p>Tax Amount</p>
            </div>
            <div class="icon">
              <i class="fa fa-inr"></i>
            </div>
          </div>
        </div>
		
         
      </div>
	  </section>
	  </div>
  <footer class="main-footer">
    <?php include "common/footer.php";?>
  </footer>  
</div>
<!-- ./wrapper -->

<?php include "common/JS_link.php";?>
</body>
</html>